15 bf[ 0 ] =
dec2bcd( now_tmp->tm_sec );
17 bf[ 2 ] =
dec2bcd( now_tmp->tm_min );
19 bf[ 4 ] =
dec2bcd( now_tmp->tm_hour );
21 bf[ 7 ] =
dec2bcd( now_tmp->tm_mday );
22 bf[ 8 ] =
dec2bcd( now_tmp->tm_mon + 1 );
23 bf[ 9 ] =
dec2bcd( now_tmp->tm_year - 100 );
25 now_time = mktime( now_tmp );
26 cnv_tmp = localtime( &now_time );
27 bf[ 6 ] =
dec2bcd( cnv_tmp->tm_wday );
29 reg_w( Seconds, bf,
sizeof( bf ) );
34 return reg_r( Status_Register ) & 0x40;
35 bit_op8( Status_Register, ~0x40, 0x40 );
41 bit_op8( Control_Register, ~0x08, 0x08 );
46 reg_w( alarm_offsets[ SECOND ], 0xFF );
47 reg_w( alarm_offsets[ MINUTE ], 0xFF );
48 reg_w( alarm_offsets[ HOUR ], 0xFF );
53 bit_op8( Control_Register, ~0x08, 0x00 );
58 uint8_t status =
reg_r( Status_Register );
60 reg_w( Status_Register, ~(status & 0xF0) );
69 reg_r( Seconds, bf,
sizeof( bf ) );
71 now_tm.tm_sec =
bcd2dec( bf[ 0 ] );
72 now_tm.tm_min =
bcd2dec( bf[ 2 ] );
73 now_tm.tm_hour =
bcd2dec( bf[ 4 ] );
74 now_tm.tm_mday =
bcd2dec( bf[ 7 ] );
75 now_tm.tm_mon =
bcd2dec( bf[ 8 ] ) - 1;
76 now_tm.tm_year =
bcd2dec( bf[ 9 ] ) + 100;
79 return mktime( &now_tm );
82int PCF85053A::alarm_offsets[ 3 ] = { 1, 3, 5 };
void reg_w(uint8_t reg_adr, uint8_t *data, int size)
void bit_op8(uint8_t reg, uint8_t mask, uint8_t value)
bool oscillator_stop(void)
void reg_r(uint8_t reg_adr, uint8_t *data, int size)
PCF85053A(uint8_t i2c_address=(0xDE > > 1))
void alarm(alarm_setting digit, int val)
void set(struct tm *now_tm)
static uint8_t dec2bcd(uint8_t v)
static uint8_t bcd2dec(uint8_t v)