C语言 24小时制时钟单片机程序源码
C语言 24小时制时钟单片机程序源码
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar code dx[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- uchar code wx[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
- void timer();
- void display(uchar b,uchar c ,uchar d ,uchar e,uchar f,uchar g);
- uchar a,b,c,d,e,f,g;
- int h;
- void delay()
- {
- uchar a;
- for(a=0;a<=250;a++)
- ;
- }
- void main()
- {
- timer();
- while(1)
- {
- if(a==20)
- {
- a=0;
- h++;
- g=h%3600%60%10;
- f=h%3600%60/10;
- e=h%3600/60%10;
- d=h%3600/60/10;
- c=h/3600%60;
- b=h/3600/60;
- }
- display(b,c,d,e,f,g);
- }
- }
- void timer()
- {
- TMOD=0x01;
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- EA=1;
- ET0=1;
- TR0=1;
- }
- void timer0() interrupt 1
- {
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- a++;
- }
- void display(uchar b,uchar c ,uchar d ,uchar e,uchar f,uchar g)
- {
- P2=wx[2];
- P0=dx;
- delay();
- P2=wx[3];
- P0=dx[c];
- delay();
- P2=wx[4];
- P0=dx[d];
- delay();
- P2=wx[5];
- P0=dx[e];
- delay();
- P2=wx[6];
- P0=dx[f];
- delay();
- P2=wx[7];
- P0=dx[g];
- delay();
- }
复制代码