还剩63页未读,继续阅读
本资源只提供10页预览,全部文档请下载后查看!喜欢就下载吧,查找使用更方便
文本内容:
万年历数字钟及可调时钟系统.txt用快乐去奔跑,用心去倾听,用思维去发展,用努力去奋斗,用目标去衡量,用爱去生活钱多钱少,常有就好!人老人少,健康就好!家贫家富,和睦就好万年历数字钟及可调时钟系统
一、引言万年历数字钟是一种用万年历时钟芯片实现年、月、日、时、分、秒计时,并通过单片机处理后送给显示芯片显示的装置,与机械式时钟相比具有更高的准确性和直观性,且具有更长的使用寿命本系统还可以扩展为可调的自动开关,对家电对用电设备进行控制,笔者在随后改制成为可调时的自动断电的供电系统.
二、原理图设计
1.单片机及其外围电路设计复位采用X25045芯片,复位电路如图1所示图1复位电路设计单片机采用贴片封装的AT89s51,晶振为
11.0592MHz其中PL5PL7为下载程序使用,电路如〜图2所示图2单片机89S51外围电路设计
2.时钟芯片电路设计时钟芯片采用PCF8563,晶振采用
32.768K,电容使用15pfPCF8563是PHILIPS公司推出的一款工业级内含12c总线接口功能的具有极低功耗的多功能时钟/日历芯片内部时钟电路、内部振荡电路、内部低电压检测电路
1.0V以及两线制12c总线通讯方式,不但使外围电路及其简洁,而且也增加了芯片的可靠性同时每次读写数据后,内嵌的字地址寄存器会自动产生增量电路如图3所示图3时钟芯片电路设计SI=1;elseSI=0;SCK=1;Byte=Byte«l;〃右移SI=0;〃使SI处于确定的状态zlg7289_cs=l;〃单字节数据从X25045读到单片机〃数据由SCK的下降沿输出到S0线上unsigned charINPUTByte void〃输入一,个字节unsigned charTemp=0,TempCyc;zlg7289_cs=l;for TempCyc=0;TempCyc8;TempCyc++Temp=Templ;〃右移SCK=1;SCK=O;if SOTemp=Temp|OxOl;〃SO为1,则最低位为1elseTemp=0xFE;}return Temp;;〃这一个调试时没有执行,Temp的值总是0zlg7289_cs=l;unsigned charReadByteunsigned charADD〃读地址中的数据这里不做先导字处理,只能读00-FFHunsigned charTemp;zlg7289cs=l;SCK=O;CSR;S0=l;SI=1;0UTByte0x3;〃发送读指令03H如要支持000-FFF则要把高位地址左移3位再为03H相或OUTByteADD;〃发送低位地址Temp=INPUTByte;SCK=O;CS=1;return Temp;〃这一个调试时没有执行,Temp的zlg7289_cs=l;void WriteByteunsigned char Byte,ADD〃向地址写入数据这里同样不做先导字处理,只能写00-FFH{WREN;zlg7289cs=l;SCK=0;CS=O;S0=l;SI=1;0UTByte0x2;〃发送写指令02H如要支持000-FFF则要把高位地址左移2位再为02H相或OUTByteADD;〃发送低位地址OUTByteByte;//发送数据SCK=O;CS=1;WIPCHKO;zlg7289_cs=l;/xlzxl*xtx1^^1*sixxfxxlx^1*lx*»lz1^^1*£*xl*xjx1^sixxt*xlxxlx^1*lxsix^1*lxxlzxl*\txxtx1^iz/xj%xysXj XJ%Xjs XJXX|XXJXXjsXjS X|X xjxX|Xxyx^jxxjxXjsXj%X|SXJXXjXxjxXjXXjXXJSXgXXJXXjXxjxz|xxjxxjs x|xxj^xjxxjxxyxxjxx|sJxxjsxyszTxxT^xjxX|XXj%^gX^TXZjxXTS***************模拟I2C总线传输程序***********************************sixsixsixsixx£*s£*%fxlx^lxxL*sixsixsixxtxxL*sixsixsixsixlxL*sixsixsix£*^L*lxlxsixsixsixxlzsixsixsixslzsixsix xlx%£zlxsix/x|xXTX✓TxXjXxT✓TxxTxxTv✓TxxxxrxxjxxjxxjxxTx XTX xTx✓!✓!xl xixxTxxfx✓Tx✓Tx✓Txxx xrxXTXXTX✓TXxT/bit ack;/*应答标志位*///^JsxTsxTsxTxzTxzis✓rsxjsXjSxTsxTxzTK x!zrsxisxsxsxxzixzrxztszrsxjsxsxTsxrsxrxztxxrsxsxTsxTsxTszis✓rsxjsxx*rxxTxzTxztsxisxsxTsxxxixzrxztszrsxjsxsxTsxTxxrxztx1x^rsxjsxsxTsxTxzTxzis✓rsxjsxx*TSxTxzTx起动总线函数sixsixsixsixx£*s£*sixlxlx^lxxL*sixsixvlxxtzxL*sixsixsixsixlxsL*xlxsixlxsix£*sL*lxlx^lx^£*sixsixsixxlzlx sixslzsixsixxlxsixlxsix/xjxXTX XTXXgX^XXTXXIX✓Tx1^✓jX^|XXTXXTXXTX✓JxXjVxT✓TXxjx1^✓TX✓!✓jX✓!rx✓Tx✓Jx XjXIX/void Start_I2cSDA=1;/*发送起始条件的数据信号*/_Nop;SCL=1;_Nop;/*起始条件建立时间大于
4.7us,延时*/_Nop;_Nop;_Nop;_Nop;SDA=0;/*发送起始信号*/_Nop;/*起始条件锁定时间大于4u s*/_Nop;_Nop;_Nop;_Nop;SCL=0;/*钳住I2C总线,准备发送或接收数据*/_Nop;_Nop;/sL*sixsixsixsix sixxtz xL*sixsixsixsix xlxsixsixxtxsixvlxlxsixSXX sixxlzsixsixsix£*sixsixsix six/XIXxjx^|X XIXXTXXTX✓jX XgXXTXXIXXX TXIX✓TX✓TXXIXXjXXTX✓TxXTX✓TX✓IX✓!XTX XT结束总线函数si**lz^1*si*ry%»lz rys*lz rys*lzslz*lz*lz rps»lz rys»lz%lz%l*z qSsl rz[*、lz rj*Slz*£*slz%L*rys*fz ZTsSlz rp*»lz*£*slz%rl yz*s rl pz**rlpz»*rl yz**r1y**%rl yz*slzslzslz*l rzp»*l rzp»sl*z y»sl rz y»*l rzy*%l rz
1、s*l yz»*rl jz S*w£y**s rlyz*%ZL r*»s rfjzS*lzslz*1*^1*slz rpsf*z zpsiw*rpsi»x ryv*£*rysi**ry%l*zslzslz%lrzJSsl rzp»*l*zy»sl*z^S%l*z qS//void Stop_I2c SDA=O;/*发送结束条件的数据信号*/_Nop;/*发送结束条件的时钟信号*/SCL=1;/*结束条件建立时间大于4口s*/_Nop;_Nop;_Nop;_Nop;_Nop;SDA=1;/*发送12c总线结束信号*/_Nop;_Nop;_Nop;_Nop;/KI/xTsxTsxTxzTxzis✓rsxjsXjSxTsxTxzTxzrsxisxsxsxxzixzrxztszrsxsxTsxTxxrxztxxrsxsxjsxTsxTsxTxzTxzis✓rsxjsxTsxTsxTxzTxzrsxis✓JsxxxixzrxztszrsxjsxsxTsxTxxrxztxxrsxsxsxTsxTsxTxzTxzis✓rsxjsxTsxTxzTx字节数据传送函数sixsixsixsixx£*s£*sixlxlx^lxxL*sixsixvlxxtzxL*sixsixsixsixlxsL*xlxsixlxsix£*sL*lxlxsixsixsixxlzlx sixslzsixsixxlxsixlxsix/xjxXTX XTXXgXXTXXIX✓Tx1^✓jX^|XXTXXTXXTX✓JxXjVxT✓TXxjx1^✓TX✓!✓jX✓!rx✓Tx✓Jx XjXIX/void SendByteucharcuchar BitCnt;for BitCnt=0;BitCnt8;BitCnt++/*要传送的数据长度为8位*/if c«BitCnt0x80SDA=1;else SDA=0;_Nop;SCL=1;/*置时钟线为高,通知被控器开始接收数据位*/_Nop;_Nop;/*保证时钟高电平周期大于4u s*/_Nop;_Nop;_Nop;SCL=0;}_Nop;_Nop;SDA=1;/*8位发送完后释放数据线,准备接收应答位*/_Nop;_Nop;SCL=1;_Nop;_Nop;_Nop;if SDA==lack=O;else ack=l;/*判断是否接收到应答信号*/SCL=O;_Nop;_Nop;//*T**TXZIXTx#7%#TS^TXXT^ZTV、、*T^XTs XlzXT*Xdz^TX、*T*xj、XT^XTs XizXIs X!z zl%ZTSq、ZIXTx#7%vl*#TSviz*T^^TXXT^ZTV、、、X*TJ*z^TX|X^TS、、K!X T^sl Xz TSvi XzT*zj、、*TX xizs!zsi*K{\tzvtz ZIXTxKJ#Z7%*1#Z TS*T^XTXZTVjX字节数据接收函数**1T****A7****A j*x*z1j*x*yX j*、**j£x*x*y1**z*j1%***jX x*x*j1%*x*ji%z x*jX%*z*y1x*x*j1%**lz*1**lz*1*%lz*1**1*xl*%iz^✓fz jx*1#*JS*1z*T%*lz*1***j£%**|%zy%£z%lz*X***j1%***g1**zs ji%**s yi*x zsjl xz*1**X**1*^g**1*zy*x£*xj*xlzsixsi**J*Nl XzT%*l^zT%*£y*jS*lz%iz xsji%x**jl xz**gl*z*lz y*j1x*x*j1x*%lz x*jl zx*j1%***rX%*z*yX x*z*j2x*//uchar RcvByteucharretc;uchar BitCnt;retc=0;SDA=1;/*置数据线为输入方式*/for BitCnt=0;BitCnt8;BitCnt++_Nop;SCL=O;/*置时钟线为低,准备接收数据位*/_Nop;_Nop;/*时钟低电平周期大于
4.7s*/_Nop;_Nop;_Nop;SCL=1;/*置时钟线为高使数据线上数据有效*/_Nop;_Nop;retc=retcl;if SDA=lretc=retc+1;/*读数据位,接收的数据位放入retc中*/_Nop;_Nop;}SCL=0;_Nop;_Nop;return retc;//X7SX|SXjXX|XZjXZjS✓TSX7SX|SXjSXjXXjXZTSX1SXSXjSXgX✓TxZTXZlSZTSXgSX|SXjXXTXZ1XXJSX7SXjSXgSXjXXTXZjXZjS✓TSX7SX|SXjSXjXZjXZjSX1S✓JsXgXZTXZlSZTSXJSXgSX|SXjXXT*Z1XXTSX7SX7SXgSXjXXTXZjXXjS✓TSX7SX|SxTxXjXZTS应答子函数void Ack_I2cbit aifa==0SDA=0;/*在此发出应答或非应答信号*/else SDA=1;_Nop;_Nop;_Nop;SCL=1;_Nop;_Nop;/*时钟低电平周期大于4口s*/_Nop;_Nop;_Nop;SCL=0;/*清时钟线,钳住12c总线以便继续接收*/_Nop;_Nop;/K!K!KI/X7SX|SXjXX|XZjXZjS✓TSX7SX|SXjSXjXXjXZTSX1SXSXjSXgX✓TxZTXZlSZTSXgSX|SXjXXTXZ1XXJSX7SXjSXgSXjXXTXZjXZjS✓TSX7SX|SXjSXjXZjXZjSX1S✓JsXgXZTXZlSZTSXJSXgSX|SXjXXT*Z1XXTSX7SX7SXgSXjXXTXZjXXjS✓TSX7SX|SxTxXjX向有子地址器件发送多字节数据函数
3.显示芯片电路设计显示芯片采用ZLG7289,晶振为12MHzZLG7289A是广州周立功单片机发展有限公司自行设计的,具有SPI串行接口功能的可同时驱动8位共阴式数码管(或64只独立LED)的智能显示驱动芯片,该芯片同时还可连接多达64键的键盘矩阵,单片即可完成LED显示、键盘接口的全部功能电路如图4所示图4显示芯片电路设计
4.双电源电路设计系统采用双电源,平时使用VI=10V的外接电源,停电时使用电池,由V2输入电池有6节,其电压为9V当电池电压低于6V时,LED亮,说明电池电量不足电路如图5所示图5双电源电路设计
三、程序设计程序开始时先对系统初始化,并设置好各种中断下步操作主要是对时钟芯片进行操作,首先要给时钟芯片设置初值,时钟芯片便自行计数此时检测是否有按键按下,按键是为了调整时钟有按键按下则执行按键中断程序,没有按键按下则执行下一步的操作,即取时钟芯片中的时钟值,然后送显示程序流程图如下图6总体流程图
四、源程序ttinclude reg
51.httinclude intrins.h#include math.h#define ucharunsigned char/*宏定义*/#define uintunsigned intbitISendStr ucharsla,uchar suba,uchar*suchar i;Start_I2c;/*启动总线*/SendByte sla;/*发送器件地址*/SendByte suba;/*发送器件子地址*/ifack==Oreturn0;ifack==0return0;SendByte*s;/*发送数据*/for i=0;i9;i++if ack=0return0;s++;Stop_I2c;/*结束总线*/return1;/*X**1**1*vlx*iz*1**1**1**lz%lz*1**1**lz*lz*1*£**X**1**1**lz*1**£**1*slz*1**1**lz*£**izsi**1**1**lz%lz%lz*1**1**lz*lz*£**1**1**1*1**lz*1**1**tzsiz*lz*lz*£**X**1**1**1**1**1*/*T**gxZJx xjxxj%xj*xjxj%*j%zy**Jxxj**Jxxj*xj%xjx向有子地址器件读取多字节数据函数vizvlx tz*lz1^\tx%£zvtz*1*vlxvfzvf^vtz*lz*1**1*^1**1**lxvtx*lz*1**lx*1*%£**lx*1**lz*1*vt**lz*1**A**£**A**X**A**A**1**Jf*/*T**T**T**T**T**7**1*^r**T**T*^T**7^*T**T**T**T**1^*1**1^*7**7**T**T**7**i**T**T**T^*T^*r**7**T**T****T**T**T**T**1**T**T*^r**T**7^*T*^r**T*^T**T**T**T**T**T**T**T**T**7**4**T*/bit IRcvStrucharsla,uchar suba,uchar*suchar i;Start_I2c;/*启动总线*/SendByte sla;/*发送器件地址*/ifack==Oreturn0;SendBytesuba;/*发送器件子地址*/ifack==0return0;Start_I2c;SendBytesla+1;if ack=0return0;for i=0;i8;i++/*发送数据*/*s=RcvByte;/*发送就答位*/Ack_I2c0;s++;*s=RcvByte;Ack_I2cl;return1;/*发送非应位*/Stop_I2c;void displayuintdis{uchar j;zlg7289_clk=0;delay20;zlg7289_cs=0;forj=0;j16;j++if dis0x8000=0x8000zlg7289_dio=l;else zlg7289dio=0;delay20;zlg7289_clk=l;delay10;zlg7289_clk=0;delay10;dis=disl;}zlg7289_cs=l;delay20;void dis_playuchar aauchar i;fori=0;i8;i++if_crol_aa,i0x80zlg7289_dio=1;elsezlg7289dio=0;zlg7289_clk=1;delay10;zlg7289_clk=0;void displaymonthbuf data=buf
[5]OxOf;zlg7289cs=O;delay10;dis_play0xc8;delay10;dis_playbufdata;zlg7289cs=l;delay70;bufdata=buf
[5]0x30;bufdata=bufdata4;bufdata=bufdata0x0f;zlg7289_cs=0;delay10;dis_play0xc9;delay10;dis_playbufdata;zlg7289_cs=l;delay70;bufdata=buf
[7]0x0f;zig7289cs=0;delay10;dis_playOxca;delay10;dis_playbufdata;zig7289cs=1;delay70;bufdata=buf
[7]0x10;bufdata=bufdata4;bufdata=bufdataOxOf;zlg7289_cs=0;delay10;dis_playOxcf;delay10;dis_playbufdata;zlg7289_cs=l;delay70;}void displaytimebuf data=buf
[3]0x0f;zig7289cs=0;delay10;dis_playOxce;delay10;dis_playbufdata;zig7289cs=1;delay70;bufdata二buf
[3]0x70;bufdata=bufdata4;bufdata=bufdataOxOf;zlg7289_cs=0;delay10;dis_playOxcd;delay10;dis_playbufdata;zlg7289_cs=l;delay70;bufdata=buf
[4]OxOf;zlg7289_cs=0;delay10;dis_playOxcc;delay10;dis_playbufdata;zlg7289_cs=l;delay70;bufdata=buf
[4]0x30;bufdata=bufdata4;bufdata=bufdataOxOf;zlg7289_cs=0;delay10;dis_playOxcb;delay10;dis_playbufdata;zlg7289_cs=l;delay70;}void display_x5045date=ReadByte0x40;close_date=date;bufdata=dateOxOf;zlg7289_cs=0;delay10;dis_playOxce;delay10;displaybufdata;zlg7289_cs=l;delay70;bufdata=date0x70;bufdata=bufdata4;bufdata=bufdataOxOf;zlg7289cs=O;delay10;dis_playOxcd;delay10;dis_playbufdata;zlg7289cs=l;delay70;date=ReadByte0x42;bufdata=dateOxOf;zlg7289_cs=0;open date=ReadByte0x42;delay10;dis_playOxcc;delay10;dis_playbufdata;zlg7289_cs=l;delay70;bufdata=date0x30;bufdata=bufdata4;bufdata=bufdataOxOf;zlg7289_cs=0;delay10;dis_playOxcb;delay10;dis_playbufdata;zlg7289_cs=l;delay70;/****************按键处理程序*********************///key=47:闪烁移位键shift〃key=39:+uchar closedate,open date;void RESWDIvoid;void WRENvoid;void WRDIvoid;void WRSRvoid;unsigned charRSDRvoid;void WIPCHKvoid;void OUTByteunsigned char Byte;unsigned charINPUTBytevoid;unsigned charReadByteunsigned charADD;void WriteByteunsigned charByte,ADD;#def ine_Nop_nop_sbit zlg7289cs=P11;sbit zlg7289_clk=P2-6;sbit zlg7289dio=P2-7;sbit zlg7289_key=P32;sbit p07二PT7;sbit p06=P06;sbit CS=P2M;//key=39:-//key=31:确认键okvoid key intinterrupt0keyint=l;}void keyexe{uchar i;uchar temp=0;uchar aa;p06=l;EXO=1;zlg7289_cs=0;delay10;dis_play0x15;/*写入读键盘数据指令*/delay10;for i=0;i8;i++temp=templ;aa=zlg7289_dio;//按位或if aa==l//读数据位,接收的数据位放入retc中temp=temp+l;zlg7289_clk=l;delay10;//延时zlg7289_clk=0;}zlg7289_cs=l;key=temp;if key=47〃闪烁移位键|key=0;keyok=0;EX0=0;if num=8num=l;elsenum++;case1:{display0x88fe;}break;switchnumcase2:{display0x88fd;}break;case3:{display0x88fb;}break;case4:{display0x88f7;}break;case5:{display0x88ef;}break;case6:{display0x88df;}break;case7:{display0x88bf;}break;case8:{display0x887f;}break;default:EXO=1;}else ifkey=39//+EXO=O;key=O;RESWDI;if num!=0|keyok=0;keychange=l;RESWDI;if num==7〃在分个位上if buf
[3]0x0f==0x09buf
[3]=0xf0;else++buf
[3];EX0=l;bufdata=buf
[3]0x0f;zlg7289_cs=0;delay10;dis_playOxce;delay10;display bufdata;zlg7289_cs=l;delay70;RESWDI;}else ifnum==6〃在分十位上|i fbuf
[3]Oxf0=0x50buf
[3]=OxOf;else buf
[3]+=0x10;EXO=1;bufdata=buf
[3]0x70;bufdata=bufdata4;buf data=buf dataOxOf;zlg7289cs=0;delay10;dis_playOxcd;delay10;dis_playbufdata;zlg7289cs=l;delay70;RESWDI;}else ifnum=5〃在小时个位上{ifbuf
[4]0xf0==0x20ifbuf
[4]0x0f0x02buf
[4]=0xf0;else++buf
[4];else ifbuf
[4]0x0f=0x09buf
[4]=Oxf0;else++buf
[4];EXO=1;bufdata=buf
[4]0x0f;zig7289cs=0;delay10;dis_playOxcc;delay10;dis_playbufdata;zig7289cs=1;delay70;RESWDI;else ifnum=4〃在小时十位上|ifbuf
[4]0x0f0x03if buf
[4]OxfO0x00buf
[4]=OxOf;else buf
[4]+=0x10;}else ifbuf
[4]0xf0==0x20buf
[4]=0x0f;else buf
[4]+=0x10;EXO=1;buf data=buf
[4]0x30;bufdata=bufdata4;bufdata=OxOf;zig7289cs=0;RESWDI;delay10;dis_playOxcb;delay10;dis_playbufdata;zlg7289_cs=l;delay70;RESWDI;}else if num==l〃在日的个位上if buf
[5]0xf0==0x30ifbuf
[5]0x0f0x00buf
[5]=0xf0;else++buf
[5];else ifbuf
[5]OxOf==0x09buf
[5]=0xf0;else++buf
[5];EXO=1;bufdata=buf
[5]0x0f;RESWDI;zig7289cs=0;delay10;dis_play0xc8;delay10;dis_playbufdata;zig7289cs=1;delay70;RESWDI;else ifnum=2〃在日的十位上|ifbuf
[5]0x0f0x01ifbuf
[5]0xf00x10buf
[5]=0x0f;else buf
[5]+=0x10;}else ifbuf
[5]0xf0==0x30buf
[5]=0x0f;else buf
[5]+=0x10;EX0=l;buf data=buf
[5]0x30;RESWDI;bufdata=bufdata4;bufdata=OxOf;zlg7289_cs=0;delay10;dis_play0xc9;delay10;dis_playbufdata;zlg7289_cs=l;delay70;RESWDI;}else ifnum==4〃在月个位上if buf
[7]0xf0==0xl0ifbuf
[7]0x0f0x01buf
[7]=0x0f;else++buf
[7];else ifbuf
[7]0x0f==0x09buf
[7]=0xf0;else++buf
[7];EX0=l;bufdata=buf
[7]0x0f;RESWDI;zig7289cs=0;delay10;dis_playOxca;delay10;dis_playbufdata;zlg7289_cs=l;delay70;RESWDI;}else ifnum==8〃在月十位上ifbuf
[7]0x0f0x02buf
[7]=OxOf;}else ifbuf
[7]0xf0==0xl0buf
[7]=0x0f;else buf
[7]+=0xl0;EXO=1;buf data=buf
[7]0x10;bufdata=bufdata4;bufdata=OxOf;sbit SCK=P22;sbit S0=P2-5;sbit SI=P2^3;sbit pio=pro;sbit SDA=Pr2;/*模拟I2C数据传送位*/sbit SCL二P「3;/*模拟I2C时钟控制位*/ucharuchar bufdata,bb,date;uchar SLA=0xA2,SUBA=0x00;buf
[9]={0x00,0x00,0x30,0x23,0x15,0x1,0x05,0x04,0x05};uchar keychange=0;uchar key=0;/*键盘值*/bit keyint=0;/*按键中断标志*/bit keyok=l;/*数据是否修改好*/ucharuchar num=0;/*移位键移到哪个LED*/RESWDI;zlg7289_cs=0;delay10;dis_playOxcf;delay10;dis_play bufdata;/*显示月十位*/zlg7289_cs=l;delay70;RESWDI;}else;}else ifkey=15〃存放断电时间,数据存放于5045中,每按键数据减少一|display_x5045;EXO=1;key=O;if num!=0keyok=0;ifnum==7〃在分个位上date=ReadByte0x40;if dateOxOf==0x00date|=0x09;else-date;EXO=1;bufdata=dateOxOf;zlg7289_cs=0;delay10;dis_playOxce;delay10;d is_p1aybufdata;zlg7289_cs=l;delay70;WriteByte date,0x40;else ifnum=6〃在分十位上date=ReadByte0x40;if dateOxfO=0x00date|=0x50;EX0-1;bufdata=date0x70;bufdata=bufdata4;bufdata=0x0f;zig7289cs=0;delay10;dis_playOxcd;delay10;dis_playbufdata;zlg7289cs=l;delay70;WriteByte date,0x40;}else ifnum==5〃在小时个位上|date=ReadByte0x42;if date0xf0==0x20ifdateOxOf=OxOO||dateOxOf0x03date|=0x03;else——date;else ifdateOxOf==OxOO date|=0x09;else--date;EXO=1;bufdata=dateOxOf;zlg7289cs=0;delay10;dis_playOxcc;delay10;dis_playbufdata;zlg7289cs=l;delay70;WriteByte date,0x42;else ifnum=4〃在小时十位上date=ReadByte0x42;if dateOxOf0x03i fdateOxf0=0x00date|=0xl0;else date-=OxlO;EXO=1;bufdata=date0x30;bufdata=bufdata4;bufdata=OxOf;zlg7289_cs=0;delay10;dis_playOxcb;delay10;displaybufdata;zlg7289_cs=l;delay70;WriteByte date,0x42;}else ifnum==l〃在日的个位上ifbufE5]0xf0=0x30ifbuf
[5]0x0f=0x00||buf
[5]0x0f0x01buf
[5]|=0x01;else一一buf
[5];else-buf
[5];bufdata=buf
[5]OxOf;zlg7289_cs=0;delay10;dis play0xc8;delay10;dis_playbufdata;zlg7289_cs=l;delay70;else ifnum=2〃在日的十位上ifbuf
[5]0x0f0x01if buf
[5]0xf0==0x00elsebuf
[5]|=0x20;buf
[5]-=0x10;}buf
[5]|=0x30;else ifbuf
[5]0xf0==0x00else buf
[5]-=0xl0;bufdata=buf
[5]0x30;bufdata=bufdata4;bufdata=OxOf;zlg7289_cs=0;delay10;dis_play0xc9;delay10;displaybufdata;zlg7289_cs=l;delay70;else ifnum=3〃在月个位上|ifbuf
[7]0xf0==0xl0ifbuf
[7]0x0f==0x00||buf
[7]0x0f0x01buf
[7]|=0x01;else-buf
[7];else ifbuf
[7]0x0f=0x00buf
[7]|=0x09;else--buf
[7];bufdata=buf
[7]0x0f;zlg7289cs=0;delay10;dis_playOxca;delay10;dis_playbufdata;zig7289cs=1;delay70;else ifnum==8〃在月十位上{ifbuf
[7]0x0f0x02buf
[7]=0x0f;else ifbuf
[7]0xf0==0x00buf
[7]|=OxlO;else buf
[7]-=0xl0;bufdata=buf
[7]0xl0;bufdata=bufdata4;bufdata=OxOf;zlg7289_cs=0;delay10;dis_playOxcf;delay10;dis_playbufdata;zlg7289_cs=l;delay70;EXO=1;elseelse ifkey==31//okEX0=0;key=0;keyok=l;num=0;if keychange==lkeychange=O;p=buf;SUBA=0x00;buf
[0]=0x00;buf[l]=0x00;buf
[2]=0x00;ISendStr SLA,SUBA,p;for i=0;i250;i++delay250;zlg7289cs=O;delay10;dis_play0x88;dis_playOxff;/*清LED闪烁*/delay10;zlg7289cs=l;delay70;EXO=1;void mainunsigned chari,j,word2;TM0D=0x09;TH0=0x3c;TLO-OxbO;void delayuchariwhilei一;}//********************TIMERI interruptprocess***************************//timerO voidinterrupt1using1TH0=0x3c;TLO-OxbO;RESWDI;void RESWDIvoid〃〃复位看门狗喂狗zlg7289cs=l;CS=1;TRO=1;ETO=1;IP=0x02;〃中断优先级敲定ITO=1;EXO=1;IEO=1;EA=1;/*打开全部中断*/plO=l;p06=l;p07=l;WREN;WRSR;WRDI;WriteByte0x07,0x40;〃在0x20中写入0x10,为了验证WriteByte0x0a,0x42;WRDI;word2=ReadByte0x22;/*初始化结束********************************//slzIIJIII,I--Aslzslzsixxixslzslzsixsizslzslzsixsixslzslzslzslzslzslzsixslzslzsixsixslzslzvlxsixxixslzslzslzslzslz//不/曰LLUyb力、不不不不不不不不不不不不不不不不不不不不不不不不不不不不不不不不不不不不不不不不/zlg7289_cs=0;display0xA4;〃复位zlg7289_cs=l;delay70;/*给时钟芯片附初值********************************/Stop_I2c;EX0=0;p=buf;SUBA=0x00;buf
[0]=0x00;buf[l]=0x00;forj=0;j8;j++for i=0;i250;i++delay250;ISendStr SLA,SUBA,p;delay100;EX0-1;while1if keyint==lEXO=1;ETO=1;keyexe;if keychange==Okeyint=O;ETO=1;}for i=0;i250;i++delay250;EXO=1;}if keyok=l keychange=0keyint=0|EX0=0;p=buf;SUBARxOO;IRcvStrSLA,SUBA,p;for i=0;i250;i++buf
[3]=0x7f;buf
[4]=0x3f;buf
[5]=0x3f;buf
[7]=0xlf;displaymonth;displaytime;EXO=1;}if buf
[4]=close_date||buf
[4]=open_date pl0=0;for i=0;i〈250;i++delay25;CS=0;CS=1;zlg7289_cs=l;}void WRENvoid//写使能复位使用{zlg7289_cs=l;SCK=0;cs=o;0UTByte0x06;〃发送06H写使能命令字SCK=0;CS=1;zlg7289_cs=lvoid WRDIvoid〃写使能复位禁止写{zlg7289_cs=l;SCK=O;CS=O;OUTByte0x04;〃发送0411写禁止命令字SCK=0;CS=1;zlg7289_cs=l;void WRSRvoid〃写状态寄存器{WREN;zig7289cs;SCK=0;CS=0;OUTByte0x01;〃发送01H写寄存器命令字OUTByte0x00;〃发送寄存器值BLO,BL1为0没写保护,WD0=0W01=l〃WD1=OWD『O看门狗复位时间
1.4SSCK=O;CS=1;zlg7289cs=l;WIPCHKO;〃判断是否写入unsigned charRSDRvoid//读状态寄存器unsigned charTemp;zlg7289_cs=l;SCK=0;cs=o;OUTByte0x05;〃发送05H读状态寄存器命令字Temp=INPUTByte;〃读状态寄存器值SCK=0;CS=1;return Temp;;〃这一个调试时没有执行,Temp的值总是OxFF;zlg7289cs=l;void WIPCHKvoid〃检查WIP位,判断是否写入完成unsignedcharTemp,TempCyc;for TempCyc=0;TempCyc50;TempCyc++Temp=RSDRO;〃读状态寄存器if Temp0x01==0TempCyc=50;〃单字节指令或数据写入X25045〃在SI线上输入的数据在SCK的上升沿被锁存void OUTByteunsignedcharByte//输出一个定节{unsignedcharTempCyc;zlg7289_cs=l;for TempCyc=0;TempCyc8;TempCyc++SCK=0;if Byte0x80。