#include "extern_rtc.h" #include "i2c.h" #include "uart.h" #include "sundry.h" #include "ex_rtc.h" //__IO CALENDAR_TIME_T calendar_g = {0}; __IO CALENDAR_TIME_T calendar_test_g = {0}; void R8025T_Write(uint8_t sadd,uint8_t * pBuffer,uint8_t length) { #if SOFT_OR_HARD I2c_Start(); I2c_Send(RX8025_WRITE_ADDR); I2c_Send(sadd);//д¼Ä´æÆ÷´¢´æµØÖ· for(uint8_t i = 0;i < length;i++) I2c_Send(pBuffer[i]); I2c_Stop(); #else I2C_Send_Bit(I2C0,STARTBIT); I2C_Send_Byte(I2C0,RX8025_WRITE_ADDR); I2C_Send_Byte(I2C0,sadd); for(uint8_t i = 0;i < length;i++) I2C_Send_Byte(I2C0,pBuffer[i]); I2C_Send_Bit(I2C0,STOPBIT); #endif } void R8025T_Read(uint8_t sadd,uint8_t * pBuffer,uint8_t length) { uint8_t i = 0; #if SOFT_OR_HARD I2c_Start(); I2c_Send(RX8025_WRITE_ADDR); I2c_Send(sadd);//·¢ËͼĴæÆ÷µØÖ· I2c_Start();//SrÌõ¼þ£¬RESTART I2c_Send(RX8025_READ_ADDR); for(i = 0;i < length - 1;i++) { pBuffer[i] = I2c_Read(); I2c_Ack(); } pBuffer[i] = I2c_Read(); I2c_No_Ack(); I2c_Stop(); #else I2C_Send_Bit(I2C0,STARTBIT); I2Cx_CR_RCEN_Setable(I2C0,DISABLE ); I2C_Send_Byte(I2C0,RX8025_WRITE_ADDR); I2C_Send_Byte(I2C0,sadd); I2C_Send_Bit(I2C0,RESTARTBIT); I2C_Send_Byte(I2C0,RX8025_READ_ADDR); for(i = 0;i < length - 1;i++) { I2C_Receive_Byte(I2C0,&pBuffer[i]); I2C_SEND_ACK_0(I2C0); } I2C_Receive_Byte(I2C0,&pBuffer[i]); I2C_SEND_ACK_1(I2C0);; I2C_Send_Bit(I2C0,STOPBIT); #endif } //ÉèÖÃÍⲿRTCʱ¼ä //²ÎÊý£ºBCD¸ñʽ void Set_Extern_Rtc_Time(uint16_t year,uint8_t month,uint8_t day,uint8_t week,uint8_t hour,uint8_t min,uint8_t sec) { uint8_t time[7] = {0,0,0,0,1,1,0x15}; year &= 0x00FF; if(Bcd_2_Hex(sec) < 60) time[0] = sec; if(Bcd_2_Hex(min) < 60) time[1] = min; if(Bcd_2_Hex(hour) < 24) time[2] = hour; time[3] = week; if(Bcd_2_Hex(day) < 32) time[4] = day; if(Bcd_2_Hex(month) < 13) time[5] = month; if(Bcd_2_Hex(year) < 100) time[6] = year; // R8025T_Write(0,time,7); R8025T_write(0,time,7); } //»ñÈ¡ÍⲿRTCʱ¼ä void Get_Extern_Rtc_Time(__IO CALENDAR_TIME_T * calendar_p) { uint8_t rtc_time[7]; // R8025T_Read(0,rtc_time,7); R8025T_read(0,rtc_time,7); if(Bcd_2_Hex(rtc_time[0]) < 60) calendar_p->second = rtc_time[0]; else calendar_p->second = 0; if(Bcd_2_Hex(rtc_time[1]) < 60) calendar_p->minute = rtc_time[1]; else calendar_p->minute = 0; if(Bcd_2_Hex(rtc_time[2]) < 24) calendar_p->hour = rtc_time[2]; else calendar_p->hour = 0; calendar_p->week = rtc_time[3]; if(Bcd_2_Hex(rtc_time[4]) < 32) calendar_p->day = rtc_time[4]; else calendar_p->day = 1; if(Bcd_2_Hex(rtc_time[5]) < 13) calendar_p->month = rtc_time[5]; else calendar_p->month = 0x12; if(Bcd_2_Hex(rtc_time[6]) < 100) calendar_p->year = 0x2000 + rtc_time[6]; else calendar_p->year = 0x2015; #ifdef RS232_PRINTF printf("EX_RTC_TIME = %X-%02X-%02X-%02X-%02X-%02X \r\n",calendar_p->year,calendar_p->month,calendar_p->day, calendar_p->hour,calendar_p->minute,calendar_p->second); #endif } void Set_Rtc_UpdataInterrupt(void) { uint8_t rtc_reg[5]; // rtc_reg[0] = 0x00; // rtc_reg[1] = 0x05; // Counter Ϊ0x0500£¬¼´1280¼ÆÊý£¬ÅäºÏ64HzµÄƵÂÊ£¬²úÉú20SµÄ¼ÆÊ±ÄÖÖÓ // rtc_reg[2] = 0x19; //¿ªÆôTime interrupt£¬FOUT Ϊ1hz(Õâ¸öËæ±ãÅä²»Ó°Ïì)£¬ ¼ÆÊ±µÄƵÂÊΪ64Hz¡£ // rtc_reg[3] = 0x00; // rtc_reg[4] = 0x50; //ζȲ¹³¥ÆµÂÊ2s£¨Ä¬ÈÏ£©£¬Ê¹ÄÜTime interrupt // rtc_reg[0] = 0; // rtc_reg[1] = 0x00; //ǰÁ½¸ö×Ö½Ú´ú±í¼ÆÊýÖµ = 0 // rtc_reg[2] = 0x02; //´ú±í1s¸üÐÂÒ»´Î // rtc_reg[3] = 0x00; // rtc_reg[4] = 0x60; //´ú±íUpdate Interrupt Enable /* Ïê¼û¡¶RX-8025T Application Manual¡·*/ rtc_reg[0] = TIMER_COUNTER_0; //×¢£º¼ÆÊýÆ÷×Üʱ¼äΪTIMER_COUNTER_0 + TIMER_COUNTER_1£» rtc_reg[1] = TIMER_COUNTER_1; rtc_reg[2] = TEST_BIT_FLAG | ALARM_BIT_FLAG | UPDATA_INTER_SELECT | TIMER_EN | FOUT_FRE_SELECT | EXTENSION_TIMER_SELECT; rtc_reg[3] = FLAG_REG; rtc_reg[4] = TEMP_BIT_FLAG | UPDATA_BIT_FLAG| TIMER_BIT_FLAG | ALARM_BIT_EN | RESET_BIT_FLAG; R8025T_Write(0x0B,rtc_reg,5); }