T_RST = 1;
oneByteToClock(0xbe); // 0xbe:时钟突发模式:写寄存器 时钟多字节写命令
oneByteToClock(second); oneByteToClock(minute); oneByteToClock(hour); oneByteToClock(date); oneByteToClock(month); oneByteToClock(day); oneByteToClock(year); oneByteToClock(0); T_CLK = 1; T_RST =0; }
void disTime(void) {
unchar sec,min,hou,dat,mon,wek,yea,i,j=0; T_RST = 0; T_CLK = 0; T_RST = 1;
oneByteToClock(0xbf); //* 0xbf:时钟突发模式寄存器:读寄存器字节读命令
sec = oneByteFromClock(); min = oneByteFromClock(); hou = oneByteFromClock(); dat = oneByteFromClock(); mon = oneByteFromClock(); wek = oneByteFromClock(); yea = oneByteFromClock(); T_CLK = 1; T_RST =0;
Dispbuff[0] = sec; Dispbuff[1] = sec/16; Dispbuff[2] = 0xa; Dispbuff[3] = min; Dispbuff[4] = min/16; Dispbuff[5] = 0xa; Dispbuff[6] = hou; Dispbuff[7] = hou/16;
for(i=0; i<8; i++) {
时钟多 P1 = j; P0 = Led[Dispbuff[i]]; CDelay(60); j ++; CDelay(60); } }
void disDate(void) {
unchar sec,min,hou,dat,mon,wek,yea,i,j=0; T_RST = 0; T_CLK = 0; T_RST = 1;
oneByteToClock(0xbf); //* 0xbf:时钟多字节读命令 sec = oneByteFromClock(); min = oneByteFromClock(); hou = oneByteFromClock(); dat = oneByteFromClock(); mon = oneByteFromClock(); wek = oneByteFromClock(); yea = oneByteFromClock(); T_CLK = 1; T_RST =0;
Dispbuff[0] = dat; Dispbuff[1] = dat/16; Dispbuff[2] = 0xa;
Dispbuff[3] = mon; Dispbuff[4] = mon/16; Dispbuff[5] = 0xa; Dispbuff[6] = yea; Dispbuff[7] = yea/16;
for(i=0; i<8; i++) { P1 = j; P0 = Led[Dispbuff[i]]; CDelay(60); j ++; CDelay(60); }
}
void iniClock() {
giveOneTime(0x8e,0x00); //控制写入WP=0 giveOneTime(0x90,0xa5);
giveOneTime(0x80,second); //秒 giveOneTime(0x82,minute); //分 giveOneTime(0x84,hour); //时 giveOneTime(0x86,date); //日 giveOneTime(0x88,month); //月 giveOneTime(0x8a,day); //星期 giveOneTime(0x8c,year); //年 */ giveOneTime(0x8e,0x80); }
unchar bcdToChar (unchar bcd) { unchar n;
n= (bcd>>4)*10 + (bcd&0x0F); return n; }
unchar charToBcd (unchar num) {
unchar n;
n = ((num/10)<<4) | ( num ); return n; }
unchar sToS(unchar s) {
unchar n;
n=(s/16)*10+(s); return n; }
void disRing() //闹钟1设置显示 {
P1=0;
P0=Led[ring[0]]; CDelay(60); P1=1;
P0=Led[ring[0]/10];
CDelay(60); P1=4;
P0=Led[ring[1]]; CDelay(60); P1=5;
P0=Led[ring[1]/10]; CDelay(60); }
void disRing1() //闹钟2设置显示 {
P1=0;
P0=Led[ring1[0]]; CDelay(60); P1=1;
P0=Led[ring1[0]/10]; CDelay(60); P1=4;
P0=Led[ring1[1]]; CDelay(60); P1=5;
P0=Led[ring1[1]/10]; CDelay(60); }
void disRing2() // 闹钟3设置显示 {
P1=0;
P0=Led[ring2[0]]; CDelay(60); P1=1;
P0=Led[ring2[0]/10]; CDelay(60); P1=4;
P0=Led[ring2[1]]; CDelay(60); P1=5;
P0=Led[ring2[1]/10]; CDelay(60); }
void DateDisF() {
if(i==0)
作
{ disDate(); //K1 if(K1==0&&i1==0) { i1=1; yea= bcdToChar(getOneTime(0x8d)); if(yea==89) { yea=0; yea= charToBcd(yea); giveOneTime(0x8e,0x00); //* 控制命令,WP=0,写操 giveOneTime(0x8c,yea); //写寄存器指令,年 giveOneTime(0x8e,0x80); disDate(); } else{ yea= yea+1; yea= charToBcd(yea); giveOneTime(0x8e,0x00); //* 控制命令,WP=0,写操作 giveOneTime(0x8c,yea); //写寄存器指令,年 giveOneTime(0x8e,0x80); disDate(); } } //K2 if(K2==0&&i2==0) { i2=1; mon= bcdToChar(getOneTime(0x89)); if(mon==12) { mon=1; mon= charToBcd(mon);
giveOneTime(0x8e,0x00); //* 控制命令,WP=0,写操作? giveOneTime(0x88,mon); //写寄存器指令,月 giveOneTime(0x8e,0x80); disDate(); } else{ mon= mon+1; mon= charToBcd(mon);