| 代码逻辑上没问题。我记得printf是不能传入太多叁数。7个叁数可能太多了, 试试只传入秒的数据。 |
|
//从DS302读出时钟数据 void DS1302_Read_Time(void) { time_buf[1] = DS1302_Read_Byte(ds1302_year_add); //年 time_buf[2] = DS1302_Read_Byte(ds1302_month_add); //月 time_buf[3] = DS1302_Read_Byte(ds1302_date_add); //日 time_buf[4] = DS1302_Read_Byte(ds1302_hr_add); //时 time_buf[5] = DS1302_Read_Byte(ds1302_min_add); //分 time_buf[6] = (DS1302_Read_Byte(ds1302_sec_add))&0x7f; //秒,屏蔽秒的第7位,避免超出59 time_buf[7] = DS1302_Read_Byte(ds1302_day_add); //周 } //DS1302向上层返回时间数据 void DS1302_Get_Time(u8 *time) { DS1302_Read_Time(); time[0]=(time_buf[0]>>4); //年 time[1]=(time_buf[0]&0x0f); time[2]=(time_buf[1]>>4); time[3]=(time_buf[1]&0x0f); time[4]=(time_buf[2]>>4); //月 time[5]=(time_buf[2]&0x0f); time[6]=(time_buf[3]>>4); //日 time[7]=(time_buf[3]&0x0f); time[8]=(time_buf[7]&0x07); //星期 time[9]=(time_buf[4]>>4); //时 time[10]=(time_buf[4]&0x0f); time[11]=(time_buf[5]>>4); //分 time[12]=(time_buf[5]&0x0f); time[13]=(time_buf[6]>>4); //秒 time[14]=(time_buf[6]&0x0f); } 更新日期时间数组的部分程序有问题。。。。没这硬件。。。。。调试原始的数据吧,看看具体哪读的问题 |