PCF8563时钟+AT24C02+LCD12864显示时钟程序
扫描二维码
随时随地手机看文章
//aa0047132563000404
//秒分时日星期和月(最高3位0-6,代表1-7)
#include
#include
#include"hcLCDdot.h"//点阵库
#defineUcharunsignedchar
#defineUintunsignedint
#defineSomeNOP();_nop_();_nop_();_nop_();
/*LCD驱动要用到的一些口线定意*/
#defineLCDPORTP0
sbitD_I=P3^7;
sbitR_W=P3^6;
sbitE=P3^5;
sbitCS1=P3^2;
sbitCS2=P3^4;
sbitRST=P3^3;
/*I2C要用到的口线定意*/
sbitSDA=P2^7;
sbitSCL=P2^6;
////////////以下为函数声明///////////////////////////////
//LCD驱动要用到的一些函数
voidlcdwrite_cmd(Ucharcmd_dat);
voidlcdwrite_dat(Uchardot_dat);
voidlcd_busy();
Ucharlcdread_dat(void);
voidlcddispon(void);
voidlcddispoff(void);
voidlcdclrall(void);
voidlcdini(void);
voidHz12disp(UcharNowrow,UcharNowcol,UcharCHplace);
voidASC12disp(UcharNowrow,UcharNowcol,UcharASCplace);
voidflashlogo(UcharBmpcol);
voidDisp128_64(UcharBMPplace);
voiddelay(void);
//I2C驱动要用到的一些函数
voidDelay_1ms(Uchartime);
voidI2CStart(void);
voidI2CStop(void);
voidACK(void);//AcknowLEDge信号
voidNACK(void);//没有Acknowledge信号
voidAutoACK(void);//在一定的时间内自动确定ACK的信号//
voidWritex(Ucharj);
UcharReadx(void);
voidX24_Write(UcharAddresshigh,UcharAddresslow,UcharWrite_date);
UcharX24_Read(UcharAddresshigh,UcharAddresslow);
voidX24_WritePage(UcharAddresshigh,UcharAddresslow,Ucharidata*Writeip);
voidX24_ReadPage(UcharAddresshigh,UcharAddresslow,Ucharidata*ReaDIP);
voidGetPCF8563(Ucharidata*Getip);
voidSetPCF8563(Ucharidata*Setip);
UcharReadPCF8563(UcharAddrePCF);
voidWritePCF8563(UcharAddrePCF,UcharPCFdata);
voidSetWaring(UcharWyear,UcharWmonth,UcharWday);
bitCheckTime(void);
voidrs232(void);
voidtime0(void);
/*定义一个接收的数组*/
Uchardatarecdata[8];//
UcharidataL24cxxdata[64];//用于读出或写入24C16的数据
UcharidatacLOCkdata[7];//系统时钟
Ucharpcpointer,timecount,timecount2,*gettimeip;//用于设定从PC接收和发的指针
/*定义二个地址编码寄存器,设定地址线稳定时间,定时器2的延时时间参数,动画的时位置参数,发码结束后取消静音的时间*/
UchardataMCaddreh,MCaddrel,MCaddtime,time2_1s,time2_10s,time2_10sx,logocol;
Uintdatanomutetime;
Ucharnewbmpcount;
/*定义标志位存放的寄存器*/
Ucharbdatamyflag,myflag2,bmpflag;//定义一个用于标志寄存器存放的
sbitnomutebit=myflag^0;//用于开始取消静音标志
sbitrecpcokbit=myflag^1;//用于设定接收到一个完整的控制指令码
sbitreturnbit=myflag^2;//用于向PC回传数据标志
sbitfindokbit=myflag^3;//寻找到明码地址
sbitsendbit=myflag^4;//开始发码
sbittimenewbit=myflag^5;//时钟更新标志
sbitcallnewbit=myflag^6;//有新的呼叫
sbitendnewbit=myflag^7;//呼叫结束
sbitw24cxxbit=myflag2^0;//设定明码表
sbittimeoutbit=myflag2^1;
sbitnewtimebit=myflag2^2;//设定新的系统时间
sbitr_lbit=bmpflag^0;
sbitb_wbit=bmpflag^1;//图和文字标志
sbitnewbmpbit=bmpflag^2;//更新图片
voidmain(void)
{
TH0=0xf8;//2ms
TL0=0xce;
TH1=0xfd;//以9600Baud的速率和PC机通信
TL1=0xfd;
TH2=0x4c;//50ms
TL2=0x00;
T2CON=0x00;
TMOD=0x21;//Time0为16位,Time1为8位常数自装
SCON=0x50;
IP=0x10;
TR0=1;
TR1=1;
TR2=1;
time2_1s=0x14;
time2_10s=0x0a;
time2_10sx=0x0c;
IE=0x92;//Time0,Time2,RS232中断
timecount=0x64;
timecount2=0x32;
newbmpcount=0x01;
logocol=0;
r_lbit=0;
timeoutbit=0;
b_wbit=1;
//setadd(80);
lcdini();
while(1)
{
lcdclrall();
HZ12disp(0x00,0x04,0x01);//承
HZ12disp(0x00,0x10,0x02);//接
HZ12disp(0x00,0x1C,0x03);//单
HZ12disp(0x00,0x28,0x04);//片
HZ12disp(0x00,0x34,0x05);//机
HZ12disp(0x00,0x40,0x06);//开
HZ12disp(0x00,0x4C,0x07);//发
HZ12disp(0x00,0x58,0x08);//及
HZ12disp(0x00,0x64,0x09);//解
HZ12disp(0x00,0x70,0x0A);//密
HZ12disp(0x01,0x0A,0x0B);//各
HZ12disp(0x01,0x16,0x0C);//类
ASC12disp(0x01,0x22,0x0B);//I
ASC12disp(0x01,0x28,0x0C);//C
HZ12disp(0x01,0x2E,0x0D);//卡
ASC12disp(0x01,0x3A,0x0D);//;
ASC12disp(0x01,0x40,0x0A);//P
ASC12disp(0x01,0x46,0x0B);//I
ASC12disp(0x01,0x4C,0x0C);//C
HZ12disp(0x01,0x52,0x03);//单
HZ12disp(0x01,0x5E,0x04);//片
HZ12disp(0x01,0x6A,0x05);//机
ASC12disp(0x02,0x0A,0x05);//5
ASC12disp(0x02,0x10,0x01);//1
HZ12disp(0x02,0x16,0x0E);//编
HZ12disp(0x02,0x22,0x0F);//程
HZ12disp(0x02,0x2E,0x10);//器
ASC12disp(0x02,0x3A,0x0D);//;
ASC12disp(0x02,0x40,0x0A);//P
ASC12disp(0x02,0x46,0x0B);//I
ASC12disp(0x02,0x4C,0x0C);//C
HZ12disp(0x02,0x52,0x0E);//编
HZ12disp(0x02,0x5E,0x0F);//程
HZ12disp(0x02,0x6A,0x10);//器
HZ12disp(0x03,0x00,0x14);//星
HZ12disp(0x03,0x0c,0x15);//期
ASC12disp(0x03,0x2c,0x02);//2
ASC12disp(0x03,0x32,0x00);//0
HZ12disp(0x03,0x44,0x11);//年
HZ12disp(0x03,0x5c,0x12);//月
HZ12disp(0x03,0x74,0x13);//日
ASC12disp(0x04,0x5c,0x0e);//:
ASC12disp(0x04,0x6e,0x0e);
while(b_wbit==1)
{
if(timenewbit==1)
{
Ucharnewtime0;
timenewbit=0;
newtime0=(clockdata[6]>>4)&0x0f;
ASC12disp(0x03,0x38,newtime0);
newtime0=clockdata[6]&0x0f;
ASC12disp(0x03,0x3e,newtime0);
newtime0=(clockdata[4]>>4)&0x01;
ASC12disp(0x03,0x50,newtime0);
newtime0=clockdata[4]&0x0f;
ASC12disp(0x03,0x56,newtime0);
newtime0=((clockdata[4]>>5)&0x07)+0x16;
HZ12disp(0x03,0x1B,newtime0);//几号
newtime0=(clockdata[3]>>4)&0x03;
ASC12disp(0x03,0x68,newtime0);
newtime0=clockdata[3]&0x0f;
ASC12disp(0x03,0x6e,newtime0);
newtime0=(clockdata[2]>>4)&0x03;
ASC12disp(0x04,0x50,newtime0);
newtime0=clockdata[2]&0x0f;
ASC12disp(0x04,0x56,newtime0);
newtime0=(clockdata[1]>>4)&0x07;
ASC12disp(0x04,0x62,newtime0);
newtime0=clockdata[1]&0x0f;
ASC12disp(0x04,0x68,newtime0);
newtime0=(clockdata[0]>>4)&0x07;
ASC12disp(0x04,0x74,newtime0);
newtime0=clockdata[0]&0x0f;
ASC12disp(0x04,0x7a,newtime0);
}
if(r_lbit==0)
{
flashlogo(logocol++);
if(logocol==32)
{r_lbit=1;}
lcddispon();
delay();
}
else
{
flashlogo(logocol--);
if(logocol==0)
{r_lbit=0;}
lcddispon();
delay();
}
}
while(b_wbit==0)
{
if(newbmpbit==1)
{
newbmpbit=0;
Disp128_64(newbmpcount);
}
}
}
}
//以下为定时器TIME0中断程序
voidtime0(void)interrupt1
{
TH0=0xf8;
TL0=0xce;
timecount--;
if(timecount==0)
{
timecount=0x64;
gettimeip=&clockdata[0];
GetPCF8563(gettimeip);
//clockdata[0]=0x25;
//clockdata[0]=0x12;
//clockdata[1]=0x34;
//clockdata[2]=0x56;
//clockdata[3]=0x78;
//clockdata[4]=0x90;
//clockdata[5]=0x88;
//clockdata[6]=0x77;
timenewbit=1;
timecount2--;
if(timecount2==0)
{
timecount2=0x32;
b_wbit=!b_wbit;
if(b_wbit==0)
{
newbmpbit=1;
newbmpcount++;
if(newbmpcount==0x03)
{newbmpcount=0x01;}
}
}
}
if(newtimebit==1&&recpcokbit==1)
{
//设定新的系统时间
Uchar*pcfsetip;
newtimebit=0;
recpcokbit=0;
pcfsetip=&recdata[1];
SetPCF8563(pcfsetip);
WritePCF8563(0x00,0x00);
WritePCF8563(0x01,0x00);
WritePCF8563(0x0d,0x83);
}
}
//以下为串行口中断程序,用于接收串行数据
voidrs232(void)interrupt4
{
if(RI==1)
{
//原输入格式为AA秒,分,时日,星期,月年
if(SBUF==0xaa)
{
newtimebit=1;
pcpointer=0;
}
RI=0;
recdata[pcpointer++]=SBUF;
if(pcpointer==8)
{
pcpointer=0;
recpcokbit=1;//指针还原,置收到完整的控制码
}
}
else
{
TI=0;
}
}
voidtime2(void)interrupt5
{
TF2=0;
TH2=0x4c;//50ms
TL2=0x00;
}
/*---------------LCD驱动要用到的一些子程序--------------------*/
/*向LCD写指令*/
voidlcdwrite_cmd(Ucharcmd_dat)
{
D_I=0;
R_W=0;
E=0;
LCDPORT=cmd_dat;
SomeNOP();
E=1;
SomeNOP();
E=0;
}
/*向LCD写数据*/
voidlcdwrite_dat(Uchardot_dat)
{
D_I=1;
R_W=0;
E=0;
LCDPORT=dot_dat;
SomeNOP();
E=1;
SomeNOP();
E=0;
}
/*判断LCD是否处于*/
voidlcd_busy()
{
Uchari;
D_I=0;
R_W=1;
while(1)
{
E=0;
LCDPORT=0xff;
SomeNOP();
E=1;
SomeNOP();
i=LCDPORT;
E=0;
if(i<0x80)break;
}
}
Ucharlcdread_dat(void)
{Uchari;
D_I=1;
R_W=1;
E=0;
LCDPORT=0xff;
SomeNOP();
E=1;
SomeNOP();
i=LCDPORT;
E=0;
LCDPORT=0xff;
SomeNOP();
E=1;
SomeNOP();
i=LCDPORT;
E=0;
return(i);
}
//开LCD显示
voidlcddispon(void)
{
CS1=0;CS2=1;
lcdwrite_cmd(0x3f);
CS1=1;CS2=0;
lcdwrite_cmd(0x3f);
}
//关LCD显示
voidlcddispoff(void)
{
CS1=0;CS2=1;
lcdwrite_cmd(0x3e);
CS1=1;CS2=0;
lcdwrite_cmd(0x3e);
}
//对整屏清除,就是写空的数据
voidlcdclrall(void)
{
Uchari,j;
for(i=0;i<8;i++)
{
CS1=0;CS2=1;
lcdwrite_cmd(i"0xb8);
lcdwrite_cmd(0x40);
for(j=64;j>0;j--)
{
lcdwrite_dat(0x00);
lcd_busy();
//P3_1=!P3_1;
}
CS1=1;CS2=0;
lcdwrite_cmd(i|0xb8);
lcdwrite_cmd(0x40);
for(j=64;j>0;j--)
{
lcdwrite_dat(0x00);
lcd_busy();
}
}
}
//LCD初始化
voidlcdini(void)
{
CS1=0;CS2=1;
lcdwrite_cmd(0xc0);//从第0行开始显示
CS1=1;CS2=0;
lcdwrite_cmd(0xc0);
lcddispon();
}
/*在指定的行列上显示12点阵的汉字*/
voidHZ12disp(UcharNowrow,UcharNowcol,UcharCHplace)
{
Uchari,tmp1,tmp2,k=12;
Uintj;
j=(CHplace-1)*24;
if((Nowrow%2)==0)//
{
switch(Nowrow)
{
case0:i=0;break;
case2:i=3;break;
default:i=6;
}
while(k!=0)
{
if(Nowcol<0x40)
{CS1=0;CS2=1;}
else
{if(Nowcol<0x80)
{CS1=1;CS2=0;}
else
{break;}
}
lcdwrite_cmd(i|0xb8);
lcdwrite_cmd(Nowcol|0x40);
lcdwrite_dat(Hzk12[j]);
lcd_busy();
lcdwrite_cmd((i+1)|0xb8);//到下一页
lcdwrite_cmd(Nowcol|0x40);
tmp1=lcdread_dat();
lcdwrite_cmd(Nowcol|0x40);
lcdwrite_dat((Hzk12[j+12]&0x0f)|(tmp1&0xf0));
j++;
Nowcol++;
k--;
}
}
else
{
switch(Nowrow)
{
case1:i=1;break;
default:i=4;
}
while(k!=0)
{
if(Nowcol<0x40)
{CS1=0;CS2=1;}
else
{
if(Nowcol<0x80)
{CS1=1;CS2=0;}
else
{break;}
}
lcdwrite_cmd(i|0xb8);
lcdwrite_cmd(Nowcol|0x40);
tmp1=lcdread_dat();
tmp1=tmp1&0x0f;
tmp1=(Hzk12[j]<<4)|tmp1;
tmp2=(Hzk12[j+12]<<4)|(Hzk12[j]>>4);
lcdwrite_cmd(Nowcol|0x40);
lcdwrite_dat(tmp1);
lcd_busy();
lcdwrite_cmd((i+1)|0xb8);
lcdwrite_cmd(Nowcol|0x40);
lcdwrite_dat(tmp2);
j++;
Nowcol++;
k--;
}
}
}
//6*12点阵的ASC码显示程序
voidASC12disp(UcharNowrow,UcharNowcol,UcharASCplace)
{
Uchari,tmp1,tmp2,k=6;
Uintj;
j=ASCplace*12;
if((Nowrow%2)==0)//
{
switch(Nowrow)
{
case0:i=0;break;
case2:i=3;break;
default:i=6;
}
while(k!=0)
{
if(Nowcol<0x40)
{CS1=0;CS2=1;}
else
{if(Nowcol<0x80)
{CS1=1;CS2=0;}
else
{break;}
}
lcdwrite_cmd(i|0xb8);
lcdwrite_cmd(Nowcol|0x40);
lcdwrite_dat(ASC12[j]);
lcd_busy();
lcdwrite_cmd((i+1)|0xb8);//到下一页
lcdwrite_cmd(Nowcol|0x40);
tmp1=lcdread_dat();
lcdwrite_cmd(Nowcol|0x40);
lcdwrite_dat((ASC12[j+6]&0x0f)|(tmp1&0xf0));
j++;
Nowcol++;
k--;
}
}
else
{
switch(Nowrow)
{
case1:i=1;break;
default:i=4;
}
while(k!=0)
{
if(Nowcol<0x40)
{CS1=0;CS2=1;}
else
{
if(Nowcol<0x80)
{CS1=1;CS2=0;}
else
{break;}
}
lcdwrite_cmd(i|0xb8);
lcdwrite_cmd(Nowcol|0x40);
tmp1=lcdread_dat();
tmp1=tmp1&0x0f;
tmp1=(ASC12[j]<<4)|tmp1;
tmp2=(ASC12[j+6]<<4)|(ASC12[j]>>4);
lcdwrite_cmd(Nowcol|0x40);
lcdwrite_dat(tmp1);
lcd_busy();
lcdwrite_cmd((i+1)|0xb8);
lcdwrite_cmd(Nowcol|0x40);
lcdwrite_dat(tmp2);
j++;
Nowcol++;
k--;
}
}
}
//以动画的形式显示公司的标志,入口为在水平的第几个位置,现把它做,从32到1,由2张32X16的图组成
voidflashlogo(UcharBmpcol)
{
Uchari,j,p;
//把当前要用的区间清空
CS1=0,CS2=1;
lcdwrite_cmd(0xbe);
lcdwrite_cmd(0x40);
for(i=64;i>0;i--)
{
lcdwrite_dat(0x00);
lcd_busy();
}
lcdwrite_cmd(0xbf);
lcdwrite_cmd(0x40);
for(i=64;i>0;i--)
{
lcdwrite_dat(0x00);
lcd_busy();
}
//开始写要设定的数据(左半边)
lcdwrite_cmd(0xbe);
lcdwrite_cmd(0x40);
j=Bmpcol;
for(;j<=32;j++)
{
lcdwrite_dat(Bmp1zk[j-1]);
lcd_busy();
}
lcdwrite_cmd(0xbf);
lcdwrite_cmd(0x40);
j=Bmpcol;
for(;j<=32;j++)
{
lcdwrite_dat(Bmp1zk[j-1+32]);
lcd_busy();
}
//开始写要设定的数据(右半边)
j=Bmpcol;
lcdwrite_cmd(0xbe);
lcdwrite_cmd((32+j-1)|0x40);
p=0;
for(;j<=32;j++)
{
lcdwrite_dat(Bmp2zk[p++]);
lcd_busy();
}
j=Bmpcol;
lcdwrite_cmd(0xbf);
lcdwrite_cmd((32+j-1)|0x40);
p=0;
for(;j<=32;j++)
{
lcdwrite_dat(Bmp2zk[32+(p++)]);
lcd_busy();
}
}
//显示一幅128X64的图片,参数为图片在bmp12864放置的第几个图
voidDisp128_64(UcharBMPplace)
{
Uchari,Nowcol,k;
Uintj;
j=(BMPplace-1)*1024;//计算出在图表格中的起始位置
lcdclrall();
for(i=0;i<8;i++)
{Nowcol=0x00;
k=128;
while(k!=0)
{
if(Nowcol<0x40)
{CS1=0;CS2=1;}
else
{if(Nowcol<0x80)
{CS1=1;CS2=0;}
else
{break;}
}
lcdwrite_cmd(i|0xb8);
lcdwrite_cmd(Nowcol|0x40);
lcdwrite_dat(bmp12864[j]);
lcd_busy();
Nowcol++;
j++;
k--;
}
}
}
voiddelay(void)
{
Uchari,j,k;
for(i=0x02;i>0;i--)
{
for(j=0x96;j>0;j--)
{
for(k=0xfa;k>0;k--)
{
_nop_();
//_nop_();
}
}
}
}
/*----------------------I2C要用到的一些子程序---------------------------------*/
/***********************以下为一些用到的子程序*********************************/
/*延时子程序*/
voidDelay_1ms(Uchartime)
{
Ucharj;
while(time--)
{
for(j=163;j!=0;j--)
{;}
}
}
/*I2C的起动程序*/
voidI2CStart(void)
{
SDA=1;
SomeNOP();
SCL=1;
SomeNOP();
SDA=0;
SomeNOP();
SCL=0;
SomeNOP();
}
/*I2C的停止程序*/
voidI2CStop(void)
{
SDA=0;
SomeNOP();
SCL=1;
SomeNOP();
SDA=1;
SomeNOP();
}
voidACK(void)//Acknowledge信号
{
SDA=0;
SomeNOP();
SCL=1;
SomeNOP();
SCL=0;
SomeNOP();
}
voidNACK(void)//没有Acknowledge信号
{
SDA=1;
SomeNOP();
SCL=1;
SomeNOP();
SCL=0;
SomeNOP();
}
voidAutoACK(void)//在一定的时间内自动确定ACK的信号//
{
Uchari=0;
SCL=1;
SomeNOP();
while((SDA==1)&&(i<255))i++;
SCL=0;
SomeNOP();
}
/*I2C写数据程序(向数据线上写一个BYTE)*/
voidWritex(Ucharj)
{
Uchari,temp;
temp=j;
for(i=0;i<8;i++)//串行移位,先送高位,再送低位//
{
temp=temp<<1;
SCL=0;
SomeNOP();
SDA=CY;
SomeNOP();
SCL=1;
SomeNOP();
}
SCL=0;
SomeNOP();
SDA=1;
SomeNOP();
}
/*I2C读数据程序(从数据线上读出一个BYTE)返回值为读出的数据(BYTE型)*/
UcharReadx(void)
{
Uchari,j,k=0;
SCL=0;
SomeNOP();
SDA=1;
for(i=0;i<8;i++)//串行移位,先读出高位,后读出低位//
{
SomeNOP();
SCL=1;
SomeNOP();
if(SDA==1)j=1;
elsej=0;
k=(k<<1)|j;
SCL=0;
}
SomeNOP();
return(k);//返回读出的值//
}
//******************以下为对24CXX系列的读写程序******************************//
//*************24CXX的devICeaddress为写0A0H,读为0A1H*********************//
/*某个地址写数据*/
voidX24_Write(UcharAddresshigh,UcharAddresslow,UcharWrite_date)
{
I2CStart();
Writex(0xA0);
AutoACK();
Writex(Addresshigh);
AutoACK();
Writex(Addresslow);
AutoACK();
Writex(Write_date);
AutoACK();
I2CStop();
Delay_1ms(10);
}
/*对某个地址读操作,函数值为读出的数据*/
UcharX24_Read(UcharAddresshigh,UcharAddresslow)
{
Uchari;
I2CStart();
Writex(0xA0);
AutoACK();
Writex(Addresshigh);
AutoACK();
Writex(Addresslow);
AutoACK();
I2CStart();
Writex(0xA1);
AutoACK();
i=Readx();
//ACK();//注意:这里不能有ACK应答信号//
I2CStop();
Delay_1ms(0);
return(i);
}
/*对内存中的数据块写入,入口为写EEPROM的地址,内存缓冲中的数据的起始地址(是IDATA的数据)*/
voidX24_WritePage(UcharAddresshigh,UcharAddresslow,Ucharidata*Writeip)
{
Uchari;
I2CStart();
Writex(0xA0);
AutoACK();
Writex(Addresshigh);
AutoACK();
Writex(Addresslow);
AutoACK();
for(i=0;i<64;i++)
{
Writex(*Writeip++);
AutoACK();
}
I2CStop();
}
/*把EEPROM中的数据读出来存放在内存缓冲中,起始地址为(是IDATA的数据)*/
voidX24_ReadPage(UcharAddresshigh,UcharAddresslow,Ucharidata*Readip)
{
Uchari;
I2CStart();
Writex(0xA0);
AutoACK();
Writex(Addresshigh);
AutoACK();
Writex(Addresslow);
AutoACK();
I2CStart();
Writex(0xA1);
AutoACK();
for(i=0;i<63;i++)//PAGE读的时候最后一个BYTE不要ACK信号//
{
*Readip=Readx();
Readip=Readip++;
ACK();
}
*Readip=Readx();
NACK();
I2CStop();
Delay_1ms(0);
}
//*******************以下为对PCF8383/PCF8563的读写子程序********************//
//**********时钟片deviceaddress的写地址为0A2H,读地址为0A3H******************//
/*对PCF8563的时钟读到内存中,以IDATA指针开始的连续7个BYTE*/
//****读出的内容依次为“秒,分钟,小时,日,星期,月/世纪,年********************//
//PCF8585依次为“秒,分钟,小时,日,星期月
voidGetPCF8563(Ucharidata*Getip)
{
Uchari;
I2CStart();
Writex(0xA2);
AutoACK();
Writex(0x02);//从秒地址开始读//
AutoACK();
I2CStart();
Writex(0xA3);
AutoACK();
for(i=0;i<6;i++)
{
*Getip=Readx();
Getip=Getip++;
ACK();
}
*Getip=Readx();
NACK();
I2CStop();
Delay_1ms(0);
}
/*设定8563/8583的时间内容依次为“秒,分钟,小时,日,星期,月/世纪,年*/
//PCF8585依次为“秒,分钟,小时,日,星期月
voidSetPCF8563(Ucharidata*Setip)
{
Uchari;
I2CStart();
Writex(0xA2);
AutoACK();
Writex(0x02);
AutoACK();
for(i=0;i<7;i++)
{
Writex(*Setip++);
AutoACK();
}
I2CStop();
}
UcharReadPCF8563(UcharAddrePCF)
{
Uchari;
I2CStart();
Writex(0xA2);
AutoACK();
Writex(AddrePCF);
AutoACK();
I2CStart();
Writex(0xA3);
AutoACK();
i=Readx();
//ACK();//注意:这里不能有ACK应答信号//
I2CStop();
Delay_1ms(0);
return(i);
}
voidWritePCF8563(UcharAddrePCF,UcharPCFdata)
{
I2CStart();
Writex(0xA2);
AutoACK();
Writex(AddrePCF);
AutoACK();
Writex(PCFdata);
AutoACK();
I2CStop();
Delay_1ms(10);
}
voidSetWaring(UcharWyear,UcharWmonth,UcharWday)
{
X24_Write(0x07,0xf0,Wyear);
X24_Write(0x07,0xf1,Wmonth);
X24_Write(0x07,0xf2,Wday);
}
/*返回值为1和0,1为已溢出,0为没有溢出*/
bitCheckTime(void)
{
Ucharj,k;
j=X24_Read(0x07,0xcb);
k=ReadPCF8563(0x08);/*读年的时间*/
if(k
return(0);
}
else
{
if(k>j)
{
return(1);
}
else
{
j=X24_Read(0x07,0xCC);
k=ReadPCF8563(0x07)&0x1f;/*读月的时间*/
if(k
return(0);
}
else
{
if(k>j)
{
return(1);
}
else
{
j=X24_Read(0x07,0xcd);
k=ReadPCF8563(0x05)&0x3f;/*读日的时间*/
if(k>j)return(1);
elsereturn(0);
}
}
}
}
}