![](/media/cache/profiles/f0fcf351df4eb6786e9bb6fc4e2dee02.jpg.50x50_q85.jpg)
check program for EPSON RX-8025NB and STM M41T62 external RTC library
main.cpp@0:564965644ed2, 2020-08-07 (annotated)
- Committer:
- kenjiArai
- Date:
- Fri Aug 07 05:43:59 2020 +0000
- Revision:
- 0:564965644ed2
- Child:
- 1:0fd657a82160
check program for EPSON RX-8025NB and STM M41T62 external RTC library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:564965644ed2 | 1 | /* |
kenjiArai | 0:564965644ed2 | 2 | * mbed Application program |
kenjiArai | 0:564965644ed2 | 3 | * External RTC test program |
kenjiArai | 0:564965644ed2 | 4 | * |
kenjiArai | 0:564965644ed2 | 5 | * Copyright (c) 2020 Kenji Arai / JH1PJL |
kenjiArai | 0:564965644ed2 | 6 | * http://www7b.biglobe.ne.jp/~kenjia/ |
kenjiArai | 0:564965644ed2 | 7 | * https://os.mbed.com/users/kenjiArai/ |
kenjiArai | 0:564965644ed2 | 8 | * Created: August 7th, 2020 |
kenjiArai | 0:564965644ed2 | 9 | * Revised: August 7th, 2020 |
kenjiArai | 0:564965644ed2 | 10 | */ |
kenjiArai | 0:564965644ed2 | 11 | |
kenjiArai | 0:564965644ed2 | 12 | // tested on Nucleo-L476RG board |
kenjiArai | 0:564965644ed2 | 13 | |
kenjiArai | 0:564965644ed2 | 14 | // Select target RTC ---------------------------------------------------------- |
kenjiArai | 0:564965644ed2 | 15 | //#define CHECK_RX8025 |
kenjiArai | 0:564965644ed2 | 16 | #define CHECK_M41T62 |
kenjiArai | 0:564965644ed2 | 17 | |
kenjiArai | 0:564965644ed2 | 18 | // Include -------------------------------------------------------------------- |
kenjiArai | 0:564965644ed2 | 19 | #include "mbed.h" |
kenjiArai | 0:564965644ed2 | 20 | #include "redirect_stdio.h" |
kenjiArai | 0:564965644ed2 | 21 | #if defined(CHECK_RX8025) |
kenjiArai | 0:564965644ed2 | 22 | # include "RX8025NB.h" |
kenjiArai | 0:564965644ed2 | 23 | # define RTC_NO 0 |
kenjiArai | 0:564965644ed2 | 24 | #elif defined(CHECK_M41T62) |
kenjiArai | 0:564965644ed2 | 25 | # include "m41t62_rtc.h" |
kenjiArai | 0:564965644ed2 | 26 | # define RTC_NO 1 |
kenjiArai | 0:564965644ed2 | 27 | #endif |
kenjiArai | 0:564965644ed2 | 28 | |
kenjiArai | 0:564965644ed2 | 29 | |
kenjiArai | 0:564965644ed2 | 30 | // Definition ----------------------------------------------------------------- |
kenjiArai | 0:564965644ed2 | 31 | #define PUSHED_SW 0 // Active low |
kenjiArai | 0:564965644ed2 | 32 | |
kenjiArai | 0:564965644ed2 | 33 | #define SLEEP_TIME 2 // 2 minuts(minimum setting) |
kenjiArai | 0:564965644ed2 | 34 | |
kenjiArai | 0:564965644ed2 | 35 | // Object --------------------------------------------------------------------- |
kenjiArai | 0:564965644ed2 | 36 | DigitalIn userSW(USER_BUTTON); |
kenjiArai | 0:564965644ed2 | 37 | DigitalOut myled(LED1); // Indicate the sampling period |
kenjiArai | 0:564965644ed2 | 38 | I2C i2c(D14, D15); |
kenjiArai | 0:564965644ed2 | 39 | #if defined(CHECK_RX8025) |
kenjiArai | 0:564965644ed2 | 40 | RX8025 ex_rtc(i2c); // EPSON RX-8025NB |
kenjiArai | 0:564965644ed2 | 41 | DigitalIn rtc_irq(A5, PullUp); // will change to InterruptIn |
kenjiArai | 0:564965644ed2 | 42 | #elif defined(CHECK_M41T62) |
kenjiArai | 0:564965644ed2 | 43 | M41T62 ex_rtc(i2c); // STMicro M41T62 |
kenjiArai | 0:564965644ed2 | 44 | DigitalIn rtc_irq(A4, PullUp); // will change to InterruptIn |
kenjiArai | 0:564965644ed2 | 45 | #endif |
kenjiArai | 0:564965644ed2 | 46 | |
kenjiArai | 0:564965644ed2 | 47 | // RAM ------------------------------------------------------------------------ |
kenjiArai | 0:564965644ed2 | 48 | |
kenjiArai | 0:564965644ed2 | 49 | // ROM / Constant data -------------------------------------------------------- |
kenjiArai | 0:564965644ed2 | 50 | const char *const msg0 = "Is a time correct? If no, please hit any key. "; |
kenjiArai | 0:564965644ed2 | 51 | const char *const msg1 = "<Push USER SW then enter the Deep Sleep mode> "; |
kenjiArai | 0:564965644ed2 | 52 | const char *const rtc_name[2] = {"RX-8025NB", "M41T62"}; |
kenjiArai | 0:564965644ed2 | 53 | |
kenjiArai | 0:564965644ed2 | 54 | // Function prototypes -------------------------------------------------------- |
kenjiArai | 0:564965644ed2 | 55 | static void w_check_rtc_time(void); |
kenjiArai | 0:564965644ed2 | 56 | static void time_enter_mode(void); |
kenjiArai | 0:564965644ed2 | 57 | static void chk_and_set_time(char *ptr); |
kenjiArai | 0:564965644ed2 | 58 | static int32_t xatoi(char **str, int32_t *res); |
kenjiArai | 0:564965644ed2 | 59 | static void get_line(char *buff, int32_t len); |
kenjiArai | 0:564965644ed2 | 60 | static void rtc_interrut(void); |
kenjiArai | 0:564965644ed2 | 61 | |
kenjiArai | 0:564965644ed2 | 62 | extern void print_revision(void); |
kenjiArai | 0:564965644ed2 | 63 | |
kenjiArai | 0:564965644ed2 | 64 | //------------------------------------------------------------------------------ |
kenjiArai | 0:564965644ed2 | 65 | // Control Program |
kenjiArai | 0:564965644ed2 | 66 | //------------------------------------------------------------------------------ |
kenjiArai | 0:564965644ed2 | 67 | int main() |
kenjiArai | 0:564965644ed2 | 68 | { |
kenjiArai | 0:564965644ed2 | 69 | char buf[64]; |
kenjiArai | 0:564965644ed2 | 70 | time_t seconds; |
kenjiArai | 0:564965644ed2 | 71 | uint8_t wait_counter = 0; |
kenjiArai | 0:564965644ed2 | 72 | |
kenjiArai | 0:564965644ed2 | 73 | puts("\r\n\r\nTest Nucleo RTC Function."); |
kenjiArai | 0:564965644ed2 | 74 | printf("External RTC is %s\r\n", rtc_name[RTC_NO]); |
kenjiArai | 0:564965644ed2 | 75 | print_revision(); |
kenjiArai | 0:564965644ed2 | 76 | myled = !myled; |
kenjiArai | 0:564965644ed2 | 77 | ThisThread::sleep_for(100ms); |
kenjiArai | 0:564965644ed2 | 78 | myled = !myled; |
kenjiArai | 0:564965644ed2 | 79 | ThisThread::sleep_for(100ms); |
kenjiArai | 0:564965644ed2 | 80 | // RTC related preparation |
kenjiArai | 0:564965644ed2 | 81 | //ex_rtc.set_sq_wave(RTC_SQW_NONE); |
kenjiArai | 0:564965644ed2 | 82 | ex_rtc.clear_IRQ(); |
kenjiArai | 0:564965644ed2 | 83 | w_check_rtc_time(); |
kenjiArai | 0:564965644ed2 | 84 | while(true) { |
kenjiArai | 0:564965644ed2 | 85 | seconds = time(NULL); |
kenjiArai | 0:564965644ed2 | 86 | strftime(buf, 50, " %B %d,'%y, %H:%M:%S\r\n", localtime(&seconds)); |
kenjiArai | 0:564965644ed2 | 87 | printf("[Time] %s", buf); |
kenjiArai | 0:564965644ed2 | 88 | printf("%s", msg0); |
kenjiArai | 0:564965644ed2 | 89 | printf("%s", msg1); |
kenjiArai | 0:564965644ed2 | 90 | puts("\r"); |
kenjiArai | 0:564965644ed2 | 91 | wait_counter = 0; |
kenjiArai | 0:564965644ed2 | 92 | while (seconds == time(NULL)) { |
kenjiArai | 0:564965644ed2 | 93 | if (readable() == 1) { // Enter time from PC console |
kenjiArai | 0:564965644ed2 | 94 | getc(); // dummy read |
kenjiArai | 0:564965644ed2 | 95 | time_enter_mode(); |
kenjiArai | 0:564965644ed2 | 96 | } |
kenjiArai | 0:564965644ed2 | 97 | if (userSW == PUSHED_SW) { // goto sleep and wake up by RTC timer |
kenjiArai | 0:564965644ed2 | 98 | while (userSW == PUSHED_SW) { |
kenjiArai | 0:564965644ed2 | 99 | ThisThread::sleep_for(10ms); |
kenjiArai | 0:564965644ed2 | 100 | } |
kenjiArai | 0:564965644ed2 | 101 | printf("Please wait %d minutes to wake-up(Reset).", SLEEP_TIME); |
kenjiArai | 0:564965644ed2 | 102 | puts(" Entered the deep sleep mode. "); |
kenjiArai | 0:564965644ed2 | 103 | ThisThread::sleep_for(1s); |
kenjiArai | 0:564965644ed2 | 104 | myled = 0; |
kenjiArai | 0:564965644ed2 | 105 | #if defined(CHECK_RX8025) |
kenjiArai | 0:564965644ed2 | 106 | InterruptIn rtc_irq(A5, PullUp); |
kenjiArai | 0:564965644ed2 | 107 | #elif defined(CHECK_M41T62) |
kenjiArai | 0:564965644ed2 | 108 | InterruptIn rtc_irq(A4, PullUp); |
kenjiArai | 0:564965644ed2 | 109 | #endif |
kenjiArai | 0:564965644ed2 | 110 | rtc_irq.fall(&rtc_interrut); |
kenjiArai | 0:564965644ed2 | 111 | ex_rtc.set_next_IRQ(SLEEP_TIME); |
kenjiArai | 0:564965644ed2 | 112 | ThisThread::sleep_for(1s); |
kenjiArai | 0:564965644ed2 | 113 | DigitalIn dmy0(LED1); |
kenjiArai | 0:564965644ed2 | 114 | DigitalIn dmy1(USBTX); |
kenjiArai | 0:564965644ed2 | 115 | DigitalIn dmy2(USBRX); |
kenjiArai | 0:564965644ed2 | 116 | ThisThread::sleep_for(10000s); // sleep long time |
kenjiArai | 0:564965644ed2 | 117 | } |
kenjiArai | 0:564965644ed2 | 118 | ThisThread::sleep_for(50ms); |
kenjiArai | 0:564965644ed2 | 119 | if (++wait_counter > (2000 / 50)) { |
kenjiArai | 0:564965644ed2 | 120 | break; |
kenjiArai | 0:564965644ed2 | 121 | } |
kenjiArai | 0:564965644ed2 | 122 | } |
kenjiArai | 0:564965644ed2 | 123 | // delete previous strings |
kenjiArai | 0:564965644ed2 | 124 | printf("\033[2A"); |
kenjiArai | 0:564965644ed2 | 125 | puts(""); // null |
kenjiArai | 0:564965644ed2 | 126 | uint8_t n = strlen(msg0) + strlen(msg1); |
kenjiArai | 0:564965644ed2 | 127 | memset(buf, ' ', 64); |
kenjiArai | 0:564965644ed2 | 128 | if (n > 64) { |
kenjiArai | 0:564965644ed2 | 129 | n -= 64; |
kenjiArai | 0:564965644ed2 | 130 | puts_wo_cr(buf, 64); |
kenjiArai | 0:564965644ed2 | 131 | } |
kenjiArai | 0:564965644ed2 | 132 | if (n > 64) { |
kenjiArai | 0:564965644ed2 | 133 | puts_wo_cr(buf, 64); |
kenjiArai | 0:564965644ed2 | 134 | } else { |
kenjiArai | 0:564965644ed2 | 135 | puts_wo_cr(buf, n); |
kenjiArai | 0:564965644ed2 | 136 | } |
kenjiArai | 0:564965644ed2 | 137 | printf("\033[G"); |
kenjiArai | 0:564965644ed2 | 138 | myled = !myled; |
kenjiArai | 0:564965644ed2 | 139 | } |
kenjiArai | 0:564965644ed2 | 140 | } |
kenjiArai | 0:564965644ed2 | 141 | |
kenjiArai | 0:564965644ed2 | 142 | // Check External RTC data |
kenjiArai | 0:564965644ed2 | 143 | static void w_check_rtc_time(void) |
kenjiArai | 0:564965644ed2 | 144 | { |
kenjiArai | 0:564965644ed2 | 145 | time_t seconds_1st, seconds_2nd, diff; |
kenjiArai | 0:564965644ed2 | 146 | struct tm t; |
kenjiArai | 0:564965644ed2 | 147 | |
kenjiArai | 0:564965644ed2 | 148 | for (uint32_t i = 0; i < 5; i++) { |
kenjiArai | 0:564965644ed2 | 149 | ex_rtc.read_rtc_std(&t); // read External RTC data |
kenjiArai | 0:564965644ed2 | 150 | printf("Year:%d ",t.tm_year); |
kenjiArai | 0:564965644ed2 | 151 | printf("Month:%d ",t.tm_mon); |
kenjiArai | 0:564965644ed2 | 152 | printf("Day:%d ",t.tm_mday); |
kenjiArai | 0:564965644ed2 | 153 | printf("Hour:%d ",t.tm_hour); |
kenjiArai | 0:564965644ed2 | 154 | printf("Min:%d ",t.tm_min); |
kenjiArai | 0:564965644ed2 | 155 | printf("Sec: %d \r\n",t.tm_sec); |
kenjiArai | 0:564965644ed2 | 156 | seconds_1st = mktime(&t); |
kenjiArai | 0:564965644ed2 | 157 | ex_rtc.read_rtc_std(&t); // read External RTC data again (make sure) |
kenjiArai | 0:564965644ed2 | 158 | seconds_2nd = mktime(&t); |
kenjiArai | 0:564965644ed2 | 159 | diff = seconds_2nd - seconds_1st; |
kenjiArai | 0:564965644ed2 | 160 | if ((diff == 0) || (diff == 1)) { |
kenjiArai | 0:564965644ed2 | 161 | break; |
kenjiArai | 0:564965644ed2 | 162 | } |
kenjiArai | 0:564965644ed2 | 163 | } |
kenjiArai | 0:564965644ed2 | 164 | set_time(seconds_2nd); |
kenjiArai | 0:564965644ed2 | 165 | } |
kenjiArai | 0:564965644ed2 | 166 | |
kenjiArai | 0:564965644ed2 | 167 | // Interrupt for wake up |
kenjiArai | 0:564965644ed2 | 168 | static void rtc_interrut(void) |
kenjiArai | 0:564965644ed2 | 169 | { |
kenjiArai | 0:564965644ed2 | 170 | system_reset(); // restart from RESET condition |
kenjiArai | 0:564965644ed2 | 171 | } |
kenjiArai | 0:564965644ed2 | 172 | |
kenjiArai | 0:564965644ed2 | 173 | // Time adjustment |
kenjiArai | 0:564965644ed2 | 174 | static void time_enter_mode(void) |
kenjiArai | 0:564965644ed2 | 175 | { |
kenjiArai | 0:564965644ed2 | 176 | char *ptr; |
kenjiArai | 0:564965644ed2 | 177 | char linebuf[64]; |
kenjiArai | 0:564965644ed2 | 178 | |
kenjiArai | 0:564965644ed2 | 179 | puts("Set time into RTC."); |
kenjiArai | 0:564965644ed2 | 180 | puts(" e.g. >20 8 1 12 34 56 -> August 01,'20, 12:34:56"); |
kenjiArai | 0:564965644ed2 | 181 | puts(" If time is fine, just hit enter key."); |
kenjiArai | 0:564965644ed2 | 182 | putc('>'); |
kenjiArai | 0:564965644ed2 | 183 | ptr = linebuf; |
kenjiArai | 0:564965644ed2 | 184 | get_line(ptr, sizeof(linebuf)); |
kenjiArai | 0:564965644ed2 | 185 | puts("\r"); |
kenjiArai | 0:564965644ed2 | 186 | chk_and_set_time(ptr); |
kenjiArai | 0:564965644ed2 | 187 | } |
kenjiArai | 0:564965644ed2 | 188 | |
kenjiArai | 0:564965644ed2 | 189 | // Change string -> integer |
kenjiArai | 0:564965644ed2 | 190 | static int32_t xatoi(char **str, int32_t *res) |
kenjiArai | 0:564965644ed2 | 191 | { |
kenjiArai | 0:564965644ed2 | 192 | uint32_t val; |
kenjiArai | 0:564965644ed2 | 193 | uint8_t c, radix, s = 0; |
kenjiArai | 0:564965644ed2 | 194 | |
kenjiArai | 0:564965644ed2 | 195 | while ((c = **str) == ' ') (*str)++; |
kenjiArai | 0:564965644ed2 | 196 | if (c == '-') { |
kenjiArai | 0:564965644ed2 | 197 | s = 1; |
kenjiArai | 0:564965644ed2 | 198 | c = *(++(*str)); |
kenjiArai | 0:564965644ed2 | 199 | } |
kenjiArai | 0:564965644ed2 | 200 | if (c == '0') { |
kenjiArai | 0:564965644ed2 | 201 | c = *(++(*str)); |
kenjiArai | 0:564965644ed2 | 202 | if (c <= ' ') { |
kenjiArai | 0:564965644ed2 | 203 | *res = 0; |
kenjiArai | 0:564965644ed2 | 204 | return 1; |
kenjiArai | 0:564965644ed2 | 205 | } |
kenjiArai | 0:564965644ed2 | 206 | if (c == 'x') { |
kenjiArai | 0:564965644ed2 | 207 | radix = 16; |
kenjiArai | 0:564965644ed2 | 208 | c = *(++(*str)); |
kenjiArai | 0:564965644ed2 | 209 | } else { |
kenjiArai | 0:564965644ed2 | 210 | if (c == 'b') { |
kenjiArai | 0:564965644ed2 | 211 | radix = 2; |
kenjiArai | 0:564965644ed2 | 212 | c = *(++(*str)); |
kenjiArai | 0:564965644ed2 | 213 | } else { |
kenjiArai | 0:564965644ed2 | 214 | if ((c >= '0')&&(c <= '9')) { |
kenjiArai | 0:564965644ed2 | 215 | radix = 8; |
kenjiArai | 0:564965644ed2 | 216 | } else { |
kenjiArai | 0:564965644ed2 | 217 | return 0; |
kenjiArai | 0:564965644ed2 | 218 | } |
kenjiArai | 0:564965644ed2 | 219 | } |
kenjiArai | 0:564965644ed2 | 220 | } |
kenjiArai | 0:564965644ed2 | 221 | } else { |
kenjiArai | 0:564965644ed2 | 222 | if ((c < '1')||(c > '9')) { |
kenjiArai | 0:564965644ed2 | 223 | return 0; |
kenjiArai | 0:564965644ed2 | 224 | } |
kenjiArai | 0:564965644ed2 | 225 | radix = 10; |
kenjiArai | 0:564965644ed2 | 226 | } |
kenjiArai | 0:564965644ed2 | 227 | val = 0; |
kenjiArai | 0:564965644ed2 | 228 | while (c > ' ') { |
kenjiArai | 0:564965644ed2 | 229 | if (c >= 'a') c -= 0x20; |
kenjiArai | 0:564965644ed2 | 230 | c -= '0'; |
kenjiArai | 0:564965644ed2 | 231 | if (c >= 17) { |
kenjiArai | 0:564965644ed2 | 232 | c -= 7; |
kenjiArai | 0:564965644ed2 | 233 | if (c <= 9) return 0; |
kenjiArai | 0:564965644ed2 | 234 | } |
kenjiArai | 0:564965644ed2 | 235 | if (c >= radix) return 0; |
kenjiArai | 0:564965644ed2 | 236 | val = val * radix + c; |
kenjiArai | 0:564965644ed2 | 237 | c = *(++(*str)); |
kenjiArai | 0:564965644ed2 | 238 | } |
kenjiArai | 0:564965644ed2 | 239 | if (s) val = -val; |
kenjiArai | 0:564965644ed2 | 240 | *res = val; |
kenjiArai | 0:564965644ed2 | 241 | return 1; |
kenjiArai | 0:564965644ed2 | 242 | } |
kenjiArai | 0:564965644ed2 | 243 | |
kenjiArai | 0:564965644ed2 | 244 | // Get key input data |
kenjiArai | 0:564965644ed2 | 245 | static void get_line(char *buff, int32_t len) |
kenjiArai | 0:564965644ed2 | 246 | { |
kenjiArai | 0:564965644ed2 | 247 | char c; |
kenjiArai | 0:564965644ed2 | 248 | int32_t idx = 0; |
kenjiArai | 0:564965644ed2 | 249 | |
kenjiArai | 0:564965644ed2 | 250 | for (;;) { |
kenjiArai | 0:564965644ed2 | 251 | c = getc(); |
kenjiArai | 0:564965644ed2 | 252 | //printf("0x%x \r\n", c); |
kenjiArai | 0:564965644ed2 | 253 | if ((c == '\r') || (c == '\n')) { |
kenjiArai | 0:564965644ed2 | 254 | buff[idx++] = '\r'; |
kenjiArai | 0:564965644ed2 | 255 | break; |
kenjiArai | 0:564965644ed2 | 256 | } |
kenjiArai | 0:564965644ed2 | 257 | if ((c == '\b') && idx) { |
kenjiArai | 0:564965644ed2 | 258 | idx--; |
kenjiArai | 0:564965644ed2 | 259 | const char bf_bs[] = |
kenjiArai | 0:564965644ed2 | 260 | {0x1b, '[', '1', 'D', ' ', 0x1b, '[', '1', 'D',0}; |
kenjiArai | 0:564965644ed2 | 261 | for(uint32_t i = 0; bf_bs[i] != 0; i++) { |
kenjiArai | 0:564965644ed2 | 262 | putc(bf_bs[i]); |
kenjiArai | 0:564965644ed2 | 263 | } |
kenjiArai | 0:564965644ed2 | 264 | } |
kenjiArai | 0:564965644ed2 | 265 | if (((uint8_t)c >= ' ') && (idx < len - 1)) { |
kenjiArai | 0:564965644ed2 | 266 | buff[idx++] = c; |
kenjiArai | 0:564965644ed2 | 267 | putc(c); |
kenjiArai | 0:564965644ed2 | 268 | } |
kenjiArai | 0:564965644ed2 | 269 | } |
kenjiArai | 0:564965644ed2 | 270 | buff[idx] = 0; |
kenjiArai | 0:564965644ed2 | 271 | putc('\n'); |
kenjiArai | 0:564965644ed2 | 272 | } |
kenjiArai | 0:564965644ed2 | 273 | |
kenjiArai | 0:564965644ed2 | 274 | // Check key input strings and set time |
kenjiArai | 0:564965644ed2 | 275 | static void chk_and_set_time(char *ptr) |
kenjiArai | 0:564965644ed2 | 276 | { |
kenjiArai | 0:564965644ed2 | 277 | int32_t p1; |
kenjiArai | 0:564965644ed2 | 278 | struct tm t; |
kenjiArai | 0:564965644ed2 | 279 | time_t seconds; |
kenjiArai | 0:564965644ed2 | 280 | |
kenjiArai | 0:564965644ed2 | 281 | if (xatoi(&ptr, &p1)) { |
kenjiArai | 0:564965644ed2 | 282 | t.tm_year = (uint8_t)p1 + 100; |
kenjiArai | 0:564965644ed2 | 283 | printf("Year:%d ",p1); |
kenjiArai | 0:564965644ed2 | 284 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:564965644ed2 | 285 | t.tm_mon = (uint8_t)p1 - 1; |
kenjiArai | 0:564965644ed2 | 286 | printf("Month:%d ",p1); |
kenjiArai | 0:564965644ed2 | 287 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:564965644ed2 | 288 | t.tm_mday = (uint8_t)p1; |
kenjiArai | 0:564965644ed2 | 289 | printf("Day:%d ",p1); |
kenjiArai | 0:564965644ed2 | 290 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:564965644ed2 | 291 | t.tm_hour = (uint8_t)p1; |
kenjiArai | 0:564965644ed2 | 292 | printf("Hour:%d ",p1); |
kenjiArai | 0:564965644ed2 | 293 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:564965644ed2 | 294 | t.tm_min = (uint8_t)p1; |
kenjiArai | 0:564965644ed2 | 295 | printf("Min:%d ",p1); |
kenjiArai | 0:564965644ed2 | 296 | xatoi( &ptr, &p1 ); |
kenjiArai | 0:564965644ed2 | 297 | t.tm_sec = (uint8_t)p1; |
kenjiArai | 0:564965644ed2 | 298 | printf("Sec: %d \r\n",p1); |
kenjiArai | 0:564965644ed2 | 299 | seconds = mktime(&t); |
kenjiArai | 0:564965644ed2 | 300 | set_time(seconds); |
kenjiArai | 0:564965644ed2 | 301 | } else { |
kenjiArai | 0:564965644ed2 | 302 | seconds = time(NULL); |
kenjiArai | 0:564965644ed2 | 303 | } |
kenjiArai | 0:564965644ed2 | 304 | seconds = time(NULL); |
kenjiArai | 0:564965644ed2 | 305 | struct tm *time_ajd = localtime(&seconds); |
kenjiArai | 0:564965644ed2 | 306 | ex_rtc.write_rtc_std(time_ajd); |
kenjiArai | 0:564965644ed2 | 307 | // Show Time with several example |
kenjiArai | 0:564965644ed2 | 308 | // ex.1 |
kenjiArai | 0:564965644ed2 | 309 | printf( |
kenjiArai | 0:564965644ed2 | 310 | "Date: %04d/%02d/%02d, %02d:%02d:%02d\r\n", |
kenjiArai | 0:564965644ed2 | 311 | t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec |
kenjiArai | 0:564965644ed2 | 312 | ); |
kenjiArai | 0:564965644ed2 | 313 | char buf[64]; |
kenjiArai | 0:564965644ed2 | 314 | // ex.2 |
kenjiArai | 0:564965644ed2 | 315 | strftime(buf, 40, "%x %X", localtime(&seconds)); |
kenjiArai | 0:564965644ed2 | 316 | printf("Date: %s\r\n", buf); |
kenjiArai | 0:564965644ed2 | 317 | // ex.3 |
kenjiArai | 0:564965644ed2 | 318 | strftime(buf, 40, "%I:%M:%S %p (%Y/%m/%d)", localtime(&seconds)); |
kenjiArai | 0:564965644ed2 | 319 | printf("Date: %s\r\n", buf); |
kenjiArai | 0:564965644ed2 | 320 | // ex.4 |
kenjiArai | 0:564965644ed2 | 321 | strftime(buf, 40, "%B %d,'%y, %H:%M:%S", localtime(&seconds)); |
kenjiArai | 0:564965644ed2 | 322 | printf("Date: %s\r\n", buf); |
kenjiArai | 0:564965644ed2 | 323 | } |