}
PC=0xfd; temp=PC;
temp=temp&0xf0; if(temp!=0xf0) { delay(5); temp=PC; temp=temp&0xf0; if(temp!=0xfe) { temp=PC; switch(temp) { case 0xed:num3=5;//定时器暂停,并进入设置clock状态按键 break; case 0xdd:num3=6;//设置clock的秒,分,时加时按键 break; case 0xbd:num3=7;//设置clock的秒,分,时减时按键 break; case 0x7d:num3=8;//定时器暂停,开启按键 break; } while(temp!=0xf0) { temp=PC; temp=temp&0xf0; display(h0,h1,mi0,mi1,s0,s1); } switch(num3) { case 5: { TR0=0; count++; if(count==4) { count=0; TR0=1; } break; } case 6: {
22
if(count==1) { second++; if(second==60) second=0; } else if(count==2) { min++; } case 7: { } case 8:
{
if(min==60) min=0; } else if(count==3) { hour++; if(hour==24) hour=0; } break;
if(count==1) { second--; if(second==-1) second=59; } else if(count==2) { min--; if(min==-1) min=59; } else if(count==3) { hour--; if(hour==-1) hour=23; } break;
23
}
}
}
S++;
if(S%2==1) TR0=0; else TR0=1; if(S==2) S=0; break;
}
}
24
附录二:程序(方案二)
#include
#define uchar unsigned char #define uint unsigned int #define uchar unsigned char
#define PA XBYTE[0xD1FF] #define PB XBYTE[0xD2FF] #define PC XBYTE[0xD5FF] #define PCON XBYTE[0xD7FF]
uchar num,temp,hour,minute,second,hour1,hour2,minute1,minute2,second1,second2; uchar aa,aa1,aa2,bb,bb1,bb2,cc,cc1,cc2; sbit buzzer=P3^3;//蜂鸣器
sbit D0=P1^0;//用来指示闹钟开启关闭的LED bit flag;//闹钟开启关闭的标志位 uint a0;
uchar code tabledu[]={ 0xA0,0xBB,0x62,0x2A, 0x39,0x2C,0x24,0xBA,
0x20,0x28};//数码管0123456789的段选编码 uchar code tablewe[]={
0xfe,0xfd,0xfb,0xf7,0xef,0xdf};//数码管的位选编码 sbit SCLK=P3^2; sbit RST=P2^6; sbit IO=P3^5;
/***毫秒延时程序*****/ void delay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--) ; }
/***微秒延时程序*****/ void delay_us(uchar n) { uchar i;
for(i=0;i 25 /***1302做好准备*****/ void ready_init1302() { RST=0; SCLK=0; RST=1; } /***1302单字节数据写入*****/ void write1302(uchar dat) { uchar i; SCLK=0; delay_us(2); for(i=0;i<8;i++) { IO=dat&0x01; delay_us(2); SCLK=1; delay_us(2); SCLK=0; dat>>=1; } } /***1302双字节数据写入(寄存器地址和数据)*****/ void write_set1302(uchar cmd,uchar dat) { ready_init1302(); delay_us(2); write1302(cmd); write1302(dat); SCLK=1; RST=0; } /***1302单字节数据读出*****/ uchar read1302() { uchar i,dat; dat=0; delay_us(2); for(i=0;i<8;i++) { 26