|
24小時時鐘仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載):
//源程序
- #include <reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar count=0;
- uchar shi=0;
- uchar fen=0;
- uchar miao=0;
- uchar code table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- uchar code tabscan[]={0,1,2,3,4,5,6,7};
- void delay(int x)
- {int i,j;
- for(i=0;i<x;i++)
- for(j=0;j<120;j++);
- }
- void Init_T0()
- {
- TMOD=0X01;
- TH0=0X4c;
- TL0=0x00;
- IE=0x82;
- TR0=1;
- }
- void _Int() interrupt 1
- {
- TH0=0x4c;
- TL0=0X00;
- count++;
- if(count==20)
- {
- count=0;
- miao++;
- if(miao==60)
- {
- miao=0;
- fen++;
- if(fen==60)
- {
- fen=0;
- shi++;
- if(shi==24)
- {
- shi=0;
- fen=0;
- miao=0;
- }
- }
- }
- }
- }
- void display()
- {
- P0=table[miao/10];
- P2=tabscan[6];
- delay(2);
- P0=0x00;
- P0=table[miao%10];
- P2=tabscan[7];
- delay(2);
- P0=0x00;
- P0=0x40;
- P2=tabscan[5];
- delay(2);
- P0=0x00;
- P0=table[fen/10];
- P2=tabscan[3];
- delay(2);
- P0=0x00;
- P0=table[fen%10];
- P2=tabscan[4];
- delay(2);
- P0=0x00;
- P0=0x40;
- P2=tabscan[2];
- delay(2);
- P0=0x00;
- P0=table[shi/10];
- P2=tabscan[0];
- delay(2);
- P0=0x00;
- P0=table[shi%10];
- P2=tabscan[1];
- delay(2);
- P0=0x00;
- }
- void main()
- {
- Init_T0();
- while(1)
- display();
- }
復制代碼
|
-
-
24小時時鐘設計.rar
2017-6-9 08:22 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
32.13 KB, 下載次數: 42, 下載積分: 黑幣 -5
評分
-
查看全部評分
|