DCF77 clock using the HY-1.8 LCD display. Sets KL25Z RTC clock and will continue to run with no DCF signal. Import the libraries to work on FRDM-KL25Z board, sends 8 bit writes to the LCD.

Dependencies:   HY-1_8TFT_ST7735 TSI mbed

Fork of KL25Z_DCF77_HY-1_8LCD by Paul Staron

This project shows the KL25Z connected to a very cheap (3 Euros) Chinese TFT LCD Display (HY-1.8 SPI from Ebay). I have modified a ST7753 driver library to work the 8 bit SPI write that the Mbed library sets the FRDM board to (not sure why as the KL25Z MCU has16 bit cababiliy). The libraries are available for import from my home page. and includes five different fonts (three are needed for this example).

I have also used the Analog Out (pin PTE30) to control the LED back light level, simply connect a small NPN transistor in the LED -ve connection to ground and feed the analog out pin to the base of the transistor via a 10k ohm resistor. When you slide your finger across the TSI touch slider the display brightness can be changed from off to full level.

The code it much the same as the other projects I have published, just with different LCD drive code. This program will decode the DCF77 signal connected to pin PTE20 and set the RTC clock. The photo shows the display before I modified the LED backlight drive circuit.

The display runs at 5V and draws arround 20mA, the backlight led will also run at this voltage and is nice and bright. It can also be connected to the USB 3v pin and runs at a lower level. there is a solder jumper to bypass the 5v regulator, leave this open and it will run on both volages, if this jumper is closed it will bypass the regulator and if connected to the 5v supply, the display will be 'bricked' so take care!.

This display is considerably better and cheaper than the Nokia display but not as good as Oled. Easy to connect, 5 data connections and 2 power wires. It also includes a SD card slot that can be connected to the FRDM board.

The backlight is LED it does not use a switch mode DC-DC converter circuit so RF noise is very low, this is essential when using a sensitive VLF DCF77 radio receiver close by.

The FRDM board and display runs at 50mA depending on LED brightness.

/media/uploads/star297/_scaled_20130322_132442.jpg

Committer:
star297
Date:
Tue Mar 26 21:04:14 2013 +0000
Revision:
2:3b26b9fda4f7
Parent:
1:6f4c5876140d
1st revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
star297 1:6f4c5876140d 1 // DCF77 Atomic Clock for HY-1.8 SPI (ST7735) LCD display
smultron1977 0:2353da390056 2
smultron1977 0:2353da390056 3 #include "mbed.h"
smultron1977 0:2353da390056 4 #include "ST7735_TFT.h"
star297 1:6f4c5876140d 5 #include "Arial24x23i.h"
star297 1:6f4c5876140d 6 #include "Arial11x11.h"
star297 1:6f4c5876140d 7 #include "Arial9x9.h"
star297 1:6f4c5876140d 8 #include "TSISensor.h"
star297 1:6f4c5876140d 9
star297 1:6f4c5876140d 10 AnalogOut DisplayLED(PTE30);
star297 1:6f4c5876140d 11 TSISensor tsi;
star297 1:6f4c5876140d 12
star297 1:6f4c5876140d 13 // FRDM-KL25Z
star297 2:3b26b9fda4f7 14 ST7735_TFT lcd(PTD2, NC, PTD1, PTA13, PTD5, PTD0 ,"TFT"); // sda, miso (not connected), sck, cs, AO, reset
star297 1:6f4c5876140d 15 DigitalIn dcfSignalIn(PTE20);//conection of output inverting MSF module
star297 2:3b26b9fda4f7 16 DigitalOut dcfLED(LED_GREEN); // indicates DCF signal on Mbed
star297 1:6f4c5876140d 17
star297 1:6f4c5876140d 18
star297 1:6f4c5876140d 19 // LPC1768
star297 1:6f4c5876140d 20 //ST7735_TFT lcd(p5, p6, p7, p8, p11, p15); //,"TFT"); // mosi, miso, sclk, cs, rs, reset
star297 1:6f4c5876140d 21 //DigitalIn dcfSignalIn(p21);//conection to NON inverting output of dcf module
star297 1:6f4c5876140d 22 //DigitalOut dcfLED (LED1);//received DCF signal
smultron1977 0:2353da390056 23
star297 1:6f4c5876140d 24 //variable
star297 1:6f4c5876140d 25 char paritycheck,paritym,parityu,paritydmy;
star297 1:6f4c5876140d 26 char testu,testm,testdmy;
star297 1:6f4c5876140d 27 char minh,minl;
star297 1:6f4c5876140d 28 char hourh,hourl;
star297 1:6f4c5876140d 29 char w_day;
star297 1:6f4c5876140d 30 char day,dayh,dayl;
star297 1:6f4c5876140d 31 char monthh,monthl;
star297 1:6f4c5876140d 32 char yearh,yearl;
star297 1:6f4c5876140d 33 char summertime;
star297 1:6f4c5876140d 34 int dcf_array[61];
star297 1:6f4c5876140d 35
star297 1:6f4c5876140d 36 //makro,s
star297 1:6f4c5876140d 37 void getbit();
star297 1:6f4c5876140d 38 void dcf_check();
star297 1:6f4c5876140d 39 void lcd_date_print();
star297 1:6f4c5876140d 40 void lcd_time_print();
star297 1:6f4c5876140d 41 void bit_map_draw();
star297 1:6f4c5876140d 42 void bit_print();
star297 1:6f4c5876140d 43 void parity_calc();
star297 1:6f4c5876140d 44 void reset_rtc();
star297 1:6f4c5876140d 45 void local_time();
star297 1:6f4c5876140d 46 void setRTC();
star297 1:6f4c5876140d 47 void s_display();
star297 1:6f4c5876140d 48 void drawgraph();
star297 1:6f4c5876140d 49 void showRTC();
star297 1:6f4c5876140d 50 void loop();
star297 1:6f4c5876140d 51 void oled_time_print();
star297 1:6f4c5876140d 52 void oled_date_print();
star297 1:6f4c5876140d 53 void drawgraph();
star297 1:6f4c5876140d 54 void bit_map_draw();
star297 1:6f4c5876140d 55 void set_time();
star297 1:6f4c5876140d 56 void restart();
star297 1:6f4c5876140d 57 void showRTCdate();
star297 1:6f4c5876140d 58
star297 1:6f4c5876140d 59 Timer d;
star297 1:6f4c5876140d 60 Ticker Ticker10ms;
star297 1:6f4c5876140d 61
star297 1:6f4c5876140d 62 #define ZERO 1e-10
star297 1:6f4c5876140d 63 #define isBetween(A, B, C) (((A-B) > -ZERO) && ((A-C) < ZERO))
smultron1977 0:2353da390056 64
star297 1:6f4c5876140d 65 struct status {
star297 1:6f4c5876140d 66 bool is_leap; // Leap year flag (NOT actually transmitted but calculated)
star297 1:6f4c5876140d 67 bool sample50; // dcf sample at 50mS into the start of the second
star297 1:6f4c5876140d 68 bool sample150; // dcf sample at 150mS into the start of the second
star297 1:6f4c5876140d 69 int second; // dcf second (NOT actually transmitted but calculated)
star297 1:6f4c5876140d 70 }
star297 1:6f4c5876140d 71 dcf_status;
smultron1977 0:2353da390056 72
star297 1:6f4c5876140d 73 struct dcf {
star297 1:6f4c5876140d 74 char dut1; // DUT1 (0.1 - 0.8)
star297 1:6f4c5876140d 75 char dut2; // DUT2 (-0.1 - -0.8)
star297 1:6f4c5876140d 76 char year; // Year (00 - 99)
star297 1:6f4c5876140d 77 char month; // Month (01 - 12)
star297 1:6f4c5876140d 78 char dayofmonth; // Day of month (01 - 31)
star297 1:6f4c5876140d 79 char dayofweek; // Day of week (Sunday=0 Saturday=6)
star297 1:6f4c5876140d 80 char hour; // Hour (00 - 23)
star297 1:6f4c5876140d 81 char minute; // Minute (00 - 59)
star297 1:6f4c5876140d 82 } dcf_time;
smultron1977 0:2353da390056 83
star297 1:6f4c5876140d 84 // Global variables
star297 1:6f4c5876140d 85 int in_sec_counter = 0;
star297 1:6f4c5876140d 86 int interrupt_counter = 0;
star297 1:6f4c5876140d 87 int hour = 12;
star297 1:6f4c5876140d 88 int minute = 0;
star297 1:6f4c5876140d 89 int second = 0;
star297 1:6f4c5876140d 90 int dayofweek = 6;
star297 1:6f4c5876140d 91 int dayofmonth = 1;
star297 1:6f4c5876140d 92 int month = 1;
star297 1:6f4c5876140d 93 int year = 0;
star297 1:6f4c5876140d 94 int nosignal;
star297 1:6f4c5876140d 95 int start;
star297 1:6f4c5876140d 96 int zero_bit;
star297 1:6f4c5876140d 97 int dcf_sec;
star297 1:6f4c5876140d 98 int s,x,y,r;
star297 1:6f4c5876140d 99 int bmd;
star297 1:6f4c5876140d 100 int sync;
star297 1:6f4c5876140d 101 int p_minute,p_hour,p_dayofweek,p_dayofmonth,p_month,p_year;
star297 1:6f4c5876140d 102 int dcf_error;
star297 1:6f4c5876140d 103 int status;
star297 1:6f4c5876140d 104 int insecond_counter;
star297 1:6f4c5876140d 105 int delay;
star297 1:6f4c5876140d 106 int start_delay;
star297 1:6f4c5876140d 107 int RTCsecond;
star297 1:6f4c5876140d 108 int laststatus;
star297 1:6f4c5876140d 109 int lastbit,laststart;
star297 1:6f4c5876140d 110
star297 1:6f4c5876140d 111 float LedBright;
star297 1:6f4c5876140d 112
star297 1:6f4c5876140d 113 typedef unsigned char byte;
star297 1:6f4c5876140d 114
star297 1:6f4c5876140d 115 // Various text strings used in display
star297 1:6f4c5876140d 116 char weekDayName[7][4] = {"Sun","Mon","Tue","Wed","Thu", "Fri","Sat"};
star297 1:6f4c5876140d 117 char monthName[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
star297 1:6f4c5876140d 118 char statusText[5][18] = {" Waiting Sync "," Reading dcf data"," Checking Parity "," Last Minute Ok "," Signal error "};
star297 1:6f4c5876140d 119 char leapText[2][10] = {" ", "Leap"};
star297 1:6f4c5876140d 120 char MAX_DAY[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // Max days in a month for a non-leap year
star297 1:6f4c5876140d 121
star297 1:6f4c5876140d 122 // Return the maximum day in month for a given month & year
star297 1:6f4c5876140d 123
star297 1:6f4c5876140d 124 byte maxDay(byte year, byte month)
star297 1:6f4c5876140d 125 {
star297 1:6f4c5876140d 126 byte lastday, leap;
star297 1:6f4c5876140d 127 leap = year%4 == 0 && year%100 !=0 || year%400 == 0;
star297 1:6f4c5876140d 128 lastday = MAX_DAY[month - 1];
star297 1:6f4c5876140d 129 dcf_status.is_leap = leap > 0 ? 1 : 0;
star297 1:6f4c5876140d 130 if ((leap > 0) && (month == 2))
star297 1:6f4c5876140d 131 lastday++;
star297 1:6f4c5876140d 132 return lastday;
smultron1977 0:2353da390056 133 }
smultron1977 0:2353da390056 134
star297 1:6f4c5876140d 135 int dayOfWeek(int y, int m, int d) // 0 = Sunday
star297 1:6f4c5876140d 136 {
star297 1:6f4c5876140d 137 static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
star297 1:6f4c5876140d 138 y -= m < 3;
star297 1:6f4c5876140d 139 return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
smultron1977 0:2353da390056 140 }
smultron1977 0:2353da390056 141
star297 1:6f4c5876140d 142 void myISR() //This is the interrupt service routine (ISR) that is called every 50ms
star297 1:6f4c5876140d 143 {
star297 1:6f4c5876140d 144 interrupt_counter++;
star297 1:6f4c5876140d 145
star297 1:6f4c5876140d 146 //dcfLED = !dcfSignalIn; // Show dcfSignal state on LED
star297 1:6f4c5876140d 147
star297 1:6f4c5876140d 148
star297 1:6f4c5876140d 149 if (interrupt_counter == 20) { // 50mS x 20 = 1000mS = 1 Second
star297 1:6f4c5876140d 150 interrupt_counter = 0;
star297 1:6f4c5876140d 151 second++;insecond_counter++;
star297 1:6f4c5876140d 152 if (d.read()> 2) {d.reset();d.start();delay=1;}
star297 1:6f4c5876140d 153 else {delay=0;}
star297 1:6f4c5876140d 154 if (second > 2) {start_delay=0;}
star297 1:6f4c5876140d 155 if (dcf_error==1) {status = 4;}
star297 1:6f4c5876140d 156 }
star297 1:6f4c5876140d 157 if (dcf_sec==58) {status = 2;}
star297 1:6f4c5876140d 158 if (dcf_sec==59) {dcf_check();}
star297 1:6f4c5876140d 159 if (status == 3 && dcf_sec == 1) {set_time();}
star297 1:6f4c5876140d 160
star297 1:6f4c5876140d 161 if (second >= 60) {
star297 1:6f4c5876140d 162 ++minute;
star297 1:6f4c5876140d 163 second -=60;
star297 1:6f4c5876140d 164 }
star297 1:6f4c5876140d 165 if (minute >= 60) {
star297 1:6f4c5876140d 166 ++hour;
star297 1:6f4c5876140d 167 minute-=60;
star297 1:6f4c5876140d 168 }
star297 1:6f4c5876140d 169 if (hour >= 24) {
star297 1:6f4c5876140d 170 hour -=24;
star297 1:6f4c5876140d 171 ++dayofweek;
star297 1:6f4c5876140d 172 ++dayofmonth;
star297 1:6f4c5876140d 173 }
star297 1:6f4c5876140d 174 if (dayofweek > 6)
star297 1:6f4c5876140d 175 dayofweek = 0;
star297 1:6f4c5876140d 176
star297 1:6f4c5876140d 177 if (dayofmonth > maxDay(year, month)) {
star297 1:6f4c5876140d 178 dayofmonth = 1;
star297 1:6f4c5876140d 179 month++;
star297 1:6f4c5876140d 180 }
star297 1:6f4c5876140d 181 if (month > 12) {
star297 1:6f4c5876140d 182 month = 1;
star297 1:6f4c5876140d 183 year++;
star297 1:6f4c5876140d 184 }
star297 1:6f4c5876140d 185 if (year > 99)
star297 1:6f4c5876140d 186 year = 1;
star297 1:6f4c5876140d 187
star297 1:6f4c5876140d 188 switch (interrupt_counter) {
star297 1:6f4c5876140d 189 case 1:{ // 50mS after start of second pulse
star297 1:6f4c5876140d 190 dcf_status.sample50 = (dcfSignalIn);
star297 1:6f4c5876140d 191 break;}
star297 1:6f4c5876140d 192 case 3: { // 150mS after start of second pulse (bit "1" dcf Data)
star297 1:6f4c5876140d 193 dcf_status.sample150 = (dcfSignalIn);
star297 1:6f4c5876140d 194 if (!dcf_status.sample150 && !dcf_status.sample50 && start_delay==0) {zero_bit=1;sync=0;insecond_counter=0;start=1;dcf_sec=0;}
star297 1:6f4c5876140d 195 else {zero_bit=0;}
star297 1:6f4c5876140d 196 break;}
star297 1:6f4c5876140d 197 case 6: { // 300mS after start of second (signal error if true)
star297 1:6f4c5876140d 198 if (dcfSignalIn) {dcf_error = 1;}
star297 1:6f4c5876140d 199 break;}
star297 1:6f4c5876140d 200 case 10: { // 500mS after start of second (signal error if true)
star297 1:6f4c5876140d 201 if (dcfSignalIn) {dcf_error = 1;}
star297 1:6f4c5876140d 202 break;}
star297 1:6f4c5876140d 203 case 12: { // 600mS after start of second (signal error if true)
star297 1:6f4c5876140d 204 if (dcfSignalIn) {dcf_error = 1;}
star297 1:6f4c5876140d 205 break;}
star297 1:6f4c5876140d 206 }
star297 1:6f4c5876140d 207 if (interrupt_counter==1){
star297 1:6f4c5876140d 208 if (dcfSignalIn){nosignal=1;}
star297 1:6f4c5876140d 209 else nosignal++;
star297 1:6f4c5876140d 210 if (nosignal>5){nosignal=2; status = 0; restart();}
star297 1:6f4c5876140d 211 if (dcf_error == 1 && delay == 1) {dcf_error = 0; status = 0;restart();}
star297 1:6f4c5876140d 212 }
star297 1:6f4c5876140d 213 if (interrupt_counter==3){
star297 1:6f4c5876140d 214 if (start==1){
star297 1:6f4c5876140d 215 dcf_array[dcf_sec]=dcf_status.sample150;
star297 1:6f4c5876140d 216 if (insecond_counter==1){
star297 1:6f4c5876140d 217 dcf_sec=0;x=0;y=0;dcf_array[58] = 0; bmd=0;
star297 1:6f4c5876140d 218 if (r == 1){r=0;}
star297 1:6f4c5876140d 219 else {r=1;}
star297 1:6f4c5876140d 220 }
star297 1:6f4c5876140d 221
star297 1:6f4c5876140d 222 if (dcf_sec > 1) {status = 1;}
star297 1:6f4c5876140d 223 if (dcf_sec > 20 && dcf_sec < 59 ) {bit_print();}
star297 1:6f4c5876140d 224 if (dcf_sec > 60) {dcf_error = 1;bit_map_draw();status = 4;dcf_sec=0;dcf_error = 0;}
star297 1:6f4c5876140d 225 if (sync==1) {dcf_sec++;}
star297 1:6f4c5876140d 226 }
star297 1:6f4c5876140d 227 }
star297 1:6f4c5876140d 228 if (sync==0 ) {
star297 1:6f4c5876140d 229 if (dcfSignalIn) {interrupt_counter =0 ;sync=1;}
star297 1:6f4c5876140d 230 }
star297 1:6f4c5876140d 231 } // End of ISR
star297 1:6f4c5876140d 232
star297 1:6f4c5876140d 233 int main()
star297 1:6f4c5876140d 234 {
star297 1:6f4c5876140d 235 DisplayLED=1;
star297 1:6f4c5876140d 236 lcd.background(Black);
smultron1977 0:2353da390056 237 lcd.cls();
star297 1:6f4c5876140d 238 lcd.set_orientation(0);
star297 1:6f4c5876140d 239 lcd.set_font((unsigned char*) Arial11x11);
star297 1:6f4c5876140d 240 lcd.rect(0,0,127,159,(White));
star297 1:6f4c5876140d 241 lcd.locate (15,10);
star297 1:6f4c5876140d 242 lcd.foreground (Red);
star297 1:6f4c5876140d 243 lcd.printf("DCF77 Clock");
star297 1:6f4c5876140d 244 lcd.locate (15,35);
star297 1:6f4c5876140d 245 lcd.foreground (Green);
star297 1:6f4c5876140d 246 lcd.printf("FRDM-KL25Z");
star297 1:6f4c5876140d 247 lcd.locate (20,60);
star297 1:6f4c5876140d 248 lcd.foreground (Blue);
star297 1:6f4c5876140d 249 lcd.printf("HY-1.8 SPI");
star297 1:6f4c5876140d 250 lcd.locate (15,90);
star297 1:6f4c5876140d 251 lcd.foreground (Yellow);
star297 1:6f4c5876140d 252 lcd.printf("128*160 TFT");
star297 1:6f4c5876140d 253 lcd.locate (4,120);
star297 1:6f4c5876140d 254 lcd.foreground (Magenta);
star297 1:6f4c5876140d 255 lcd.printf("Signal pin PTE20");
star297 1:6f4c5876140d 256 lcd.set_font((unsigned char*) Arial9x9);
star297 1:6f4c5876140d 257 wait (2);lcd.cls();r = 1;
star297 1:6f4c5876140d 258 bit_map_draw();dcf_sec=0;bmd=1;start=0;zero_bit=0;
star297 1:6f4c5876140d 259 status = 0; laststatus=1; start_delay=1; laststart=1;
star297 1:6f4c5876140d 260 d.start();showRTC();showRTCdate();
star297 1:6f4c5876140d 261 if (dcfSignalIn) {interrupt_counter =0 ;sync=1;}
star297 1:6f4c5876140d 262 Ticker10ms.attach(& myISR, .05 ); //Setup Ticker to call myISR every 50 ms
star297 1:6f4c5876140d 263
star297 1:6f4c5876140d 264 while (true) {
star297 1:6f4c5876140d 265 loop(); // Continuously get dcf time and Display data interrupted by the Ticker every 50ms
star297 1:6f4c5876140d 266 }
star297 1:6f4c5876140d 267 }
star297 1:6f4c5876140d 268
star297 1:6f4c5876140d 269 void dcf_check()
star297 1:6f4c5876140d 270 {
star297 1:6f4c5876140d 271 parity_calc();
star297 1:6f4c5876140d 272 paritycheck= testu or testm or testdmy;
star297 1:6f4c5876140d 273 if (year>99) paritycheck=1;
star297 1:6f4c5876140d 274 if (month>12) paritycheck=1;
star297 1:6f4c5876140d 275 if (day>31) paritycheck=1;
star297 1:6f4c5876140d 276 if (hour>23) paritycheck=1;
star297 1:6f4c5876140d 277 if (minute>59) paritycheck=1;
star297 1:6f4c5876140d 278 if (paritycheck) {
star297 1:6f4c5876140d 279 status = 4;
smultron1977 0:2353da390056 280 }
star297 1:6f4c5876140d 281 else {
star297 1:6f4c5876140d 282 status = 3;
star297 1:6f4c5876140d 283 }
star297 1:6f4c5876140d 284 }
star297 1:6f4c5876140d 285 void loop()
star297 1:6f4c5876140d 286 {
star297 1:6f4c5876140d 287 if (interrupt_counter == 0) {
star297 1:6f4c5876140d 288 showRTC();
star297 1:6f4c5876140d 289 lcd.locate(60,127);
star297 1:6f4c5876140d 290 lcd.foreground (White);
star297 1:6f4c5876140d 291 lcd.printf("%02d",dcf_sec);
star297 1:6f4c5876140d 292
star297 1:6f4c5876140d 293 if (status == 3 && dcf_sec == 1) {setRTC();RTCsecond=0;showRTC();} // set RTC clock if good data
star297 1:6f4c5876140d 294 }
star297 1:6f4c5876140d 295
star297 1:6f4c5876140d 296 if (interrupt_counter==3){
star297 1:6f4c5876140d 297 if (dcf_status.sample150 != lastbit) {lcd.locate(5,48);lcd.foreground (Cyan);lcd.printf("Bit %d ",dcf_status.sample150);}
star297 1:6f4c5876140d 298 lastbit = dcf_status.sample150;
star297 1:6f4c5876140d 299 if (start==0 && laststart != start) {
star297 1:6f4c5876140d 300 lcd.locate(60,48);lcd.foreground (Red);lcd.printf(" No Sync ");laststart=start;}
star297 1:6f4c5876140d 301 if (start==1 && laststart != start) {
star297 1:6f4c5876140d 302 lcd.locate(60,48);lcd.foreground (Green);lcd.printf(" In Sync ");laststart=start;}
star297 1:6f4c5876140d 303 }
star297 1:6f4c5876140d 304 if (interrupt_counter==3){
star297 1:6f4c5876140d 305 if (RTCsecond == 1) {showRTCdate();}
star297 1:6f4c5876140d 306 }
star297 1:6f4c5876140d 307 if (interrupt_counter>5){
star297 1:6f4c5876140d 308 LedBright = 0 + tsi.readPercentage();
star297 1:6f4c5876140d 309 if (LedBright > 0 ){
star297 1:6f4c5876140d 310 if (LedBright > .01) {DisplayLED = LedBright; }
smultron1977 0:2353da390056 311 }
star297 1:6f4c5876140d 312 }
star297 1:6f4c5876140d 313 if (interrupt_counter == 10){
star297 1:6f4c5876140d 314 if (status==0) {lcd.foreground (White);}
star297 1:6f4c5876140d 315 if (status==1) {lcd.foreground (Cyan);}
star297 1:6f4c5876140d 316 if (status==2) {lcd.foreground (Blue);}
star297 1:6f4c5876140d 317 if (status==3) {lcd.foreground (Green);}
star297 1:6f4c5876140d 318 if (status==4) {lcd.foreground (Red);}
star297 1:6f4c5876140d 319 lcd.locate(0,147);
star297 1:6f4c5876140d 320 if (status != laststatus) {lcd.printf(statusText[status]);}
star297 1:6f4c5876140d 321 laststatus = status;
star297 1:6f4c5876140d 322 lcd.set_font((unsigned char*) Arial9x9);
star297 1:6f4c5876140d 323
star297 1:6f4c5876140d 324 }
star297 1:6f4c5876140d 325 }
star297 1:6f4c5876140d 326
star297 1:6f4c5876140d 327 void showRTC()
star297 1:6f4c5876140d 328 {
star297 1:6f4c5876140d 329 lcd.foreground (White);
star297 1:6f4c5876140d 330 time_t seconds = time(NULL);
star297 1:6f4c5876140d 331 char buffer[40];
star297 1:6f4c5876140d 332 if (RTCsecond == 0) {
star297 1:6f4c5876140d 333 strftime(buffer, 40, "%H:%M", localtime(&seconds));
star297 1:6f4c5876140d 334 lcd.set_font((unsigned char*) Arial24x23i);
star297 1:6f4c5876140d 335 lcd.locate(6,0);
star297 1:6f4c5876140d 336 lcd.printf(buffer);
star297 1:6f4c5876140d 337 }
star297 1:6f4c5876140d 338 lcd.set_font((unsigned char*) Arial11x11);
star297 1:6f4c5876140d 339 strftime(buffer, 40,":%S", localtime(&seconds));
star297 1:6f4c5876140d 340 lcd.locate(96,9);
star297 1:6f4c5876140d 341 lcd.printf(buffer);
star297 1:6f4c5876140d 342 strftime(buffer, 40,"%S", localtime(&seconds));
star297 1:6f4c5876140d 343 RTCsecond = atoi(buffer);
star297 1:6f4c5876140d 344 lcd.set_font((unsigned char*) Arial9x9);
star297 1:6f4c5876140d 345 }
star297 1:6f4c5876140d 346
star297 1:6f4c5876140d 347 void showRTCdate()
star297 1:6f4c5876140d 348 {
star297 1:6f4c5876140d 349 time_t seconds = time(NULL);
star297 1:6f4c5876140d 350 char buffer[40];
star297 1:6f4c5876140d 351 strftime(buffer, 40, "%a %d %b %Y", localtime(&seconds));
star297 1:6f4c5876140d 352 lcd.locate(1,24);
star297 1:6f4c5876140d 353 lcd.foreground (White);
star297 1:6f4c5876140d 354 lcd.set_font((unsigned char*) Arial11x11);
star297 1:6f4c5876140d 355 lcd.printf(buffer);
star297 1:6f4c5876140d 356 lcd.locate(1,36);
star297 1:6f4c5876140d 357 lcd.set_font((unsigned char*) Arial9x9);
star297 1:6f4c5876140d 358 if (status==3) {
star297 1:6f4c5876140d 359 if (summertime) {lcd.foreground (Orange);lcd.printf("Summer Time ");}
star297 1:6f4c5876140d 360 else {lcd.foreground (LightBlue);lcd.printf("Winter Time ");}
star297 1:6f4c5876140d 361 lcd.foreground (Olive);lcd.printf("%s",leapText[dcf_status.is_leap]);
smultron1977 0:2353da390056 362 }
star297 1:6f4c5876140d 363 }
star297 1:6f4c5876140d 364
star297 1:6f4c5876140d 365 void setRTC()
star297 1:6f4c5876140d 366 {
star297 1:6f4c5876140d 367 //Mbed rtc clock set
star297 1:6f4c5876140d 368 struct tm t;
star297 1:6f4c5876140d 369 t.tm_sec = (second); // 0-59
star297 1:6f4c5876140d 370 t.tm_min = (minute); // 0-59
star297 1:6f4c5876140d 371 t.tm_hour = (hour); // 0-23
star297 1:6f4c5876140d 372 t.tm_mday = (dayofmonth); // 1-31
star297 1:6f4c5876140d 373 t.tm_mon = (month-1); // 0-11 DCF "0" = Jan, -1 added for Mbed RCT clock format
star297 1:6f4c5876140d 374 t.tm_year = ((year)+100); // year since 1900, current DCF year + 100 + 1900 = correct year
star297 1:6f4c5876140d 375 set_time(mktime(&t)-3600);
star297 1:6f4c5876140d 376 time_t seconds = mktime(&t);
star297 1:6f4c5876140d 377 }
star297 1:6f4c5876140d 378 void bit_print()
star297 1:6f4c5876140d 379 {
star297 1:6f4c5876140d 380 if (r==1) {lcd.foreground (Magenta);} // alternate bit draw colour
star297 1:6f4c5876140d 381 else {lcd.foreground (White);}
star297 1:6f4c5876140d 382 lcd.locate(x+20,(y+72));
star297 1:6f4c5876140d 383 lcd.printf("%d",dcf_status.sample150);
star297 1:6f4c5876140d 384 y=y+8;
star297 1:6f4c5876140d 385 if ((dcf_sec)==27){(y)=64;}
star297 1:6f4c5876140d 386 if ((dcf_sec)==28){(y)=0;(x)=(x)+12; lcd.printf(" ");}
star297 1:6f4c5876140d 387 if ((dcf_sec)==34){(y)=64;}
star297 1:6f4c5876140d 388 if ((dcf_sec)==35){(y)=0;(x)=(x)+14;}
star297 1:6f4c5876140d 389 if ((dcf_sec)==41){(y)=0;(x)=(x)+14;}
star297 1:6f4c5876140d 390 if ((dcf_sec)==44){(y)=0;(x)=(x)+14;}
star297 1:6f4c5876140d 391 if ((dcf_sec)==49){(y)=0;(x)=(x)+14;}
star297 1:6f4c5876140d 392 }
star297 1:6f4c5876140d 393 void bit_map_draw()
star297 1:6f4c5876140d 394 {
star297 1:6f4c5876140d 395 lcd.foreground (Yellow);
star297 1:6f4c5876140d 396 (x)=18,(y)=59;
star297 1:6f4c5876140d 397 lcd.locate(x,y);lcd.printf("m h d d m y");
star297 1:6f4c5876140d 398 (x)=0,(y)=61;
star297 1:6f4c5876140d 399 y=y+3;
star297 1:6f4c5876140d 400 lcd.locate(x,y+8);lcd.printf(" 1 i o a a o e");
star297 1:6f4c5876140d 401 lcd.locate(x,y+16);lcd.printf(" 2 n u t y n a");
star297 1:6f4c5876140d 402 lcd.locate(x,y+24);lcd.printf(" 4 u r e t r");
star297 1:6f4c5876140d 403 lcd.locate(x,y+32);lcd.printf(" 8 t h ");
star297 1:6f4c5876140d 404 lcd.locate(x,y+40);lcd.printf("10 e ");
star297 1:6f4c5876140d 405 lcd.locate(x,y+48);lcd.printf("20 ");
star297 1:6f4c5876140d 406 lcd.locate(x,y+56);lcd.printf("40 ");
star297 1:6f4c5876140d 407 lcd.locate(x,y+64);lcd.printf("80 ");
star297 1:6f4c5876140d 408 lcd.locate(x,y+72);lcd.printf(" P arity ");
star297 1:6f4c5876140d 409 lcd.fillrect(15,60,16,144,(Red));
star297 1:6f4c5876140d 410 lcd.fillrect(2,69,100,70,(Red));
star297 1:6f4c5876140d 411 }
star297 1:6f4c5876140d 412
star297 1:6f4c5876140d 413 void set_time()
star297 1:6f4c5876140d 414 {
star297 1:6f4c5876140d 415 second = dcf_sec;
star297 1:6f4c5876140d 416 minute=p_minute;
star297 1:6f4c5876140d 417 hour=p_hour;
star297 1:6f4c5876140d 418 dayofweek=p_dayofweek;
star297 1:6f4c5876140d 419 dayofmonth=p_dayofmonth;
star297 1:6f4c5876140d 420 month=p_month;
star297 1:6f4c5876140d 421 year=p_year;
star297 1:6f4c5876140d 422 }
star297 1:6f4c5876140d 423
star297 1:6f4c5876140d 424 void restart()
star297 1:6f4c5876140d 425 {
star297 1:6f4c5876140d 426 start=0;s=0;x=0;y=5;dcf_sec=0;dcf_error=0;
star297 1:6f4c5876140d 427 insecond_counter=0;zero_bit=0;start_delay=1;
star297 1:6f4c5876140d 428 }
star297 1:6f4c5876140d 429
star297 1:6f4c5876140d 430 void parity_calc()
star297 1:6f4c5876140d 431 {
star297 1:6f4c5876140d 432 //calculate summer/winter time----------------------------------------------------------------------
star297 1:6f4c5876140d 433 summertime = dcf_array[17] & 1;
star297 1:6f4c5876140d 434 //calculate hour--------------------------------------------------------------------------------------
star297 1:6f4c5876140d 435 hourh = dcf_array[34] * 20 + dcf_array[33] * 10;
star297 1:6f4c5876140d 436 hourl = dcf_array[32] * 8 + dcf_array[31] * 4 + dcf_array[30] * 2 + dcf_array[29] * 1;
star297 1:6f4c5876140d 437 p_hour = hourh + hourl;
star297 1:6f4c5876140d 438 //calculate minutes------------------------------------------------------------------------------------
star297 1:6f4c5876140d 439 minl = dcf_array[24] * 8 + dcf_array[23] * 4 + dcf_array[22] * 2 + dcf_array[21] * 1;
star297 1:6f4c5876140d 440 minh = dcf_array[27] * 40 + dcf_array[26] * 20 +dcf_array[25] * 10;
star297 1:6f4c5876140d 441 p_minute = minh + minl;
star297 1:6f4c5876140d 442 //calculate day of week--------------------------------------------------------------------------------
star297 1:6f4c5876140d 443 p_dayofweek = dcf_array[44] * 4 +dcf_array[43] * 2 + dcf_array[42] * 1;
star297 1:6f4c5876140d 444 //calculate day----------------------------------------------------------------------------------------
star297 1:6f4c5876140d 445 dayl = dcf_array[39] * 8 + dcf_array[38] * 4 + dcf_array[37] * 2 + dcf_array[36] * 1;
star297 1:6f4c5876140d 446 dayh = dcf_array[41] * 20 + dcf_array[40] * 10;
star297 1:6f4c5876140d 447 p_dayofmonth=dayh+dayl;
star297 1:6f4c5876140d 448 //calculate month--------------------------------------------------------------------------------------
star297 1:6f4c5876140d 449 monthh = dcf_array[49] * 10;
star297 1:6f4c5876140d 450 monthl = dcf_array[48] * 8 + dcf_array[47] * 4 + dcf_array[46] * 2 + dcf_array[45] * 1;
star297 1:6f4c5876140d 451 p_month = monthh +monthl;
star297 1:6f4c5876140d 452 //calculate year---------------------------------------------------------------------------------------
star297 1:6f4c5876140d 453 yearh = dcf_array[57] * 80 + dcf_array[56] * 40 + dcf_array[55] * 20 + dcf_array[54] * 10;
star297 1:6f4c5876140d 454 yearl = dcf_array[53] * 8 +dcf_array[52] * 4 + dcf_array[51] * 2 + dcf_array[50] * 1;
star297 1:6f4c5876140d 455 p_year = yearh+yearl;
star297 1:6f4c5876140d 456 //calculate parity
star297 1:6f4c5876140d 457 paritym = dcf_array[21] + dcf_array[22] + dcf_array[23] + dcf_array[24] + dcf_array[25] + dcf_array[26] +dcf_array[27] +dcf_array [28];
star297 1:6f4c5876140d 458 parityu =dcf_array[29] + dcf_array[30] + dcf_array[31] + dcf_array[32] + dcf_array[33] + dcf_array[34] + dcf_array[35];
star297 1:6f4c5876140d 459 paritydmy =dcf_array[36] + dcf_array [37] + dcf_array [38] + dcf_array [39] + dcf_array[40] + dcf_array[41] + dcf_array [42] + dcf_array [43] + dcf_array[44] + dcf_array [45] + dcf_array[46] + dcf_array [47] + dcf_array[48] + dcf_array[49] + dcf_array[50] + dcf_array[51] + dcf_array [52] + dcf_array[53] + dcf_array[54] + dcf_array[55] + dcf_array[56] + dcf_array[57] + dcf_array[58];
star297 1:6f4c5876140d 460 //test parity------------------------------
star297 1:6f4c5876140d 461 testu=parityu & 1;
star297 1:6f4c5876140d 462 testm=paritym & 1;
star297 1:6f4c5876140d 463 testdmy=paritydmy & 1;
smultron1977 0:2353da390056 464 }