FRDM-KL46Z board sLCD demo code using RTC clock.
Fork of FRDM-KL46Z LCD rtc Demo by
Diff: main.cpp
- Revision:
- 0:4f67859595b2
- Child:
- 1:34f0bfc62803
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Jan 20 21:08:57 2014 +0000 @@ -0,0 +1,158 @@ +#include "mbed.h" +#include "SLCD.h" + +time_t seconds = time(NULL); // needed to start rtc + +SLCD slcd; +Timer scroll; + +InterruptIn setmin (SW1); +InterruptIn sethour (SW3); + +struct tm t; + +int i,j,k,lastscroll,display,minute,hour,colon,dp; +char message[80]; +void scroll_message(); +char buffer[32]; + +void setminIRQ(); +void sethourIRQ(); + + +main() +{ + + slcd.LCD_All_Segments_ON(); + wait(.5); + slcd.LCD_All_Segments_OFF (); + wait(.5); + slcd.printf(" "); + wait(.5); + slcd.COLON_ON(); + wait(.5); + slcd.DP1_ON(); + wait(.5); + slcd.DP2_ON(); + wait(.5); + slcd.DP3_ON(); + wait(.5); + slcd.printf("8888"); + wait(.5); + slcd.COLON_OFF(); + wait(.5); + slcd.DP1_OFF(); + wait(.5); + slcd.DP2_OFF(); + wait(.5); + slcd.DP3_OFF(); + wait(.5); + slcd.DP1_ON(); + wait(.5); + slcd.DP2_ON(); + wait(.5); + slcd.DP3_ON(); + wait(.5); + slcd.LCD_All_Segments_OFF(); + + sprintf(message, " 1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + + scroll.start(); + while (i<44){ + + while (i<44) { + scroll_message(); + } + } + + + setmin.rise(setminIRQ); + sethour.rise(sethourIRQ); + + while(1){ + + time_t seconds = time(NULL); + + if(display>14) { + strftime(buffer, 4, "%H%M", localtime(&seconds));colon=1;dp=0;; + } + else{strftime(buffer, 4, "%M%S", localtime(&seconds));dp=1;colon=0;} + + if(colon){slcd.COLON_ON();slcd.DP2_OFF();} + if(dp){slcd.DP2_ON();slcd.COLON_OFF();} + slcd.printf(buffer); + wait(.25); + if(colon)slcd.COLON_ON(); + if(dp){slcd.DP2_OFF();slcd.COLON_OFF();} + slcd.printf(buffer); + display++; + if (display>19)display=0; + wait(.25); + + } +} + +void scroll_message() +{ + if (scroll.read_ms() > lastscroll + 200) { + scroll.reset(); + if (i > 44) { + i=0; + } + int j, k = i; + for (j = 0; j < 4; j++) { + if (message[k+j]) { + slcd.putc(message[k+j]); + } else { + slcd.putc(' '); + k--; + } + } + i++; + lastscroll=scroll.read_ms(); + } +} + +void setminIRQ(void) +{ + display=15; + time_t seconds = time(NULL); + char buffer[2]; + strftime(buffer, 2,"%H", localtime(&seconds)); + hour = atoi(buffer); + strftime(buffer, 2,"%M", localtime(&seconds)); + minute = atoi(buffer); + minute++; + if(minute>59) minute=0; + t.tm_sec = 0; + t.tm_min = minute; + t.tm_hour = hour; + t.tm_mday = 28; + t.tm_mon = 1; + t.tm_year = 114; + set_time (mktime(&t)); + +} + +void sethourIRQ(void) +{ + display=15; + time_t seconds = time(NULL); + char buffer[2]; + strftime(buffer, 2,"%M", localtime(&seconds)); + minute = atoi(buffer); + strftime(buffer, 2,"%H", localtime(&seconds)); + hour = atoi(buffer); + hour++; + if(hour>23) hour=0; + t.tm_sec = 0; + t.tm_min = minute; + t.tm_hour = hour; + t.tm_mday = 28; + t.tm_mon = 1; + t.tm_year = 114; + set_time (mktime(&t)); + +} + +