郭天祥的板子单片机按键,在下面程序的基础上加按键,确保不会出现抖动且按紧不会熄灭- #include<reg52.h>
- #define uint unsigned int
- #define uchar unsigned char
- uchar code du[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- uchar code we[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
- sbit dula = P2^6;
- sbit wela = P2^7;
- sbit coke = P2^3;
- uchar shi,fen,miao,aa;
- void display(uchar);
- void delay(uint z)
- {
- uint x;
- for(;z>0;z--)
- for(x=110;x>0;x--);
- }
- void mm(uchar a,k)
- {
- wela=1;
- P0=we[a];
- wela=0;
- dula=1;
- P0=du[k];
- dula=0;
- delay(1);
- P0=0xff;
- }
- void main()
- {
-
- uchar temp;
- uchar miao_ge,miao_shi,fen_ge,fen_shi;
- uchar shi_ge,shi_shi;
- aa=0;
- TMOD=0x01;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- EA=1;
- ET0=1;
- TR0=1;
- while(1)
- {
- miao_ge =(miao%10);
- miao_shi=(miao/10);
- fen_ge=(fen%10);
- fen_shi=(fen/10);
- shi_ge=(shi%10);
- shi_shi=(shi/10);
-
- dula=1;
- wela=1;
- mm(5,miao_ge);
- mm(4,miao_shi);
- mm(3,fen_ge);
- mm(2,fen_shi);
- mm(1,shi_ge);
- mm(0,shi_shi);
- dula = 0;
- wela = 0;
- P0 = 0xff;
-
- if(aa<10)
- {
- dula = 1;
- P0 = 0x80;
- dula = 0;
- wela = 1;
- P0 = 0x15;
- wela = 0;
- P0 = 0xff;
- }
- }
- }
- void timer0() interrupt 1
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- aa++;
- if(aa==20)
- {
- aa=0;
- miao++;
- if(miao>59)
- {
- fen++;
- miao=0;
- }
- if(fen>59)
- {
- shi++;
- fen=0;
- }
- if(shi>23)
- {
- shi=0;
- }
- }
- if(fen==0&&miao==0)
- {
- coke=0;
- }
- else
- {
- coke=1;
- }
- }
复制代码
|