用數碼管做一個秒表
單片機源程序如下:
- #include"reg52.h"
- #define u8 unsigned char
- #define u16 unsigned int
- sbit duan1=P2^2;
- sbit duan2=P2^3;
- sbit duan3=P2^4;
- u8 code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- u16 date=5448;
- u8 a;
- void delay(u16 mas)
- {
- u16 i,j;
- for(i=mas;i>0;i--)
- for(j=110;j>0;j--);
- }
- void display(u16 date)
- {
- u8 ge,shi,bai,qian;
- ge=date%10;
- shi=date/10%10;
- bai=date/100%10;
- qian=date/1000;
- duan1=0;duan2=0;duan3=0;
- P0=table[ge];
- delay(5);
- P0=0x00;
- duan1=1;duan2=0;duan3=0;
- P0=table[shi];
- delay(5);
- P0=0x00;
- duan1=0;duan2=1;duan3=0;
- P0=table[bai];
- delay(5);
- P0=0x00;
- duan1=1;duan2=1;duan3=0;
- P0=table[qian];
- delay(5);
- P0=0x00;
- }
- void main()
- {
-
- TMOD=0x01;
- TH0=(65536-45872)/256;
- TL0=(65536-45872)%256;
- EA=1;
- ET0=1;
- TR0=1;
- while(1)
- {
- display(date);
-
- }
- }
- void inttime() interrupt 1
- {
-
- TH0=(65536-50000)/256;
- TL0=(65536-50000)%256;
- a++;
-
- if(a==20)
- {
- a=0;
- date=date-1;
- if(date==0)
- date=5448;
- }
- }
復制代碼
所有資料51hei提供下載:
秒表.zip
(22.98 KB, 下載次數: 7)
2017-10-13 00:16 上傳
點擊文件名下載附件
一個秒表 下載積分: 黑幣 -5
|