2019-07-20 19:59发布
liarlaker 发表于 2016-9-12 16:34 我都用内置上拉了,少焊两个电阻,何乐不为呢?你把程序传上来看看
liarlaker 发表于 2016-9-13 10:06 兄弟,抱歉没时间细看,但是我觉得问题不在这里,应该在你主程序执行过程中,你看看你的中断程序部分。
最多设置5个标签!
使用了内部的上拉也一样的效果
void I2C_GPIO_Config(void)
{
uint8_t i;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOF, ENABLE);
GPIO_InitStructure.GPIO_Pin = I2C_SCL|I2C_SDA;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOF, &GPIO_InitStructure);
}
u8 PCF8563_SetDate(u8 PCF_Format, RTC_DateTypeDef* PCF_DataStruct)
{
RTC_DateTypeDef SetDate_Stu;
u8 ret = TRUE;
if(PCF_Format == PCF_Format_HEX) // 16进制
{
// 转换BCD 码
SetDate_Stu.RTC_Year = RTC_HexToBcd(PCF_DataStruct->RTC_Year);
SetDate_Stu.RTC_Month = RTC_HexToBcd(PCF_DataStruct->RTC_Month);
SetDate_Stu.RTC_Date = RTC_HexToBcd(PCF_DataStruct->RTC_Date);
SetDate_Stu.RTC_WeekDay = RTC_HexToBcd(PCF_DataStruct->RTC_WeekDay);
}
else if(PCF_Format == PCF_Format_BCD) // BCD 码
{
SetDate_Stu.RTC_Year = (PCF_DataStruct->RTC_Year);
SetDate_Stu.RTC_Month = (PCF_DataStruct->RTC_Month);
SetDate_Stu.RTC_Date = (PCF_DataStruct->RTC_Date);
SetDate_Stu.RTC_WeekDay = (PCF_DataStruct->RTC_WeekDay);
}
// 写进PCF8563
ret = Rtc8563Write(PCF8563_Address_Years,SetDate_Stu.RTC_Year);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_Months,SetDate_Stu.RTC_Month);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_Days,SetDate_Stu.RTC_Date);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_WeekDays,SetDate_Stu.RTC_WeekDay);
if(ret == FALSE)
goto ERROR;
return TRUE;
ERROR:
return FALSE;
}
u8 PCF8563_SetTime(u8 PCF_Format, RTC_TimeTypeDef* PCF_TimeStruct)
{
RTC_TimeTypeDef SetTime_Stu;
u8 ret = TRUE;
if(PCF_Format == PCF_Format_HEX) // 16进制
{
// 转换BCD 码
SetTime_Stu.RTC_Hours = RTC_HexToBcd(PCF_TimeStruct->RTC_Hours);
SetTime_Stu.RTC_Minutes = RTC_HexToBcd(PCF_TimeStruct->RTC_Minutes);
SetTime_Stu.RTC_Seconds = RTC_HexToBcd(PCF_TimeStruct->RTC_Seconds);
}
else if(PCF_Format == PCF_Format_BCD) // BCD 码
{
SetTime_Stu.RTC_Hours = (PCF_TimeStruct->RTC_Hours);
SetTime_Stu.RTC_Minutes = (PCF_TimeStruct->RTC_Minutes);
SetTime_Stu.RTC_Seconds = (PCF_TimeStruct->RTC_Seconds);
}
// 写进PCF8563
ret = Rtc8563Write(PCF8563_Alarm_Hours,SetTime_Stu.RTC_Hours);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_Minutes,SetTime_Stu.RTC_Minutes);
if(ret == FALSE)
goto ERROR;
ret = Rtc8563Write(PCF8563_Address_Seconds,SetTime_Stu.RTC_Seconds);
if(ret == FALSE)
goto ERROR;
return TRUE;
ERROR:
return FALSE;
}
u8 PCF8563_GetDate(u8 PCF_Format, RTC_DateTypeDef* PCF_DataStruct)
{
/*
PCF_DataStruct->RTC_Years = Rtc8563Read(PCF8563_Address_Years);
PCF_DataStruct->RTC_Months= Rtc8563Read(PCF8563_Address_Months);
PCF_DataStruct->RTC_Days= Rtc8563Read(PCF8563_Address_Days);
PCF_DataStruct->RTC_WeekDays= Rtc8563Read(PCF8563_Address_WeekDays);
*/
PCF_DataStruct->RTC_Year= Rtc8563Read(PCF8563_Address_Years);
PCF_DataStruct->RTC_Month= Rtc8563Read(PCF8563_Address_Months);
PCF_DataStruct->RTC_Date= Rtc8563Read(PCF8563_Address_Days);
// PCF_DataStruct->RTC_WeekDay= Rtc8563Read(PCF8563_Address_WeekDays);
if(PCF_Format == PCF_Format_HEX)
{
// 转回16进制
PCF_DataStruct->RTC_Year = ((PCF_DataStruct->RTC_Year>>4)*10) + (PCF_DataStruct->RTC_Year&0x0F);
PCF_DataStruct->RTC_Month = ((PCF_DataStruct->RTC_Month>>4)*10) + (PCF_DataStruct->RTC_Month&0x0F);
PCF_DataStruct->RTC_Date = ((PCF_DataStruct->RTC_Date>>4)*10) + (PCF_DataStruct->RTC_Date&0x0F);
PCF_DataStruct->RTC_WeekDay = ((PCF_DataStruct->RTC_WeekDay>>4)*10) + (PCF_DataStruct->RTC_WeekDay&0x0F);
}
}
u8 PCF8563_GetTime(u8 PCF_Format, RTC_TimeTypeDef* PCF_TimeStruct)
{
PCF_TimeStruct->RTC_Hours = Rtc8563Read(PCF8563_Address_Hours);
PCF_TimeStruct->RTC_Minutes = Rtc8563Read(PCF8563_Address_Minutes);
PCF_TimeStruct->RTC_Seconds = Rtc8563Read(PCF8563_Address_Seconds);
UART6_SendByte(PCF_TimeStruct->RTC_Hours);
UART6_SendByte(PCF_TimeStruct->RTC_Minutes);
UART6_SendByte(PCF_TimeStruct->RTC_Seconds);
if(PCF_Format == PCF_Format_HEX)
{
// 转回16进制
PCF_TimeStruct->RTC_Hours = ((PCF_TimeStruct->RTC_Hours>>4)*10) + (PCF_TimeStruct->RTC_Hours&0x0F);
PCF_TimeStruct->RTC_Minutes = ((PCF_TimeStruct->RTC_Minutes>>4)*10) + (PCF_TimeStruct->RTC_Minutes&0x0F);
PCF_TimeStruct->RTC_Seconds = ((PCF_TimeStruct->RTC_Seconds>>4)*10) + (PCF_TimeStruct->RTC_Seconds&0x0F);
}
}
没有用中断处理,I2C上还挂了AT24C1024
一周热门 更多>