60s計時器,自動計時,無返回
單片機源程序如下:
- //0-59自動計數器
- //跳線設置:默認
- #include<reg51.h>
- unsigned char code discode1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- unsigned char code discode2[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- unsigned char timer=0;
- unsigned char second;
- main()
- {
- TMOD = 0x01;
- EA=1; //總中斷打開
- ET0=1; //定時器中斷打開
- second=0;
- TR0=1;
- P0=discode1[second/10];
- P2=discode2[second%10];
- while(1)
- {
-
- }
- }
- void int_T0() interrupt 1 using 0
- {
- TR0=0;
- TH0=0xee;
- TL0=0x00;
- timer ++;
- if(timer==200)
- {
- timer = 0;
- second ++;
- P0=discode1[second/10];
- P2=discode2[second%10];
- }
- if(second==60)
- {
- TR0=0;
- second=0;
- }
- else
- {
- TR0=1;
- }
- }
復制代碼
所有資料51hei提供下載:
jishi.zip
(18.68 KB, 下載次數: 13)
2020-11-28 16:17 上傳
點擊文件名下載附件
|