一个改造项目,要使用mega8 驱动8563,之前用其他cpu一致很成功,mega8 的twi优点不同
之前程序员留下俩函数,帮忙咋设置?
void PCF_Init(uint8_t mode)
{
TWI_Init();
uint8_t tmp = 0b00000000;
PCF_Write(0x00, &tmp, 1); //Control_status_1
mode &= 0b00010011; //Mask unnecessary bits
PCF_Write(0x01, &mode, 1); //Control_status_2
}
uint8_t PCF_GetDateTime(PCF_DateTime *dateTime)
{
//uint8_t buffer[7];
PCF_Read(0x02, buffer, sizeof(buffer));
dateTime->second = (((buffer[0] >> 4) & 0x07) * 10) + (buffer[0] & 0x0F);
dateTime->minute = (((buffer[1] >> 4) & 0x07) * 10) + (buffer[1] & 0x0F);
dateTime->hour = (((buffer[2] >> 4) & 0x03) * 10) + (buffer[2] & 0x0F);
dateTime->day = (((buffer[3] >> 4) & 0x03) * 10) + (buffer[3] & 0x0F);
dateTime->weekday = (buffer[4] & 0x07);
dateTime->month = ((buffer[5] >> 4) & 0x01) * 10 + (buffer[5] & 0x0F);
dateTime->year = 1900 + ((buffer[6] >> 4) & 0x0F) * 10 + (buffer[6] & 0x0F);
if (buffer[5] & 0x80)
{
dateTime->year += 100;
}
if (buffer[0] & 0x80) //Clock integrity not guaranted
{
return 1;
}
return 0;
}
我想从串口输出时间printf("CLOCK = %d:%d:%d",buffer[2],buffer[1],buffer[0]);对吗
PCF_Init()没太看懂,如何设置 |