资源预览内容
第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
亲,该文档总共3页全部预览完了,如果喜欢就下载吧!
资源描述
基于51单片机的倒计时实现,精确到毫秒。#include #define uchar unsigned char#define uint unsigned intuchar t1,shu,shi,ge,miao1,miao2;sbit wei1=P20;sbit wei2=P21;sbit wei3=P22;sbit wei4=P23;void display(uchar shi,uchar ge,uchar miao1,uchar miao2);uchar code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f;void delay(uint z) /延时uint x,y;for(x=z;x0;x-)for(y=110;y0;y-);void init()shu=60;t1=100;TMOD=0x01;TH0=(65536-10000)/256;TL0=(65536-10000)%256;ET0=1;/ 开始计时 EA=1;TR0=1;/ 开所有中断void timer0() interrupt 1/定时器0TH0=(65536-10000)/256;TL0=(65536-10000)%256;t1-;miao1=t1/10;miao2=t1%10;if(t1=0)t1=100;shu-;shi=shu/10;ge=shu%10;if(shu=0)TH0=(65536-10000)/256; TL0=(65536-10000)%256;TR0=0;void display(uchar shi,uchar ge,uchar miao1,uchar miao2) /显示P2=0xfe;P0=tableshi;delay(5);P2=0xfd;P0=tablege;delay(5);P2=0xfb;P0=tablemiao1;delay(5);P2=0xf7;P0=tablemiao2;delay(5);void main()init();shi=5;ge=9;display(shi,ge,miao1,miao2);while(1)display(shi,ge,miao1,miao2);
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号