例4 數字鐘的proteus仿真電路及C語言程序設計
2.png (14.68 KB, 下載次數: 34)
下載附件
2018-11-29 18:35 上傳
1.png (30.12 KB, 下載次數: 26)
下載附件
2018-11-29 18:35 上傳
單片機源程序如下:
- #include <REG51.H>
- #define uint unsigned int
- #define uchar unsigned char
- uint sec;
- uint min=23;
- uint hour=8;
- uint tcnt;
- unsigned char table[]=
- {0x3f,0x06,0x5b,0x4f,0x66,
- 0x6d,0x7d,0x07,0x7f,0x6f,
- 0x40,0x00};
- //共陰數碼管 0-9 '-'
- void display(unsigned char a,unsigned char b,unsigned char c);
- //顯示延時 函數
- void delay(unsigned int z)
- {
- unsigned int x;
- unsigned char y;
- for(x=z;x>0;x--)
- for(y=200;y>0;y--);
- }
- void display()
- {
-
- P3=0xfe;P2=0x00;
- P2=table[sec%10];
- delay(3);
-
- P3=0xfd;P2=0x00;
- P2=table[sec/10];
- delay(3);
-
-
- P3=0xfb;P2=0x00;
- P2=table[10];
- delay(3);
-
- P3=0xf7;P2=0x00;
- P2=table[min%10];
- delay(3);
-
- P3=0xef;P2=0x00;
- P2=table[min/10];
- delay(3);
-
-
- P3=0xdf;P2=0x00;
- P2=table[10];
- delay(3);
-
- P3=0xbf;P2=0x00;
- P2=table[hour%10];
- delay(3);
-
-
- P3=0x7f;P2=0x00;
- P2=table[hour/10];
- delay(3);
- }
- main()
- {
-
- TMOD=0x02; //設置模式為定時器T0的模式2 (8位自動重裝計數初值的計數值)
- TH0=0x06; //設置計數器初值,靠TH0存儲重裝的計數值X0=256-250=6
- TL0=0x06;
- TR0=1; //啟動T0
- ET0=1; //開啟定時器T0中斷允許
- EA=1;
-
- while(1)
- {
-
- display();
-
- }
- }
- void t0(void)interrupt 1 using 0 //t0的中斷程序
- {
- tcnt++;
- if(tcnt==4000)//定時器的定時計數,4000次250us為1秒
- {
- tcnt=0;
-
- sec++;
- if(sec==60)
- {
- sec=0;
- min++;
- if(min==60)
- {
- min=0;
- hour++;
- if(hour==24)
- {
- hour=0;
-
-
- }
-
- }
- }
- }
- }
復制代碼
所有資料51hei提供下載:
數字鐘的proteus仿真電路及C語言程序設計.rar
(50.94 KB, 下載次數: 35)
2018-11-29 18:36 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|