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)
|