22 bf[ 0 ] =
dec2bcd( now_tmp->tm_sec );
23 bf[ 1 ] =
dec2bcd( now_tmp->tm_min );
24 bf[ 2 ] =
dec2bcd( now_tmp->tm_hour );
25 bf[ 3 ] =
dec2bcd( now_tmp->tm_mday );
26 bf[ 5 ] =
dec2bcd( now_tmp->tm_mon + 1 );
27 bf[ 6 ] =
dec2bcd( now_tmp->tm_year - 100 );
29 now_time = mktime( now_tmp );
30 cnv_tmp = localtime( &now_time );
31 bf[ 4 ] =
dec2bcd( cnv_tmp->tm_wday);
34 _reg_w( Seconds, bf,
sizeof( bf ) );
40 return _reg_r( Seconds ) & 0x80;
45 int v = (val == 0x80) ? 0x80 :
dec2bcd( val );
46 _reg_w( Second_alarm + digit, v );
47 _bit_op8( Control_2, (uint8_t)(~0x80), 0x80 );
57 _bit_op8( Control_2, (uint8_t)(~0x80), 0x00 );
62 uint8_t v =
_reg_r( Control_2 );
63 _reg_w( Control_2, v & ~0x48 );
70 float sf[] = { 1 / 4096.0, 1 / 64.0, 1.0, 60 };
73 period = ((255 * 60.0) < period) ? 255 * 60.0 : period;
75 for ( tcf = 0; tcf < 4; tcf++ ) {
76 if ( period <= sf[ tcf ] * 255 )
80 uint8_t v = (uint8_t)(period / sf[ tcf ]);
83 Serial.print(
" period:");
84 Serial.print( period, 10 );
85 Serial.print(
" tcf:");
89 Serial.print(
" v*tcf:");
90 Serial.print( v * sf[tcf], 10 );
95 _reg_w( Timer_mode, tcf << 3 | 0x06 );
106 _reg_r( Seconds, bf,
sizeof( bf ) );
108 now_tm.tm_sec =
bcd2dec( bf[ 0 ] );
109 now_tm.tm_min =
bcd2dec( bf[ 1 ] );
110 now_tm.tm_hour =
bcd2dec( bf[ 2 ] );
111 now_tm.tm_mday =
bcd2dec( bf[ 3 ] );
112 now_tm.tm_mon =
bcd2dec( bf[ 5 ] ) - 1;
113 now_tm.tm_year =
bcd2dec( bf[ 6 ] ) + 100;
116 return mktime(&now_tm);
120PCF85063A::PCF85063A( uint8_t i2c_address ) : I2C_device( i2c_address )
128void PCF85063A::_reg_w( uint8_t reg, uint8_t *vp,
int len )
130 reg_w( reg, vp, len );
133void PCF85063A::_reg_r( uint8_t reg, uint8_t *vp,
int len )
135 reg_r( reg, vp, len );
138void PCF85063A::_reg_w( uint8_t reg, uint8_t val )
143uint8_t PCF85063A::_reg_r( uint8_t reg )
148void PCF85063A::_bit_op8( uint8_t reg, uint8_t mask, uint8_t val )
150 bit_op8( reg, mask, val );
void set(struct tm *now_tm)
virtual void _bit_op8(uint8_t reg, uint8_t mask, uint8_t val)=0
bool oscillator_stop(void)
void alarm(alarm_setting digit, int val)
float timer(float period)
virtual void _reg_w(uint8_t reg, uint8_t *vp, int len)=0
virtual void _reg_r(uint8_t reg, uint8_t *vp, int len)=0
static uint8_t dec2bcd(uint8_t v)
static uint8_t bcd2dec(uint8_t v)