芯片复制dspic33F系列的单片机驱动
| 芯片复制#include "config.h" 芯片复制#include "p33FJ256MC710.h" /* r8025N寄存器定义 */ #define RX8025_REG_SEC 0x00 #define RX8025_REG_MIN 0x01 #define RX8025_REG_HOUR 0x02 #define RX8025_REG_WDAY 0x03 #define RX8025_REG_MDAY 0x04 #define RX8025_REG_MONTH 0x05 #define RX8025_REG_YEAR 0x06 #define RX8025_REG_RAM 0x07//#define RX8025_REG_DIGOFF 0x07 8025 #define RX8025_REG_ALWMIN 0x08 #define RX8025_REG_ALWHOUR 0x09 #define RX8025_REG_ALWWDAY 0x0a #define RX8025_REG_TMCNT0 0x0b//#define RX8025_REG_ALDMIN 0x0b #define RX8025_REG_TMCNT1 0x0c//#define RX8025_REG_ALDHOUR 0x0c /* 0x0d is reserved */ #define RX8025_REG_FLAG 0x0e//#define RX8025_REG_CTRL1 0x0e #define RX8025_REG_CTRL 0x0f//#define RX8025_REG_CTRL2 0x0f #define RX8025_BIT_FLAG_VDET (1<<0)//用于检测温度补偿的状态 #define RX8025_BIT_FLAG_VLF (1<<1)//用于检测电压低的状态 typedef struct strtime{ BYTE cSecond; BYTE cMinute; BYTE cHour; BYTE cMonth; BYTE cWeek; BYTE cDay; UINT16 sYear; }strTIME; BYTE rx8025_get_time(strTIME *get_time); /* I2C定义 */ INT Time_Adjust(strTIME *dt); BYTE is_leap_year(UINT16 year); UINT16 bcd2bin(BYTE val); BYTE bin2bcd(unsigned val); VOID IdleI2C(VOID); VOID StartI2C(VOID); BYTE WriteI2C(BYTE byte); VOID StopI2C(VOID); VOID RestartI2C(VOID); BYTE getsI2C(BYTE*, BYTE); VOID NotAckI2C(VOID); VOID InitI2C(VOID); UINT16 ACKStatus(VOID); BYTE getI2C(VOID); VOID AckI2C(VOID); UINT16 EEAckPolling(BYTE); UINT16 putstringI2C(BYTE *wrptr,BYTE Write_Data_Length); UINT32 TimeToMinute(strTIME *Time_Set); UINT32 TimeToSecond(strTIME *Time_Set); VOID MinuteToTime(UINT32 Minute,strTIME *T); VOID SecondToTime(UINT32 SecondT,strTIME *T); void TimeDir(strTIME *T); /*********************************************************************** ** Time: liwenjin 2012.10 ** Function:读取rx8025n内部寄存器 ** Input: ** Output: ** Attention ***********************************************************************/ UINT16 rx8025_read_regs(BYTE Add, BYTE ReadDatatLength,BYTE *Data) { BYTE ErrorCode; // Add=Add<<4;//地址(高4位)加传送模式00(低四位) IdleI2C(); //Wait for bus Idle StartI2C(); //Generate Start condition WriteI2C(0x64); //发送写控制命令,0x64 IdleI2C(); //Wait for bus Idle ErrorCode = ACKStatus(); //Return ACK Status WriteI2C(Add); //Send High Address IdleI2C(); //Wait for bus Idle ErrorCode = ACKStatus(); //Return ACK Status RestartI2C(); //Generate Restart WriteI2C(0x65); //发送读控制命令 IdleI2C(); //Wait for bus Idle ErrorCode = ACKStatus(); //Return ACK Status getsI2C(Data,ReadDatatLength); //Read Length number of bytes to Data NotAckI2C(); //send Not Ack StopI2C(); //Send Stop Condition return(ErrorCode); } |

芯片解密