add example code using TM1637
This commit is contained in:
parent
8094ed6293
commit
25af0ba6eb
27
main.c
27
main.c
|
@ -42,6 +42,7 @@
|
|||
#include "global.h" // board definitions
|
||||
#include "usart.h" // USART utilities
|
||||
#include "usb_cdcacm.h" // USB CDC ACM utilities
|
||||
#include "led_tm1637.h" // TM1637 7-segment controller utilities
|
||||
|
||||
#define WATCHDOG_PERIOD 10000 /**< watchdog period in ms */
|
||||
|
||||
|
@ -183,12 +184,35 @@ void main(void)
|
|||
uint32_t ticks_time = rtc_get_counter_val(); // get time from internal RTC (since first start/power up)
|
||||
printf("uptime: %lu.%02lu:%02lu:%02lu\n", ticks_time/(60*60*24), (ticks_time/(60*60))%24, (ticks_time%(60*60))/60, (ticks_time%60)); // display uptime
|
||||
|
||||
// setup TM1637
|
||||
printf("setup 7-segment display: ");
|
||||
led_tm1637_setup();
|
||||
if (!led_tm1637_time(88,88)) { // test display
|
||||
fprintf(stderr,"could not send time to TM1637\n");
|
||||
}
|
||||
if (!led_tm1637_on()) { // switch on display
|
||||
fprintf(stderr,"could not switch on TM1637\n");
|
||||
}
|
||||
for (uint32_t i=0; i<5000000; i++) { // wait a bit to have the user check the display
|
||||
__asm__("nop");
|
||||
}
|
||||
if (!led_tm1637_text(" ")) { // clear display
|
||||
fprintf(stderr,"could not clear\n");
|
||||
}
|
||||
if (!led_tm1637_off()) { // switch off display
|
||||
fprintf(stderr,"could not switch off TM1637\n");
|
||||
}
|
||||
printf("OK\n");
|
||||
|
||||
// main loop
|
||||
printf("command input: ready\n");
|
||||
bool action = false; // if an action has been performed don't go to sleep
|
||||
button_flag = false; // reset button flag
|
||||
char c = '\0'; // to store received character
|
||||
bool char_flag = false; // a new character has been received
|
||||
if (!led_tm1637_on()) { // switch on display
|
||||
fprintf(stderr,"could not switch on TM1637\n");
|
||||
}
|
||||
while (true) { // infinite loop
|
||||
iwdg_reset(); // kick the dog
|
||||
while (usart_received) { // data received over UART
|
||||
|
@ -237,6 +261,9 @@ void main(void)
|
|||
if ((ticks_time%(60))==0) { // one minute passed
|
||||
printf("uptime: %lu.%02lu:%02lu:%02lu\n", ticks_time/(60*60*24), (ticks_time/(60*60))%24, (ticks_time%(60*60))/60, (ticks_time%60)); // display uptime
|
||||
}
|
||||
if (!led_tm1637_time((ticks_time%(60*60))/60, ticks_time%60)) {
|
||||
fprintf(stderr,"could not set time on TM1637\n");
|
||||
}
|
||||
}
|
||||
if (action) { // go to sleep if nothing had to be done, else recheck for activity
|
||||
action = false;
|
||||
|
|
Loading…
Reference in New Issue