标题: 单片机AT89C51外接4 位共阳LED 数码管 [打印本页]

作者: 2315695146    时间: 2018-5-28 19:44
标题: 单片机AT89C51外接4 位共阳LED 数码管
单片机AT89C51外接4 位共阳LED 数码管,P3.0引脚外接一独立按键。开机
时数码管显示数字2018; 在按下按键时,显示月日期,设计单片机接口电路并编程

  1. #include<reg51.h>
  2. #include "intrins.h"
  3. #include "absacc.h"
  4. #define uchar unsigned char
  5. uchar code ledtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40,0xff};//0-9
  6. unsigned char disdat[4]="2018";
  7. sbit key=P3^0;
  8. void ext0() interrupt 0
  9. {
  10.     key++;
  11.     key%=3;
  12. }
  13. void t1isr() interrupt 3 //显示
  14. {
  15.     TH1=0xec;
  16.     TL1=0x78;
  17.     P0=0xff;
  18.     P2=0x01<<scanled;
  19.     P0=~ledtab[disdat[3]];
  20.     scanled++;
  21.     scanled%=4;
  22. }
  23. main()
  24. {
  25.     TMOD=0x10;
  26.     TH1=0xec;
  27.     TL1=0x78;
  28.     TR1=1;
  29.     ET1=1;
  30.     EA=1;
  31.     while(1)
  32.     {
  33.     if(key==0)
  34.         {
  35.         disdat[]="0423";
  36.         while(key==0);
  37.         disdat[]="2018";
  38.         }
  39.     }
  40. }
复制代码




作者: admin    时间: 2018-5-29 01:26
此贴需要补全源码和图纸后才能获得积分




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1