38 return( ( (data/10U) << 4 ) | (data%10U) );
50 return ( ( ( (data&0xf0U) >> 4) * 10 ) + (data&0x0fU) );
67 if ( !I2C_read(
DS1307, 0, 1, &b, 1) )
91 if ( !I2C_read(
DS1307, 0, 1, &b, 1) )
98 return ((b & 0x80) ? 0 : 1);
100 b = ( b & 0x7f) | (run ? 0 : 0x80);
102 if ( !I2C_write(
DS1307, 0, 1, &b, 1) )
129 I2C_init(50000UL, 20000UL);
154 printf(
"rtc _write epoch failed\n");
161 for (addr = 8; addr < 0x3f; addr += 8)
163 if ( !I2C_write(
DS1307, addr, 1, buf, 8) )
196 buf[3] = ((t->
tm_wday & 7) + 1) & 0x0f;
203 printf(
"rtc_write():%d, day:%d,mon:%d,hour:%d,min:%d,sec:%d, wday:%d\n",
216 printf(
"rtc_write buf: ");
218 printf(
"%02x ", 0xff & buf[i]);
222 if ( !I2C_write(
DS1307, 0, 1, buf, 8) )
242 if ( !I2C_read(
DS1307, 0, 1, buf, 8) )
252 printf(
"%02x ", 0xff & buf[i]);
259 t->
tm_wday = ( buf[3] & 0x07) - 1;
265 printf(
"rtc_read():%d, day:%d,mon:%d,hour:%d,min:%d,sec:%d, wday:%d\n",
MEMSPACE DWORD get_fattime(void)
Read time and convert to FAT32 time.
Master include file for project Includes all project includes and defines here.
Common Linux/POSIX time functions.
MEMSPACE uint8_t rtc_read(tm_t *t)
Read DS1307 RTC into POSIX struct tm * structure.
MEMSPACE uint8_t BINtoBCD(uint8_t data)
Convert number >= 0 and <= 99 to BCD.
uint32_t time_t
type of EPOCH result.
MEMSPACE int8_t rtc_run_test()
Check if the DS1307 device is running.
MEMSPACE uint8_t rtc_write(tm_t *t)
Set DS1307 RTC from POSIX struct tm * structure.
MEMSPACE uint8_t rtc_init(int force, time_t seconds)
Initialize DS1307 rtc if not initialied - or if forced.
Math IO functions, and verious conversion code with floating point support.
MEMSPACE tm_t * gmtime(time_t *tp)
Convert epoch GMT time_t *tp into POSIX static tm_t *t.
MEMSPACE uint8_t BCDtoBIN(uint8_t data)
Convert two "digit" BCD number to binary.
MEMSPACE int rtc_run(int run)
Set DS1307 run state.
MEMSPACE int printf(const char *format,...)
MEMSPACE uint32_t tm_to_fat(tm_t *t)
FAT time structer reference.