FRDM-KL46Z board sLCD demo code using RTC clock.
Fork of FRDM-KL46Z LCD rtc Demo by
main.cpp@0:4f67859595b2, 2014-01-20 (annotated)
- Committer:
- star297
- Date:
- Mon Jan 20 21:08:57 2014 +0000
- Revision:
- 0:4f67859595b2
- Child:
- 1:34f0bfc62803
added functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
star297 | 0:4f67859595b2 | 1 | #include "mbed.h" |
star297 | 0:4f67859595b2 | 2 | #include "SLCD.h" |
star297 | 0:4f67859595b2 | 3 | |
star297 | 0:4f67859595b2 | 4 | time_t seconds = time(NULL); // needed to start rtc |
star297 | 0:4f67859595b2 | 5 | |
star297 | 0:4f67859595b2 | 6 | SLCD slcd; |
star297 | 0:4f67859595b2 | 7 | Timer scroll; |
star297 | 0:4f67859595b2 | 8 | |
star297 | 0:4f67859595b2 | 9 | InterruptIn setmin (SW1); |
star297 | 0:4f67859595b2 | 10 | InterruptIn sethour (SW3); |
star297 | 0:4f67859595b2 | 11 | |
star297 | 0:4f67859595b2 | 12 | struct tm t; |
star297 | 0:4f67859595b2 | 13 | |
star297 | 0:4f67859595b2 | 14 | int i,j,k,lastscroll,display,minute,hour,colon,dp; |
star297 | 0:4f67859595b2 | 15 | char message[80]; |
star297 | 0:4f67859595b2 | 16 | void scroll_message(); |
star297 | 0:4f67859595b2 | 17 | char buffer[32]; |
star297 | 0:4f67859595b2 | 18 | |
star297 | 0:4f67859595b2 | 19 | void setminIRQ(); |
star297 | 0:4f67859595b2 | 20 | void sethourIRQ(); |
star297 | 0:4f67859595b2 | 21 | |
star297 | 0:4f67859595b2 | 22 | |
star297 | 0:4f67859595b2 | 23 | main() |
star297 | 0:4f67859595b2 | 24 | { |
star297 | 0:4f67859595b2 | 25 | |
star297 | 0:4f67859595b2 | 26 | slcd.LCD_All_Segments_ON(); |
star297 | 0:4f67859595b2 | 27 | wait(.5); |
star297 | 0:4f67859595b2 | 28 | slcd.LCD_All_Segments_OFF (); |
star297 | 0:4f67859595b2 | 29 | wait(.5); |
star297 | 0:4f67859595b2 | 30 | slcd.printf(" "); |
star297 | 0:4f67859595b2 | 31 | wait(.5); |
star297 | 0:4f67859595b2 | 32 | slcd.COLON_ON(); |
star297 | 0:4f67859595b2 | 33 | wait(.5); |
star297 | 0:4f67859595b2 | 34 | slcd.DP1_ON(); |
star297 | 0:4f67859595b2 | 35 | wait(.5); |
star297 | 0:4f67859595b2 | 36 | slcd.DP2_ON(); |
star297 | 0:4f67859595b2 | 37 | wait(.5); |
star297 | 0:4f67859595b2 | 38 | slcd.DP3_ON(); |
star297 | 0:4f67859595b2 | 39 | wait(.5); |
star297 | 0:4f67859595b2 | 40 | slcd.printf("8888"); |
star297 | 0:4f67859595b2 | 41 | wait(.5); |
star297 | 0:4f67859595b2 | 42 | slcd.COLON_OFF(); |
star297 | 0:4f67859595b2 | 43 | wait(.5); |
star297 | 0:4f67859595b2 | 44 | slcd.DP1_OFF(); |
star297 | 0:4f67859595b2 | 45 | wait(.5); |
star297 | 0:4f67859595b2 | 46 | slcd.DP2_OFF(); |
star297 | 0:4f67859595b2 | 47 | wait(.5); |
star297 | 0:4f67859595b2 | 48 | slcd.DP3_OFF(); |
star297 | 0:4f67859595b2 | 49 | wait(.5); |
star297 | 0:4f67859595b2 | 50 | slcd.DP1_ON(); |
star297 | 0:4f67859595b2 | 51 | wait(.5); |
star297 | 0:4f67859595b2 | 52 | slcd.DP2_ON(); |
star297 | 0:4f67859595b2 | 53 | wait(.5); |
star297 | 0:4f67859595b2 | 54 | slcd.DP3_ON(); |
star297 | 0:4f67859595b2 | 55 | wait(.5); |
star297 | 0:4f67859595b2 | 56 | slcd.LCD_All_Segments_OFF(); |
star297 | 0:4f67859595b2 | 57 | |
star297 | 0:4f67859595b2 | 58 | sprintf(message, " 1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZ"); |
star297 | 0:4f67859595b2 | 59 | |
star297 | 0:4f67859595b2 | 60 | scroll.start(); |
star297 | 0:4f67859595b2 | 61 | while (i<44){ |
star297 | 0:4f67859595b2 | 62 | |
star297 | 0:4f67859595b2 | 63 | while (i<44) { |
star297 | 0:4f67859595b2 | 64 | scroll_message(); |
star297 | 0:4f67859595b2 | 65 | } |
star297 | 0:4f67859595b2 | 66 | } |
star297 | 0:4f67859595b2 | 67 | |
star297 | 0:4f67859595b2 | 68 | |
star297 | 0:4f67859595b2 | 69 | setmin.rise(setminIRQ); |
star297 | 0:4f67859595b2 | 70 | sethour.rise(sethourIRQ); |
star297 | 0:4f67859595b2 | 71 | |
star297 | 0:4f67859595b2 | 72 | while(1){ |
star297 | 0:4f67859595b2 | 73 | |
star297 | 0:4f67859595b2 | 74 | time_t seconds = time(NULL); |
star297 | 0:4f67859595b2 | 75 | |
star297 | 0:4f67859595b2 | 76 | if(display>14) { |
star297 | 0:4f67859595b2 | 77 | strftime(buffer, 4, "%H%M", localtime(&seconds));colon=1;dp=0;; |
star297 | 0:4f67859595b2 | 78 | } |
star297 | 0:4f67859595b2 | 79 | else{strftime(buffer, 4, "%M%S", localtime(&seconds));dp=1;colon=0;} |
star297 | 0:4f67859595b2 | 80 | |
star297 | 0:4f67859595b2 | 81 | if(colon){slcd.COLON_ON();slcd.DP2_OFF();} |
star297 | 0:4f67859595b2 | 82 | if(dp){slcd.DP2_ON();slcd.COLON_OFF();} |
star297 | 0:4f67859595b2 | 83 | slcd.printf(buffer); |
star297 | 0:4f67859595b2 | 84 | wait(.25); |
star297 | 0:4f67859595b2 | 85 | if(colon)slcd.COLON_ON(); |
star297 | 0:4f67859595b2 | 86 | if(dp){slcd.DP2_OFF();slcd.COLON_OFF();} |
star297 | 0:4f67859595b2 | 87 | slcd.printf(buffer); |
star297 | 0:4f67859595b2 | 88 | display++; |
star297 | 0:4f67859595b2 | 89 | if (display>19)display=0; |
star297 | 0:4f67859595b2 | 90 | wait(.25); |
star297 | 0:4f67859595b2 | 91 | |
star297 | 0:4f67859595b2 | 92 | } |
star297 | 0:4f67859595b2 | 93 | } |
star297 | 0:4f67859595b2 | 94 | |
star297 | 0:4f67859595b2 | 95 | void scroll_message() |
star297 | 0:4f67859595b2 | 96 | { |
star297 | 0:4f67859595b2 | 97 | if (scroll.read_ms() > lastscroll + 200) { |
star297 | 0:4f67859595b2 | 98 | scroll.reset(); |
star297 | 0:4f67859595b2 | 99 | if (i > 44) { |
star297 | 0:4f67859595b2 | 100 | i=0; |
star297 | 0:4f67859595b2 | 101 | } |
star297 | 0:4f67859595b2 | 102 | int j, k = i; |
star297 | 0:4f67859595b2 | 103 | for (j = 0; j < 4; j++) { |
star297 | 0:4f67859595b2 | 104 | if (message[k+j]) { |
star297 | 0:4f67859595b2 | 105 | slcd.putc(message[k+j]); |
star297 | 0:4f67859595b2 | 106 | } else { |
star297 | 0:4f67859595b2 | 107 | slcd.putc(' '); |
star297 | 0:4f67859595b2 | 108 | k--; |
star297 | 0:4f67859595b2 | 109 | } |
star297 | 0:4f67859595b2 | 110 | } |
star297 | 0:4f67859595b2 | 111 | i++; |
star297 | 0:4f67859595b2 | 112 | lastscroll=scroll.read_ms(); |
star297 | 0:4f67859595b2 | 113 | } |
star297 | 0:4f67859595b2 | 114 | } |
star297 | 0:4f67859595b2 | 115 | |
star297 | 0:4f67859595b2 | 116 | void setminIRQ(void) |
star297 | 0:4f67859595b2 | 117 | { |
star297 | 0:4f67859595b2 | 118 | display=15; |
star297 | 0:4f67859595b2 | 119 | time_t seconds = time(NULL); |
star297 | 0:4f67859595b2 | 120 | char buffer[2]; |
star297 | 0:4f67859595b2 | 121 | strftime(buffer, 2,"%H", localtime(&seconds)); |
star297 | 0:4f67859595b2 | 122 | hour = atoi(buffer); |
star297 | 0:4f67859595b2 | 123 | strftime(buffer, 2,"%M", localtime(&seconds)); |
star297 | 0:4f67859595b2 | 124 | minute = atoi(buffer); |
star297 | 0:4f67859595b2 | 125 | minute++; |
star297 | 0:4f67859595b2 | 126 | if(minute>59) minute=0; |
star297 | 0:4f67859595b2 | 127 | t.tm_sec = 0; |
star297 | 0:4f67859595b2 | 128 | t.tm_min = minute; |
star297 | 0:4f67859595b2 | 129 | t.tm_hour = hour; |
star297 | 0:4f67859595b2 | 130 | t.tm_mday = 28; |
star297 | 0:4f67859595b2 | 131 | t.tm_mon = 1; |
star297 | 0:4f67859595b2 | 132 | t.tm_year = 114; |
star297 | 0:4f67859595b2 | 133 | set_time (mktime(&t)); |
star297 | 0:4f67859595b2 | 134 | |
star297 | 0:4f67859595b2 | 135 | } |
star297 | 0:4f67859595b2 | 136 | |
star297 | 0:4f67859595b2 | 137 | void sethourIRQ(void) |
star297 | 0:4f67859595b2 | 138 | { |
star297 | 0:4f67859595b2 | 139 | display=15; |
star297 | 0:4f67859595b2 | 140 | time_t seconds = time(NULL); |
star297 | 0:4f67859595b2 | 141 | char buffer[2]; |
star297 | 0:4f67859595b2 | 142 | strftime(buffer, 2,"%M", localtime(&seconds)); |
star297 | 0:4f67859595b2 | 143 | minute = atoi(buffer); |
star297 | 0:4f67859595b2 | 144 | strftime(buffer, 2,"%H", localtime(&seconds)); |
star297 | 0:4f67859595b2 | 145 | hour = atoi(buffer); |
star297 | 0:4f67859595b2 | 146 | hour++; |
star297 | 0:4f67859595b2 | 147 | if(hour>23) hour=0; |
star297 | 0:4f67859595b2 | 148 | t.tm_sec = 0; |
star297 | 0:4f67859595b2 | 149 | t.tm_min = minute; |
star297 | 0:4f67859595b2 | 150 | t.tm_hour = hour; |
star297 | 0:4f67859595b2 | 151 | t.tm_mday = 28; |
star297 | 0:4f67859595b2 | 152 | t.tm_mon = 1; |
star297 | 0:4f67859595b2 | 153 | t.tm_year = 114; |
star297 | 0:4f67859595b2 | 154 | set_time (mktime(&t)); |
star297 | 0:4f67859595b2 | 155 | |
star297 | 0:4f67859595b2 | 156 | } |
star297 | 0:4f67859595b2 | 157 | |
star297 | 0:4f67859595b2 | 158 |