37 lines
No EOL
982 B
C
37 lines
No EOL
982 B
C
#include "rtc.h"
|
|
|
|
void plantage_i2C(void) {
|
|
while(1);
|
|
}
|
|
|
|
void (*IT_I2C_Err) (void) = plantage_i2C;
|
|
|
|
void MyRTC_Init()
|
|
{
|
|
MyI2C_Init(I2C1, 15, IT_I2C_Err);
|
|
}
|
|
|
|
void MyRTC_GetTime(int* sec, int* min, int* hour, int* day, int* date, int* month, int* year)
|
|
{
|
|
MyI2C_RecSendData_Typedef data;
|
|
char regCopy = 0;
|
|
|
|
data.SlaveAdress7bits = 0x68;
|
|
data.Ptr_Data = ®Copy;
|
|
data.Nb_Data = 1;
|
|
|
|
MyI2C_GetString(I2C1, 0x00, &data);
|
|
*sec = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
|
|
MyI2C_GetString(I2C1, 0x01, &data);
|
|
*min = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
|
|
MyI2C_GetString(I2C1, 0x02, &data);
|
|
*hour = 0;
|
|
MyI2C_GetString(I2C1, 0x03, &data);
|
|
*day = (regCopy & 0x07);
|
|
MyI2C_GetString(I2C1, 0x04, &data);
|
|
*date = ((regCopy >> 4) & 0x03) * 10 + (regCopy & 0x0F);
|
|
MyI2C_GetString(I2C1, 0x05, &data);
|
|
*month = ((regCopy >> 4) & 0x01) * 10 + (regCopy & 0x0F);
|
|
MyI2C_GetString(I2C1, 0x06, &data);
|
|
*year = ((regCopy >> 4) & 0xF0) * 10 + (regCopy & 0x0F) + 2000;
|
|
} |