|
发表于 2012-6-28 17:38:47
|
显示全部楼层
#define CLOCK_ADDR 0xA2 // PCF8563器件地址以及写入操作
//#define CLOCK_READ 0xA3 // PCF8563器件地址以及读取操作
#define CLOCK_STOP_BIT 0X20 //pcf8563停止位0010 0000 bit5=1表示芯片停止了工作
#define CLOCK_STATUS_ADDR1 0x00
#define CLOCK_STATUS_ADDR2 0x01
#define CLOCK_SECOND_ADDR 0x02
#define CLOCK_MINUTE_ADDR 0x03
#define CLOCK_HOUR_ADDR 0x04
#define CLOCK_DATE_ADDR 0x05
#define CLOCK_WEEK_ADDR 0x06
#define CLOCK_MONTH_ADDR 0x07
#define CLOCK_YEAR_ADDR 0x08
#define CLOCK_ALARM1_MINUTE_ADDR 0x09
#define CLOCK_ALARM1_HOUR_ADDR 0x0A
#define CLOCK_ALARM1_DAY_ADDR 0x0B
#define CLOCK_ALARM1_WEEKDAY_ADDR 0x0C
#define CLOCK_CONTROL_ADDR 0x0D
#define CLOCK_TIME_CONTROL_ADDR 0x0E
#define CLOCK_TIME_DATA_ADDR 0x0F
void clock_init()
{
uchar data da_00=0;
da_00 = read_byte(CLOCK_ADDR,0x00);
da_00 &= CLOCK_STOP_BIT;
//if(((da_00>>4)&&(da_00<<2))==1) //地址0x00,STOP位检测,如果等于一,说明芯片已经停止工作了,重新写入初值
if(da_00 == CLOCK_STOP_BIT) //地址0x00,STOP位检测,如果等于一,说明芯片已经停止工作了,重新写入初值
{
write_byte(CLOCK_ADDR,0x00,0x00); /*写入地址:0x00的数据,STOP=0,时钟运行*/
write_byte(CLOCK_ADDR,0x01,0x01); /*报警AF,无效,TI/TP=0,TIE=1*/
write_byte(CLOCK_ADDR,CLOCK_SECOND_ADDR,0x35); /*秒初值*/
write_byte(CLOCK_ADDR,CLOCK_MINUTE_ADDR,0x59); /*分初值*/
write_byte(CLOCK_ADDR,CLOCK_HOUR_ADDR,0x23); /*小时初值*/
write_byte(CLOCK_ADDR,CLOCK_DATE_ADDR,0x24); /*日初值*/
write_byte(CLOCK_ADDR,CLOCK_WEEK_ADDR,0x03); /*星期3初值*/
write_byte(CLOCK_ADDR,CLOCK_MONTH_ADDR,0x0C); /*月份12月,世纪位设置为0 */
write_byte(CLOCK_ADDR,CLOCK_YEAR_ADDR,0x11); /*年初值11年,地址:0x08*/
write_byte(CLOCK_ADDR,0x09,0x80); /*分钟报警地址(0x09)数据设置,报警无效*/
write_byte(CLOCK_ADDR,0x0A,0x80); /*小时报警地址(0x0A)数据设置,报警无效*/
write_byte(CLOCK_ADDR,0x0B,0x80); /*日期报警地址(0x0B)数据设置,报警无效*/
write_byte(CLOCK_ADDR,0x0C,0x80); /*星期报警地址(0x0c)数据设置,报警无效*/
write_byte(CLOCK_ADDR,0x0D,0x00); /*输出32768HZ的频率关闭,地址是(0x0d)*/
write_byte(CLOCK_ADDR,CLOCK_TIME_CONTROL_ADDR,0x81); /*定时器控制寄存器,TE=1,TD0=0,TD1=0,(64Hz)地址(0x0e)*/
write_byte(CLOCK_ADDR,CLOCK_TIME_DATA_ADDR,0x40); /*设置定时器到计数器数值64,即定时时间是1S.地址(0x0f)*/
delay_ms(50);
}
} |
|