功能:程序启动时显示“00:00:00”,以后每隔1秒显示值加1。显示到23:59:59后,自动从“00”开始,如此无限往复 。 protues仿真图:
附件:
3.rar
(47.87 KB, 下载次数: 9)
代码如下: - #include <reg51.h>
- sbit P0_0=P0^0;
- unsigned char SEG[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
- unsigned char count=0,start=0;
- void delay(unsigned int time){
- unsigned int j=0;
- for(time=time;time>0;time--)
- for(j=0;j<125;j++);
- }
- void LED() interrupt 0 {
- P0_0=!P0_0;
- }
-
- void SEG7() interrupt 2
- {
- count =count+1;
- start=1;
- if(count>99)
- count=1;
- }
- void main(){
- unsigned char seg1=0,seg2=0;
- P1=0x00;
- P2=0xff;
- TCON=0x05;
- EA=1;
- EX1=1;
- EX0=1;
-
- while(1){
-
- while (start==1)
- {
- seg1=count%10;
- P1=0x02;
- P2=SEG[seg1];
- delay(20);
-
- seg2=count/10;
- P1=0x01;
- P2=SEG[seg2];
- delay(20);
- }
- }
- }
-
复制代码
|