uint16 read_8563_realtime(void) //ctrl_addres 是控制字段 //addres是地址 { uint16 temp; uint16 *pt; pt=&temp; if(I2C_ReadNByte (0x00, pt, 0x01)) { if((*pt&0xa8)!=0) { *pt=0; I2C_WriteNByte(0x0C, pt, 0x01); I2C_WriteNByte(0x0D, pt, 0x01); I2C_WriteNByte(0x0F, pt, 0x01); I2C_WriteNByte(0x00, pt, 0x01); I2C_WriteNByte(0x01, pt, 0x01); __asm{ NOP NOP NOP NOP } *pt=0x81; I2C_WriteNByte(0x0E, pt, 0x01); } } pt=(uint16 *)&rt_time_buf.second; if(I2C_ReadNByte (0x02, pt, 0x07)==0) { if(I2C_ReadNByte (0x02, pt, 0x07)==0) return 0; } temp=rt_time_buf.second; temp=temp & 0x7f ; //59 if(temp<=0x59) rt_time.second=temp; else return 0; temp=rt_time_buf.minute; temp=temp & 0x7f ; //59 if(temp<=0x59) rt_time.minute=temp; else return 0;
temp=rt_time_buf.hour;//23 temp=temp & 0x3f; if(temp<=0x23) rt_time.hour=temp; else return 0;
temp=rt_time_buf.day;//31 temp=temp & 0x3f; if(temp<=0x31) rt_time.day=temp; else return 0;
temp=rt_time_buf.month;//12 temp=temp & 0x1f; if(temp<=0x12) rt_time.month=temp& 0x1f; else return 0;
temp=rt_time_buf.year; if(temp<=0x99) { rt_time.year=temp; return 1; } else return 0; }
在读操作的时候I2C_ReadNByte (0x00, pt, 0x01),地址0x00读出来的数据一直是0x80,而不是设置的0x00,时间也就一直是设置进去的值,时钟芯片没有计时工作 |