Demo program for the Oled display

Dependencies:   mbed-src

Committer:
star297
Date:
Fri Jan 09 00:11:48 2015 +0000
Revision:
1:793dbd6d6498
Parent:
0:94bf5ec759da
Child:
2:1eac3ea8c6e8
Oled demo v1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
star297 0:94bf5ec759da 1 #include "mbed.h"
star297 0:94bf5ec759da 2 #include "OLED32028P1T.h"
star297 0:94bf5ec759da 3
star297 1:793dbd6d6498 4
star297 1:793dbd6d6498 5 OLED32028P1T oled(PTE0,PTE1,PTA12); // Oled Display tx, rx, rs
star297 1:793dbd6d6498 6 InterruptIn SignalIn(PTC1); // conection of output NON-inverting DCF module
star297 1:793dbd6d6498 7 DigitalOut SignalLED(LED3); // indicates DCF signal on Mbed
star297 1:793dbd6d6498 8
star297 1:793dbd6d6498 9 Timer T1,T2,T3;
star297 1:793dbd6d6498 10 Ticker Ticker50ms; // DCF IRQ timer
star297 1:793dbd6d6498 11
star297 1:793dbd6d6498 12 #define clkx 110 //this point represent the x center of the clock where maths is done
star297 1:793dbd6d6498 13 #define clky 138 //this point represent the y center of the clock where maths is done
star297 1:793dbd6d6498 14
star297 1:793dbd6d6498 15 char timebuf[40];
star297 1:793dbd6d6498 16 char datebuf[40];
star297 1:793dbd6d6498 17 char paritycheck,paritym,parityu,paritydmy;
star297 1:793dbd6d6498 18 char testu,testm,testdmy,summertime;
star297 1:793dbd6d6498 19 char min,minh,minl,hourh,hourl,day,dayh,dayl,monthh,monthl,yearh,yearl;
star297 1:793dbd6d6498 20 char weekDayName[7][4] = {"Sun","Mon","Tue","Wed","Thu", "Fri","Sat"};
star297 1:793dbd6d6498 21 char monthName[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
star297 1:793dbd6d6498 22 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:793dbd6d6498 23 char statusText[6][20] = {"Waiting Synchronise"," Wait for 21st bit ","Reading Signal data"," Checking Parity "," Last Minute Okay "," Signal error "};
star297 1:793dbd6d6498 24 char leapSymbol[2][10] = {" ", "Leap Year"};
star297 0:94bf5ec759da 25
star297 1:793dbd6d6498 26 int hour,minute,second,dayofweek,dayofmonth,month,year,nextsec,DCF;
star297 1:793dbd6d6498 27 int RTCsecond,RTCminute,RTChour,RTCdayofweek,RTCdayofmonth,RTCmonth,RTCyear;
star297 1:793dbd6d6498 28 int xbuffer,ybuffer,IRQ;
star297 1:793dbd6d6498 29 int xs,ys,xm,ym,xh,yh,x,y;
star297 1:793dbd6d6498 30 int handHour=60,handMin=75,handSec=78; //RTC clock hand sizes
star297 1:793dbd6d6498 31 int numposx=105,numposy=135; // RTC clock number screen posistion
star297 1:793dbd6d6498 32
star297 1:793dbd6d6498 33 int start,sync,SignalStatus,nosignal,laststart,loop,interrupt_counter,dcf_sec,error_count;
star297 1:793dbd6d6498 34 int tz,rtcset,rtcset_times;
star297 1:793dbd6d6498 35 int r=255,g=255,b=255;
star297 1:793dbd6d6498 36 int draw_graph,dcf_good,signal_error,dcf_error,display;
star297 1:793dbd6d6498 37 int p_minute,p_hour,p_dayofweek,p_dayofmonth,p_month,p_year;
star297 1:793dbd6d6498 38 int dcf_array[61];
star297 1:793dbd6d6498 39
star297 1:793dbd6d6498 40 float angleH,angleM,angleS;
star297 1:793dbd6d6498 41 float fsecond,fminute;
star297 1:793dbd6d6498 42
star297 1:793dbd6d6498 43 typedef unsigned char byte;
star297 1:793dbd6d6498 44
star297 1:793dbd6d6498 45 struct tm t;
star297 1:793dbd6d6498 46
star297 1:793dbd6d6498 47 void RTCsetclock(),RTCset(),RTCread(),RTCclock(),RTCclockdraw(),RTCclockupdate();
star297 1:793dbd6d6498 48 void dcfISR(),dcfIRQ(),checkSIGNAL(),signal(),DCFbitprint();
star297 1:793dbd6d6498 49 void DCFclock(),DCFloop(),DCFshowClock(),DCFtestparity();
star297 1:793dbd6d6498 50 void DCFcheck(),bitprint(),DCFdrawgraph();
star297 1:793dbd6d6498 51 void DCFbitmapdraw(),DCFparitycalc(),DCFbitstatus(),DCFbitstatus2();
star297 1:793dbd6d6498 52 void DCFsetTime();
star297 0:94bf5ec759da 53
star297 1:793dbd6d6498 54 struct SignalStatus {
star297 1:793dbd6d6498 55 bool is_leap; // Leap year flag (NOT actually transmitted but calculated)
star297 1:793dbd6d6498 56 bool DCFsample50; // dcf sample at 50mS into the start of the second, seocnd marker pulse
star297 1:793dbd6d6498 57 bool DCFsample150; // dcf sample at 150mS into the start of the second, bit=1 if high, 0 if low
star297 1:793dbd6d6498 58 bool DCFsample300; // dcf sample at 300mS into the start of the second, error if high
star297 1:793dbd6d6498 59 bool DCFsample500; // dcf sample at 500mS into the start of the second, error if high
star297 1:793dbd6d6498 60 bool DCFsample600; // dcf sample at 600mS into the start of the second, error if high
star297 1:793dbd6d6498 61 unsigned char frame; // Received MSF framing code 01111110
star297 1:793dbd6d6498 62 int second; // MSF-DCF second (NOT actually transmitted but calculated)
star297 1:793dbd6d6498 63 } dcf_status;
star297 1:793dbd6d6498 64
star297 1:793dbd6d6498 65
star297 1:793dbd6d6498 66 // Return the maximum day in month for a given month & year
star297 1:793dbd6d6498 67 byte maxDay(byte year, byte month)
star297 1:793dbd6d6498 68 {
star297 1:793dbd6d6498 69 byte lastday, leap;
star297 1:793dbd6d6498 70 leap = year%4 == 0 && year%100 !=0 || year%400 == 0;
star297 1:793dbd6d6498 71 lastday = MAX_DAY[month - 1];
star297 1:793dbd6d6498 72 dcf_status.is_leap = leap > 0 ? 1 : 0;
star297 1:793dbd6d6498 73 if ((leap > 0) && (month == 2))
star297 1:793dbd6d6498 74 lastday++;
star297 1:793dbd6d6498 75 return lastday;
star297 1:793dbd6d6498 76 }
star297 0:94bf5ec759da 77
star297 1:793dbd6d6498 78 int main() {
star297 1:793dbd6d6498 79
star297 1:793dbd6d6498 80 SignalLED=1;
star297 1:793dbd6d6498 81 oled.init();
star297 1:793dbd6d6498 82 oled.clear();
star297 1:793dbd6d6498 83 oled.setTextBackgroundType(TEXT_OPAQUE);
star297 1:793dbd6d6498 84 oled.setFontSize(FONT12X16);oled.setFontColor(oled.toRGB(255,255,0));
star297 1:793dbd6d6498 85 oled.setFontColor(oled.toRGB(255,255,0));
star297 1:793dbd6d6498 86 oled.drawText(2,0,(FONT12X16),"--drawText vs. printf--",oled.toRGB(255,0,255));
star297 1:793dbd6d6498 87 oled.drawText(2,22,(FONT5X7),"Use drawText as much as possible, it's nearly twice",oled.toRGB(255,255,255));
star297 1:793dbd6d6498 88 oled.drawText(2,23,(FONT5X7),"as fast as printf. Make sure the serial stream is",oled.toRGB(255,255,255));
star297 1:793dbd6d6498 89 oled.drawText(2,24,(FONT5X7),"NOT",oled.toRGB(255,0,0));
star297 1:793dbd6d6498 90 oled.drawText(6,24,(FONT5X7),"interrupted when printing.",oled.toRGB(255,255,255));
star297 1:793dbd6d6498 91 if (time(NULL) < 1396310400) {set_time(1396310400);}
star297 1:793dbd6d6498 92 T3.start();
star297 0:94bf5ec759da 93
star297 1:793dbd6d6498 94 while(T3<10){
star297 1:793dbd6d6498 95 oled.setFontColor(oled.toRGB(0,255,255));
star297 1:793dbd6d6498 96 oled.locate (12,18);
star297 1:793dbd6d6498 97 oled.printf("Next page in %2.1f seconds ",10 - T3.read());
star297 1:793dbd6d6498 98
star297 1:793dbd6d6498 99 time_t seconds = time(NULL);
star297 1:793dbd6d6498 100 strftime(timebuf, 32, "RTC %I:%M:%S %p", localtime(&seconds));
star297 1:793dbd6d6498 101 strftime(datebuf, 32, "%a %d %b %Y ", localtime(&seconds));
star297 1:793dbd6d6498 102
star297 1:793dbd6d6498 103 T1.start();
star297 1:793dbd6d6498 104 oled.drawText(2,2,(FONT12X16),timebuf,oled.toRGB(255,255,0));
star297 1:793dbd6d6498 105 oled.drawText(2,3,(FONT12X16),datebuf,oled.toRGB(255,255,0));
star297 1:793dbd6d6498 106 T1.stop();
star297 1:793dbd6d6498 107
star297 1:793dbd6d6498 108 T2.start();
star297 1:793dbd6d6498 109 oled.setFontColor(oled.toRGB(0,255,0));
star297 1:793dbd6d6498 110 oled.setFontSize(FONT12X16);
star297 1:793dbd6d6498 111 oled.locate (2,6);
star297 1:793dbd6d6498 112 oled.printf("%s",timebuf);
star297 1:793dbd6d6498 113 oled.locate (2,7);
star297 1:793dbd6d6498 114 oled.printf("%s",datebuf);
star297 1:793dbd6d6498 115 T2.stop();
star297 0:94bf5ec759da 116
star297 1:793dbd6d6498 117 oled.setFontColor(oled.toRGB(255,255,255));
star297 1:793dbd6d6498 118 oled.setFontSize(FONT8X12);
star297 1:793dbd6d6498 119 oled.locate (4,6);
star297 1:793dbd6d6498 120 oled.printf("drawText time %3.2f mS",T1.read()*1000);T1.reset();
star297 1:793dbd6d6498 121 oled.locate (4,11);
star297 1:793dbd6d6498 122 oled.printf("printf time %3.2f mS",T2.read()*1000);T2.reset();
star297 1:793dbd6d6498 123 }
star297 1:793dbd6d6498 124 T3.reset();
star297 1:793dbd6d6498 125 while(1){
star297 1:793dbd6d6498 126 IRQ=0;
star297 1:793dbd6d6498 127 SignalLED=1;
star297 1:793dbd6d6498 128 RTCclock();
star297 1:793dbd6d6498 129 }
star297 1:793dbd6d6498 130
star297 1:793dbd6d6498 131 }
star297 1:793dbd6d6498 132
star297 1:793dbd6d6498 133 void RTCclock()
star297 1:793dbd6d6498 134 {
star297 1:793dbd6d6498 135 while(IRQ==0){
star297 1:793dbd6d6498 136 oled.disableTouch();oled.clear();
star297 1:793dbd6d6498 137 oled.setTextBackgroundType (TEXT_TRANSPARENT);
star297 1:793dbd6d6498 138 RTCclockdraw();
star297 1:793dbd6d6498 139 oled.drawTextButton(1, 200, 210,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "DCF Clock");
star297 1:793dbd6d6498 140 oled.drawTextButton(1, 252, 185,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "Set RTC");
star297 1:793dbd6d6498 141 oled.setTextBackgroundType (TEXT_OPAQUE);
star297 1:793dbd6d6498 142 oled.drawText(0,0,(FONT12X16),"RTC Clock",oled.toRGB(255,0,0));
star297 1:793dbd6d6498 143 oled.enableTouch();oled.resetTouchArea();
star297 1:793dbd6d6498 144
star297 1:793dbd6d6498 145 while(IRQ==0){
star297 1:793dbd6d6498 146 oled.setFontSize(FONT12X16);oled.locate(0,1);
star297 1:793dbd6d6498 147 oled.setFontColor(oled.toRGB(255,255,255));
star297 1:793dbd6d6498 148 time_t seconds = time(NULL);
star297 1:793dbd6d6498 149 strftime(timebuf, 32, "%I:%M:%S %p", localtime(&seconds));
star297 1:793dbd6d6498 150 strftime(datebuf, 32, "%a %d %b %Y ", localtime(&seconds));
star297 1:793dbd6d6498 151 oled.drawText(11,0,(FONT12X16),timebuf,oled.toRGB(255,255,0));
star297 1:793dbd6d6498 152 oled.drawText(11,1,(FONT12X16),datebuf,oled.toRGB(255,255,0));
star297 1:793dbd6d6498 153
star297 1:793dbd6d6498 154 if (seconds != nextsec) {RTCclockupdate();nextsec=seconds;}
star297 1:793dbd6d6498 155 oled.getTouch(&xbuffer,&ybuffer);
star297 1:793dbd6d6498 156
star297 1:793dbd6d6498 157 oled.setFontSize(FONT5X7);oled.locate(40,6); // this shows touch position
star297 1:793dbd6d6498 158 oled.printf("X %03d Y %03d ",xbuffer,ybuffer); // and can be removed
star297 1:793dbd6d6498 159
star297 1:793dbd6d6498 160 if((xbuffer>195 && xbuffer<300) && (ybuffer>205 && ybuffer<220)){DCFclock();}
star297 1:793dbd6d6498 161 if((xbuffer>240 && xbuffer<300) && (ybuffer>182 && ybuffer<200)){RTCsetclock();}
star297 1:793dbd6d6498 162 }
star297 1:793dbd6d6498 163 }
star297 1:793dbd6d6498 164 }
star297 1:793dbd6d6498 165
star297 1:793dbd6d6498 166 void RTCclockdraw()
star297 1:793dbd6d6498 167 {
star297 1:793dbd6d6498 168 (x)=0;
star297 1:793dbd6d6498 169 while ((x)<60){
star297 1:793dbd6d6498 170 x++;angleS=(x)*6; // clock minute markers in angle form
star297 1:793dbd6d6498 171 xs=(sin((angleS*3.14)/180)) * 90; // X component of markers
star297 1:793dbd6d6498 172 ys=(cos((angleS*3.14)/180)) * 90; // Y component of markers
star297 1:793dbd6d6498 173 oled.drawLine(clkx,clky,clkx+xs,clky-ys,oled.toRGB(255,255,255));
star297 1:793dbd6d6498 174 }
star297 1:793dbd6d6498 175 (x)=0;
star297 1:793dbd6d6498 176 while ((x)<13){
star297 1:793dbd6d6498 177 x++;angleS=(x)*30; // clock hour markers in angle form
star297 1:793dbd6d6498 178 xs=(sin((angleS*3.14)/180)) * 90; // X component of markers
star297 1:793dbd6d6498 179 ys=(cos((angleS*3.14)/180)) * 90; // Y component of markers
star297 1:793dbd6d6498 180 oled.drawLine(clkx,clky,clkx+xs,clky-ys,oled.toRGB(0,255,255));
star297 1:793dbd6d6498 181 if (x==1) oled.drawTextGraphic(numposx +(xs+8),numposy + (ys+8), FONT5X7, "5", 1, 1, oled.toRGB(255,255,255));
star297 1:793dbd6d6498 182 if (x==2) oled.drawTextGraphic(numposx +(xs+10),numposy + (ys+4), FONT5X7, "4", 1, 1, oled.toRGB(255,255,255));
star297 1:793dbd6d6498 183 if (x==3) oled.drawTextGraphic(numposx +(xs+10),numposy + (ys), FONT5X7, "3", 1, 1, oled.toRGB(255,255,255));
star297 1:793dbd6d6498 184 if (x==4) oled.drawTextGraphic(numposx +(xs+10),numposy + (ys-4), FONT5X7, "2", 1, 1, oled.toRGB(255,255,255));
star297 1:793dbd6d6498 185 if (x==5) oled.drawTextGraphic(numposx +(xs+8),numposy + (ys-8), FONT5X7, "1", 1, 1, oled.toRGB(255,255,255));
star297 1:793dbd6d6498 186 if (x==6) oled.drawTextGraphic(numposx +(xs),numposy + (ys-8), FONT5X7, "12", 1, 1, oled.toRGB(255,255,255));
star297 1:793dbd6d6498 187 if (x==7) oled.drawTextGraphic(numposx +(xs-4),numposy + (ys-8), FONT5X7, "11", 1, 1, oled.toRGB(255,255,255));
star297 1:793dbd6d6498 188 if (x==8) oled.drawTextGraphic(numposx +(xs-10),numposy + (ys-4), FONT5X7, "10", 1, 1, oled.toRGB(255,255,255));
star297 1:793dbd6d6498 189 if (x==9) oled.drawTextGraphic(numposx +(xs-4),numposy + (ys), FONT5X7, "9", 1, 1, oled.toRGB(255,255,255));
star297 1:793dbd6d6498 190 if (x==10) oled.drawTextGraphic(numposx +(xs-4),numposy + (ys+4), FONT5X7, "8", 1, 1, oled.toRGB(255,255,255));
star297 1:793dbd6d6498 191 if (x==11) oled.drawTextGraphic(numposx +(xs),numposy + (ys+8), FONT5X7, "7", 1, 1, oled.toRGB(255,255,255));
star297 1:793dbd6d6498 192 if (x==12) oled.drawTextGraphic(numposx +(xs+3),numposy + (ys+8), FONT5X7, "6", 1, 1, oled.toRGB(255,255,255));
star297 1:793dbd6d6498 193 }
star297 1:793dbd6d6498 194 oled.setPenSize(0);
star297 1:793dbd6d6498 195 oled.drawCircle(clkx,clky,80,oled.toRGB(0,0,0));
star297 1:793dbd6d6498 196 oled.setPenSize(1);
star297 1:793dbd6d6498 197 oled.drawCircle(clkx,clky,80,oled.toRGB(255,255,255));
star297 1:793dbd6d6498 198 oled.drawCircle(clkx,clky,90,oled.toRGB(255,255,255));
star297 1:793dbd6d6498 199 (x)=0;
star297 1:793dbd6d6498 200 }
star297 1:793dbd6d6498 201
star297 1:793dbd6d6498 202 void RTCsetclock()
star297 1:793dbd6d6498 203 {
star297 1:793dbd6d6498 204 oled.disableTouch();oled.clear();
star297 1:793dbd6d6498 205 oled.drawText(0,0,(FONT12X16)," --Manual set RTC Time--",oled.toRGB(0,255,0));
star297 1:793dbd6d6498 206 oled.setTextBackgroundType (TEXT_TRANSPARENT);
star297 1:793dbd6d6498 207 oled.drawTextButton(1, 265, 200,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(255,255,255)), 1, 1, " Back ");
star297 1:793dbd6d6498 208 oled.drawTextButton(1, 10, 200,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " Reset RTC ");
star297 1:793dbd6d6498 209 oled.drawTextButton(1, 120, 200,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " Set RTC ");
star297 1:793dbd6d6498 210 oled.drawTextButton(1, 16, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "+");
star297 1:793dbd6d6498 211 oled.drawTextButton(1, 16, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "-");
star297 1:793dbd6d6498 212 oled.drawTextButton(1, 52, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "+");
star297 1:793dbd6d6498 213 oled.drawTextButton(1, 52, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "-");
star297 1:793dbd6d6498 214 oled.drawTextButton(1, 88, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "+");
star297 1:793dbd6d6498 215 oled.drawTextButton(1, 88, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "-");
star297 1:793dbd6d6498 216
star297 1:793dbd6d6498 217 oled.drawTextButton(1, 174, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "+");
star297 1:793dbd6d6498 218 oled.drawTextButton(1, 174, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "-");
star297 1:793dbd6d6498 219 oled.drawTextButton(1, 208, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " + ");
star297 1:793dbd6d6498 220 oled.drawTextButton(1, 208, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " - ");
star297 1:793dbd6d6498 221 oled.drawTextButton(1, 270, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " + ");
star297 1:793dbd6d6498 222 oled.drawTextButton(1, 270, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " - ");
star297 1:793dbd6d6498 223 oled.setTextBackgroundType (TEXT_OPAQUE);
star297 1:793dbd6d6498 224 RTCread();
star297 1:793dbd6d6498 225 second=RTCsecond;minute=RTCminute;hour=RTChour;dayofweek=RTCdayofweek;dayofmonth=RTCdayofmonth;month=RTCmonth;year=RTCyear;
star297 1:793dbd6d6498 226
star297 1:793dbd6d6498 227 while(IRQ==0){
star297 1:793dbd6d6498 228
star297 1:793dbd6d6498 229 oled.enableTouch();
star297 1:793dbd6d6498 230 time_t seconds = time(NULL);
star297 1:793dbd6d6498 231 strftime(timebuf, 32, "%H:%M:%S", localtime(&seconds));
star297 1:793dbd6d6498 232 strftime(datebuf, 32, "%a %d %b' %Y", localtime(&seconds));
star297 1:793dbd6d6498 233 oled.drawText(0,2,(FONT12X16),timebuf,oled.toRGB(255,255,255));
star297 1:793dbd6d6498 234 oled.drawText(10,2,(FONT12X16),datebuf,oled.toRGB(255,255,255));
star297 1:793dbd6d6498 235
star297 1:793dbd6d6498 236 oled.getTouch(&xbuffer,&ybuffer);
star297 1:793dbd6d6498 237 if((xbuffer>240 && xbuffer<290) && (ybuffer>190 && ybuffer<210)){RTCclock();}
star297 1:793dbd6d6498 238 if((xbuffer>20 && xbuffer<109) && (ybuffer>190 && ybuffer<210)){set_time(1396310400);}
star297 1:793dbd6d6498 239 if((xbuffer>120 && xbuffer<195) && (ybuffer>195 && ybuffer<210)){RTCset();RTCread();
star297 1:793dbd6d6498 240 second=RTCsecond;minute=RTCminute;hour=RTChour;dayofweek=RTCdayofweek;dayofmonth=RTCdayofmonth;month=RTCmonth;year=RTCyear;
star297 1:793dbd6d6498 241 }
star297 1:793dbd6d6498 242
star297 1:793dbd6d6498 243 if((xbuffer>25 && xbuffer<40) && (ybuffer>124 && ybuffer<140)){hour++;}
star297 1:793dbd6d6498 244 if((xbuffer>25 && xbuffer<40) && (ybuffer>146 && ybuffer<160)){hour--;}
star297 1:793dbd6d6498 245 if((xbuffer>58 && xbuffer<74) && (ybuffer>124 && ybuffer<140)){minute++;}
star297 1:793dbd6d6498 246 if((xbuffer>58 && xbuffer<74) && (ybuffer>146 && ybuffer<160)){minute--;}
star297 1:793dbd6d6498 247 if((xbuffer>90 && xbuffer<105) && (ybuffer>124 && ybuffer<140)){second++;}
star297 1:793dbd6d6498 248 if((xbuffer>90 && xbuffer<105) && (ybuffer>146 && ybuffer<160)){second--;}
star297 1:793dbd6d6498 249 if((xbuffer>170 && xbuffer<186) && (ybuffer>124 && ybuffer<140)){dayofmonth++;}
star297 1:793dbd6d6498 250 if((xbuffer>170 && xbuffer<186) && (ybuffer>146 && ybuffer<160)){dayofmonth--;}
star297 1:793dbd6d6498 251 if((xbuffer>200 && xbuffer<230) && (ybuffer>124 && ybuffer<140)){month++;}
star297 1:793dbd6d6498 252 if((xbuffer>200 && xbuffer<230) && (ybuffer>146 && ybuffer<160)){month--;}
star297 1:793dbd6d6498 253 if((xbuffer>258 && xbuffer<288) && (ybuffer>124 && ybuffer<140)){year++;}
star297 1:793dbd6d6498 254 if((xbuffer>258 && xbuffer<288) && (ybuffer>146 && ybuffer<160)){year--;}
star297 1:793dbd6d6498 255 oled.disableTouch();
star297 1:793dbd6d6498 256
star297 1:793dbd6d6498 257 if (second >= 60) {second = 0;}
star297 1:793dbd6d6498 258 if (second < 0) {second = 59;}
star297 1:793dbd6d6498 259 if (minute >= 60) {minute = 0;}
star297 1:793dbd6d6498 260 if (minute < 0) {minute = 59;}
star297 1:793dbd6d6498 261 if (hour >= 24) {hour = 0;}
star297 1:793dbd6d6498 262 if (hour < 0) {hour = 23;}
star297 1:793dbd6d6498 263 if (dayofweek > 6){dayofweek = 0;}
star297 1:793dbd6d6498 264 if (dayofweek < 0){dayofweek = 6;}
star297 1:793dbd6d6498 265 if (month > 12) {month = 1;}
star297 1:793dbd6d6498 266 if (month < 1) {month = 12;}
star297 1:793dbd6d6498 267 if (dayofmonth <1) {dayofmonth = maxDay(year, month);}
star297 1:793dbd6d6498 268 if (dayofmonth > maxDay(year, month)) {dayofmonth = 1;}
star297 1:793dbd6d6498 269 if (year > 99) {year = 1;}
star297 1:793dbd6d6498 270 if (year < 0) {year = 99;}
star297 1:793dbd6d6498 271
star297 1:793dbd6d6498 272
star297 1:793dbd6d6498 273 oled.setFontSize(FONT12X16);oled.locate(1,6);
star297 1:793dbd6d6498 274 oled.setFontColor(oled.toRGB(60,255,255));
star297 1:793dbd6d6498 275 oled.printf("%2d:%02d:%02d ",hour,minute,second);
star297 1:793dbd6d6498 276 oled.printf("%s %02d %s' 20%02d",weekDayName[dayofweek],dayofmonth,monthName[month-1],year);
star297 1:793dbd6d6498 277 }
star297 0:94bf5ec759da 278
star297 1:793dbd6d6498 279 }
star297 1:793dbd6d6498 280 void RTCclockupdate()
star297 1:793dbd6d6498 281 {
star297 1:793dbd6d6498 282 RTCread();
star297 1:793dbd6d6498 283 fsecond = (RTCsecond/12);
star297 1:793dbd6d6498 284 fminute = (RTCminute/12);
star297 1:793dbd6d6498 285 if (x==1){ //Erase all hands
star297 1:793dbd6d6498 286 oled.drawLine(clkx,clky,clkx+xs,clky-ys,oled.toRGB(0,0,0)); // Erase Second's hand
star297 1:793dbd6d6498 287 oled.drawLine(clkx,clky,clkx+xm,clky-ym,oled.toRGB(0,0,0)); // Erase Minute's hand
star297 1:793dbd6d6498 288 oled.drawLine(clkx,clky,clkx+xh,clky-yh,oled.toRGB(0,0,0)); // Erase Hour's hand
star297 1:793dbd6d6498 289 }
star297 1:793dbd6d6498 290 //Calculations to get the second point of the clock hands. (first point is always the center of the clock)
star297 1:793dbd6d6498 291 angleS=(RTCsecond*6); //seconds in angle form, 360 degrees divided by 60 seconds = 6, x6 to get current angle
star297 1:793dbd6d6498 292 xs=(sin((angleS*3.14)/180)) * handSec; //get X component of the second's hand
star297 1:793dbd6d6498 293 ys=(cos((angleS*3.14)/180)) * handSec; //get Y component of the second's hand
star297 1:793dbd6d6498 294 angleM=((RTCminute*6) + fsecond); //minutes in angle form, 360 degrees divided by 60 minutes = 6, add seconds fraction, x6 to get current angle
star297 1:793dbd6d6498 295 xm=(sin((angleM*3.14)/180)) * handMin; //get X component of the minutes's hand
star297 1:793dbd6d6498 296 ym=(cos((angleM*3.14)/180)) * handMin; //get Y component of the minutes's hand
star297 1:793dbd6d6498 297 angleH=(((RTChour*5) + (fminute))*6); //hours in angle form, 360 degrees multiply hours by 5 hours = 60, add minute fraction, x6 to get angle
star297 1:793dbd6d6498 298 xh=(sin((angleH*3.14)/180)) * handHour; //get X component of the hours's hand
star297 1:793dbd6d6498 299 yh=(cos((angleH*3.14)/180)) * handHour; //get Y component of the hours's hand
star297 1:793dbd6d6498 300 x=1;
star297 1:793dbd6d6498 301 //Draw current time hands
star297 1:793dbd6d6498 302 oled.drawLine(clkx,clky,clkx+xm,clky-ym,oled.toRGB(255,255,255));
star297 1:793dbd6d6498 303 oled.drawLine(clkx,clky,clkx+xh,clky-yh,oled.toRGB(0,255,255));
star297 1:793dbd6d6498 304 oled.drawLine(clkx,clky,clkx+xs,clky-ys,oled.toRGB(255,255,0));
star297 1:793dbd6d6498 305 oled.setPenSize(0);
star297 1:793dbd6d6498 306 oled.drawCircle(clkx,clky,5,oled.toRGB(255,255,255)); // Draw the center of the second's hand
star297 1:793dbd6d6498 307 }
star297 1:793dbd6d6498 308
star297 1:793dbd6d6498 309 void RTCread()
star297 1:793dbd6d6498 310 {
star297 1:793dbd6d6498 311 time_t seconds = time(NULL);
star297 1:793dbd6d6498 312 char buffer[80];
star297 1:793dbd6d6498 313 strftime(buffer, 2,"%S", localtime(&seconds));
star297 1:793dbd6d6498 314 RTCsecond = atoi(buffer);
star297 1:793dbd6d6498 315 strftime(buffer, 2,"%M", localtime(&seconds));
star297 1:793dbd6d6498 316 RTCminute = atoi(buffer);
star297 1:793dbd6d6498 317 strftime(buffer, 2,"%H", localtime(&seconds));
star297 1:793dbd6d6498 318 RTChour = atoi(buffer);
star297 1:793dbd6d6498 319 strftime(buffer, 2,"%d", localtime(&seconds));
star297 1:793dbd6d6498 320 RTCdayofmonth = atoi(buffer);
star297 1:793dbd6d6498 321 strftime(buffer, 2,"%w", localtime(&seconds));
star297 1:793dbd6d6498 322 RTCdayofweek = atoi(buffer);
star297 1:793dbd6d6498 323 strftime(buffer, 2,"%m", localtime(&seconds));
star297 1:793dbd6d6498 324 RTCmonth = atoi(buffer);
star297 1:793dbd6d6498 325 strftime(buffer, 2,"%y", localtime(&seconds));
star297 1:793dbd6d6498 326 RTCyear = atoi(buffer);
star297 1:793dbd6d6498 327 }
star297 1:793dbd6d6498 328
star297 1:793dbd6d6498 329 void RTCset()
star297 1:793dbd6d6498 330 {
star297 1:793dbd6d6498 331 t.tm_sec = (second); // 0-59
star297 1:793dbd6d6498 332 t.tm_min = (minute); // 0-59
star297 1:793dbd6d6498 333 t.tm_hour = (hour); // 0-23
star297 1:793dbd6d6498 334 t.tm_mday = (dayofmonth); // 1-31
star297 1:793dbd6d6498 335 t.tm_mon = (month-1); // 0-11 DCF "0" = Jan, -1 added for Mbed RCT clock format
star297 1:793dbd6d6498 336 t.tm_year = ((year)+100); // year since 1900, current DCF year + 100 + 1900 = correct year
star297 1:793dbd6d6498 337 if (DCF==1) {set_time(mktime(&t)-3600);} // set RTC clock to DCF -1 hour for GMT time zone
star297 1:793dbd6d6498 338 else {set_time(mktime(&t));} // set RTC clock to local time zone
star297 1:793dbd6d6498 339 DCF=0;
star297 1:793dbd6d6498 340 }
star297 1:793dbd6d6498 341
star297 1:793dbd6d6498 342 // **************************** DCF clock **********************************************
star297 1:793dbd6d6498 343
star297 1:793dbd6d6498 344 void DCFclock()
star297 1:793dbd6d6498 345 {
star297 1:793dbd6d6498 346 oled.clear();DCFbitmapdraw();RTCread();
star297 1:793dbd6d6498 347 second=RTCsecond;minute=RTCminute;hour=RTChour;dayofweek=RTCdayofweek;dayofmonth=RTCdayofmonth;month=RTCmonth;year=RTCyear;
star297 1:793dbd6d6498 348 if(tz==0) {oled.drawText(0,0,(FONT8X12)," RTC Clock Time (GMT)",oled.toRGB(255,0,0));}
star297 1:793dbd6d6498 349 if (tz==1) {oled.drawText(0,0,(FONT8X12)," RTC Clock Time (CET)",oled.toRGB(255,0,0));}
star297 1:793dbd6d6498 350 if (tz==2) {oled.drawText(0,0,(FONT8X12)," RTC Clock Time (EET)",oled.toRGB(255,0,0));}
star297 1:793dbd6d6498 351 if (tz==3) {oled.drawText(0,0,(FONT8X12)," RTC Clock Time (MSK)",oled.toRGB(255,0,0));}
star297 1:793dbd6d6498 352 oled.drawText(22,5,(FONT8X12)," DCF Time (CET)",oled.toRGB(255,255,0));
star297 1:793dbd6d6498 353 oled.setTextBackgroundType (TEXT_TRANSPARENT);
star297 1:793dbd6d6498 354 oled.drawTextButton(1, 270, 140,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(255,255,255)), 1, 1, " Back ");
star297 1:793dbd6d6498 355 oled.setTextBackgroundType (TEXT_OPAQUE);
star297 1:793dbd6d6498 356 draw_graph=0;DCFdrawgraph();
star297 1:793dbd6d6498 357 oled.drawLine(155,190,169,190, oled.toRGB(225, 255, 255));
star297 1:793dbd6d6498 358 oled.drawLine(169,190,169,203, oled.toRGB(225, 255, 255));
star297 1:793dbd6d6498 359 oled.drawLine(170,203,287,203, oled.toRGB(255,255,255));
star297 1:793dbd6d6498 360 oled.drawLine(287,190,287,203, oled.toRGB(225, 255, 255));
star297 1:793dbd6d6498 361 oled.drawLine(288,190,305,190, oled.toRGB(225, 255, 255));
star297 1:793dbd6d6498 362 oled.drawText(0,26,(FONT5X7)," 0 start min hour Dt dy mon year 60",oled.toRGB(255,0,0));
star297 1:793dbd6d6498 363 oled.setTouchArea(240,140,290,160);
star297 1:793dbd6d6498 364 start=0;sync=0;x=0;y=5;r=0;SignalStatus=0;laststart=2;loop=0;interrupt_counter = 0;dcf_sec=0;error_count=0;
star297 1:793dbd6d6498 365
star297 1:793dbd6d6498 366 Ticker50ms.attach(& dcfISR, .05);
star297 1:793dbd6d6498 367
star297 1:793dbd6d6498 368 while (IRQ==0) {
star297 1:793dbd6d6498 369 if (loop==0) {
star297 1:793dbd6d6498 370 DCFloop(); // Continuously get dcf time and Display data every second interrupted by the Ticker every 50ms
star297 1:793dbd6d6498 371 loop=1;}
star297 1:793dbd6d6498 372 }
star297 1:793dbd6d6498 373 oled.clear();
star297 1:793dbd6d6498 374 }
star297 1:793dbd6d6498 375
star297 1:793dbd6d6498 376 void DCFloop()
star297 1:793dbd6d6498 377 {
star297 1:793dbd6d6498 378 if (interrupt_counter == 0) {
star297 1:793dbd6d6498 379 if (start == 0) {dcf_sec=0;}
star297 1:793dbd6d6498 380 if (dcf_sec == 0){dcf_array[58] = 0;}
star297 1:793dbd6d6498 381 if (dcf_good==1 && dcf_sec==2) {DCF=1;RTCset();}
star297 1:793dbd6d6498 382 }
star297 1:793dbd6d6498 383
star297 1:793dbd6d6498 384 if (interrupt_counter == 1) {
star297 1:793dbd6d6498 385 oled.setFontSize(FONT12X16);
star297 1:793dbd6d6498 386 oled.locate(15,5);oled.setFontColor(oled.toRGB(255,255,255));
star297 1:793dbd6d6498 387 oled.printf("%02d:%02d:%02d", hour, minute, second);
star297 1:793dbd6d6498 388 oled.locate(3,13);oled.setFontColor(oled.toRGB(255,255,255));
star297 1:793dbd6d6498 389 oled.setFontSize(FONT12X16);oled.printf("%02d",dcf_sec);
star297 1:793dbd6d6498 390 }
star297 1:793dbd6d6498 391
star297 1:793dbd6d6498 392 if (interrupt_counter==2){
star297 1:793dbd6d6498 393 if (rtcset==0) {
star297 1:793dbd6d6498 394 oled.drawText(33,2,(FONT5X7),"RTC -- un-set -- ",oled.toRGB(255,0,0));}
star297 1:793dbd6d6498 395 if (rtcset==1) {
star297 1:793dbd6d6498 396 oled.drawText(33,2,(FONT5X7),"RTC *** set *** ",oled.toRGB(0,255,0));}
star297 1:793dbd6d6498 397 oled.setFontSize(FONT12X16);oled.locate(0,1);
star297 1:793dbd6d6498 398 oled.setFontColor(oled.toRGB(255,255,255));
star297 1:793dbd6d6498 399 RTCread();
star297 1:793dbd6d6498 400 oled.printf("%2d:%02d:%02d",RTChour,RTCminute,RTCsecond);
star297 1:793dbd6d6498 401 }
star297 1:793dbd6d6498 402
star297 1:793dbd6d6498 403 if (interrupt_counter == 4) {
star297 1:793dbd6d6498 404 if (dcf_sec > 59) {dcf_sec = 0;}
star297 1:793dbd6d6498 405 if (dcf_sec>20 && signal_error==1) {DCFbitmapdraw();DCFdrawgraph();start=0;signal_error=0;SignalStatus=5;}
star297 1:793dbd6d6498 406 if (dcf_sec == 57) {oled.drawText(36,7,(FONT8X12)," ",oled.toRGB(0,0,0));}
star297 1:793dbd6d6498 407 if (start == 0 && signal_error==0) {SignalStatus=0;}
star297 1:793dbd6d6498 408 }
star297 1:793dbd6d6498 409
star297 1:793dbd6d6498 410 if (interrupt_counter == 6 && dcf_sec > 0){
star297 1:793dbd6d6498 411 if (dcf_sec==1){DCFdrawgraph();SignalStatus = 1;}
star297 1:793dbd6d6498 412 oled.setPenSize(1); oled.drawRectangle(11, 229, (dcf_sec*5), 8, oled.toRGB(0,255,0));draw_graph=0;
star297 1:793dbd6d6498 413 if (signal_error==1) {DCFdrawgraph();signal_error=0;SignalStatus=5;}
star297 1:793dbd6d6498 414 }
star297 1:793dbd6d6498 415
star297 1:793dbd6d6498 416 if (interrupt_counter == 7){
star297 1:793dbd6d6498 417 DCFbitstatus();
star297 1:793dbd6d6498 418 if (dcf_sec == 21){SignalStatus=2;r = !r;}
star297 1:793dbd6d6498 419 if (dcf_sec > 20 && dcf_sec < 59 ) {DCFbitprint();}
star297 1:793dbd6d6498 420 }
star297 1:793dbd6d6498 421
star297 1:793dbd6d6498 422 if (interrupt_counter == 8){
star297 1:793dbd6d6498 423 if (start==1){dcf_array[dcf_sec]=dcf_status.DCFsample150;}
star297 1:793dbd6d6498 424 oled.setFontSize(FONT12X16);oled.locate(0,2);
star297 1:793dbd6d6498 425 oled.setFontColor(oled.toRGB(255,255,255));
star297 1:793dbd6d6498 426 oled.printf("%s %02d %s' 20%02d",weekDayName[RTCdayofweek],RTCdayofmonth,monthName[RTCmonth-1],RTCyear);
star297 1:793dbd6d6498 427 }
star297 1:793dbd6d6498 428
star297 1:793dbd6d6498 429 if (interrupt_counter == 10) {
star297 1:793dbd6d6498 430 oled.setFontSize(FONT8X12);oled.locate(23,8);oled.setFontColor(oled.toRGB(255,255,255));
star297 1:793dbd6d6498 431 oled.printf("%s %02d %s' 20%02d", weekDayName[dayofweek], dayofmonth, monthName[month-1], year);
star297 1:793dbd6d6498 432 if (summertime) oled.drawText(23,9,(FONT8X12),"Summer Time",oled.toRGB(255,128,0));
star297 1:793dbd6d6498 433 else oled.drawText(23,9,(FONT8X12),"Winter Time",oled.toRGB(0,255,255));
star297 1:793dbd6d6498 434 oled.drawText(23,10,(FONT8X12),leapSymbol[dcf_status.is_leap],oled.toRGB(0,255,160));
star297 1:793dbd6d6498 435 }
star297 1:793dbd6d6498 436
star297 1:793dbd6d6498 437 if (interrupt_counter == 11 & second == 1) {
star297 1:793dbd6d6498 438 oled.setFontSize(FONT5X7);oled.locate(34,5);
star297 1:793dbd6d6498 439 oled.setFontColor(oled.toRGB(255,255,255));
star297 1:793dbd6d6498 440 oled.printf("RTC set x %d", rtcset_times);
star297 1:793dbd6d6498 441 }
star297 1:793dbd6d6498 442
star297 1:793dbd6d6498 443 if (interrupt_counter == 12){
star297 1:793dbd6d6498 444 if (SignalStatus==0) {oled.drawText(26,20,(FONT5X7),statusText[SignalStatus],oled.toRGB(255,255,255));}
star297 1:793dbd6d6498 445 if (SignalStatus==1) {oled.drawText(26,20,(FONT5X7),statusText[SignalStatus],oled.toRGB(255,255,0));}
star297 1:793dbd6d6498 446 if (SignalStatus==2) {oled.drawText(26,20,(FONT5X7),statusText[SignalStatus],oled.toRGB(0,255,255));}
star297 1:793dbd6d6498 447 if (SignalStatus==3) {oled.drawText(26,20,(FONT5X7),statusText[SignalStatus],oled.toRGB(0,0,255));}
star297 1:793dbd6d6498 448 if (SignalStatus==4) {oled.drawText(26,20,(FONT5X7),statusText[SignalStatus],oled.toRGB(0,255,0));}
star297 1:793dbd6d6498 449 if (SignalStatus==5) {
star297 1:793dbd6d6498 450 oled.drawText(26,20,(FONT5X7),statusText[SignalStatus],oled.toRGB(255,0,0));
star297 1:793dbd6d6498 451 oled.drawText(36,7,(FONT8X12)," ",oled.toRGB(0,0,0));
star297 1:793dbd6d6498 452 start=0;SignalStatus=0;sync=0;
star297 1:793dbd6d6498 453 }
star297 1:793dbd6d6498 454 }
star297 1:793dbd6d6498 455
star297 1:793dbd6d6498 456 if (interrupt_counter==13){
star297 1:793dbd6d6498 457 if (start==0 && laststart != start) {oled.drawText(26,18,(FONT5X7),("No Sync"),oled.toRGB(255,0,0));laststart=start;}
star297 1:793dbd6d6498 458 if (start==1 && laststart != start) {oled.drawText(26,18,(FONT5X7),("In Sync"),oled.toRGB(0,255,0));laststart=start;}
star297 1:793dbd6d6498 459 }
star297 0:94bf5ec759da 460
star297 1:793dbd6d6498 461 if (interrupt_counter>13){
star297 1:793dbd6d6498 462 oled.getTouch(&xbuffer,&ybuffer);
star297 1:793dbd6d6498 463 if (display==0){
star297 1:793dbd6d6498 464 if((xbuffer>2 && xbuffer<318) && (ybuffer>2 && ybuffer<238)){
star297 1:793dbd6d6498 465 oled.displayControl(0x01,0x01);display=1;
star297 1:793dbd6d6498 466 oled.resetTouchArea();}}
star297 1:793dbd6d6498 467 if((xbuffer>240 && xbuffer<290) && (ybuffer>140 && ybuffer<160)){
star297 1:793dbd6d6498 468 SignalIn.rise(NULL);Ticker50ms.detach();IRQ=1;}
star297 1:793dbd6d6498 469 }
star297 1:793dbd6d6498 470
star297 1:793dbd6d6498 471 if (interrupt_counter == 19){DCFbitstatus();}
star297 1:793dbd6d6498 472
star297 1:793dbd6d6498 473 }
star297 1:793dbd6d6498 474
star297 1:793dbd6d6498 475 void DCFtestparity()
star297 1:793dbd6d6498 476 {
star297 1:793dbd6d6498 477 rtcset=0;DCFparitycalc();
star297 1:793dbd6d6498 478 paritycheck= testu or testm or testdmy;
star297 1:793dbd6d6498 479 if (p_year>99) paritycheck=1;
star297 1:793dbd6d6498 480 if (p_month>12) paritycheck=1;
star297 1:793dbd6d6498 481 if (p_dayofmonth>31) paritycheck=1;
star297 1:793dbd6d6498 482 if (p_hour>23) paritycheck=1;
star297 1:793dbd6d6498 483 if (p_minute>59) paritycheck=1;
star297 1:793dbd6d6498 484 if (paritycheck) {dcf_good=0;SignalStatus = 5;} // bad parity
star297 1:793dbd6d6498 485 else {dcf_good=1;SignalStatus = 4;} // good parity
star297 1:793dbd6d6498 486 }
star297 1:793dbd6d6498 487
star297 1:793dbd6d6498 488 void DCFsetTime()
star297 1:793dbd6d6498 489 {
star297 1:793dbd6d6498 490 second = dcf_sec;
star297 1:793dbd6d6498 491 minute=p_minute;
star297 1:793dbd6d6498 492 hour=p_hour;
star297 1:793dbd6d6498 493 dayofweek=p_dayofweek;
star297 1:793dbd6d6498 494 dayofmonth=p_dayofmonth;
star297 1:793dbd6d6498 495 month=p_month;
star297 1:793dbd6d6498 496 year=p_year;
star297 1:793dbd6d6498 497 oled.drawText(36,7,(FONT8X12),"*",oled.toRGB(0,255,0));
star297 1:793dbd6d6498 498 }
star297 1:793dbd6d6498 499 void DCFbitprint()
star297 1:793dbd6d6498 500 {
star297 1:793dbd6d6498 501 if (r==1) {oled.setFontColor(oled.toRGB(0,0,255));} // alternate bit draw colour
star297 1:793dbd6d6498 502 else {oled.setFontColor(oled.toRGB(255,255,255));}
star297 1:793dbd6d6498 503 oled.setFontSize(FONT8X12);
star297 1:793dbd6d6498 504 if (dcf_sec==21){x=5;y=7;}
star297 1:793dbd6d6498 505 if (dcf_sec==28){x=5;y=15;oled.locate(5,15);oled.printf(" ");}
star297 1:793dbd6d6498 506 if (dcf_sec==29){x=7;y=7;}
star297 1:793dbd6d6498 507 if (dcf_sec==35){x=7;y=15;}
star297 1:793dbd6d6498 508 if (dcf_sec==36){x=9;y=7;}
star297 1:793dbd6d6498 509 if (dcf_sec==42){x=11;y=7;}
star297 1:793dbd6d6498 510 if (dcf_sec==45){x=13;y=7;}
star297 1:793dbd6d6498 511 if (dcf_sec==50){x=15;y=7;}
star297 1:793dbd6d6498 512 oled.locate(x,y);
star297 1:793dbd6d6498 513 oled.printf("%d",dcf_status.DCFsample150);
star297 1:793dbd6d6498 514 y++;
star297 1:793dbd6d6498 515 }
star297 1:793dbd6d6498 516
star297 1:793dbd6d6498 517 void DCFbitmapdraw()
star297 1:793dbd6d6498 518 {
star297 1:793dbd6d6498 519 x=2,y=6;
star297 1:793dbd6d6498 520 oled.drawText(x-2,y,(FONT8X12)," Dcf M H D d M Y",oled.toRGB(255,255,0));
star297 1:793dbd6d6498 521 oled.drawText(x,y+1,(FONT8X12)," 1 i o a a o e",oled.toRGB(255,255,0));
star297 1:793dbd6d6498 522 oled.drawText(x,y+2,(FONT8X12)," 2 n u t y n a",oled.toRGB(255,255,0));
star297 1:793dbd6d6498 523 oled.drawText(x,y+3,(FONT8X12)," 4 u r e t r",oled.toRGB(255,255,0));
star297 1:793dbd6d6498 524 oled.drawText(x,y+4,(FONT8X12)," 8 t h ",oled.toRGB(255,255,0));
star297 1:793dbd6d6498 525 oled.drawText(x,y+5,(FONT8X12),"10 e ",oled.toRGB(255,255,0));
star297 1:793dbd6d6498 526 oled.drawText(x,y+6,(FONT8X12),"20 ",oled.toRGB(255,255,0));
star297 1:793dbd6d6498 527 oled.drawText(x,y+7,(FONT8X12),"40 ",oled.toRGB(255,255,0));
star297 1:793dbd6d6498 528 oled.drawText(x,y+8,(FONT8X12),"80 ",oled.toRGB(255,255,0));
star297 1:793dbd6d6498 529 oled.drawText(x,y+9,(FONT8X12)," P arity ",oled.toRGB(255,255,0));
star297 1:793dbd6d6498 530 oled.drawLine(8,83,135,83, oled.toRGB(0, 255, 0));
star297 1:793dbd6d6498 531 oled.drawLine(35,70,35,195, oled.toRGB(0, 255, 0));
star297 1:793dbd6d6498 532 }
star297 1:793dbd6d6498 533 void DCFdrawgraph()
star297 1:793dbd6d6498 534 {
star297 1:793dbd6d6498 535 if (draw_graph==0){
star297 1:793dbd6d6498 536 oled.setPenSize(0);
star297 1:793dbd6d6498 537 oled.drawRectangle(10,228,300,8,oled.toRGB(0,0,0));
star297 1:793dbd6d6498 538 oled.setPenSize(1);
star297 1:793dbd6d6498 539 oled.drawRectangle(10,227,302,10,oled.toRGB(255,255,255));
star297 1:793dbd6d6498 540 oled.drawLine(10,220,10,237,oled.toRGB(255,255,255));
star297 1:793dbd6d6498 541 oled.drawLine(312,220,312,237,oled.toRGB(255,255,255));
star297 1:793dbd6d6498 542 oled.drawLine(111,220,111,237,oled.toRGB(255,255,255)); //start
star297 1:793dbd6d6498 543 oled.drawLine(156,220,156,237,oled.toRGB(225,255,255)); //min
star297 1:793dbd6d6498 544 oled.drawLine(186,220,186,237,oled.toRGB(255,255,225)); //hour
star297 1:793dbd6d6498 545 oled.drawLine(216,220,216,237,oled.toRGB(225,255,225)); //date
star297 1:793dbd6d6498 546 oled.drawLine(231,220,231,237, oled.toRGB(225, 255, 225));//day
star297 1:793dbd6d6498 547 oled.drawLine(256,220,256,237, oled.toRGB(225, 255, 225));//month
star297 1:793dbd6d6498 548 oled.drawLine(301,220,301,237, oled.toRGB(225, 255, 225));//year
star297 1:793dbd6d6498 549 draw_graph=1;
star297 1:793dbd6d6498 550 }
star297 1:793dbd6d6498 551 }
star297 1:793dbd6d6498 552 void DCFbitstatus()
star297 1:793dbd6d6498 553 {
star297 1:793dbd6d6498 554 oled.locate(29,22);
star297 1:793dbd6d6498 555 oled.setFontSize(FONT5X7);
star297 1:793dbd6d6498 556 oled.setFontColor(oled.toRGB(255,0,0));
star297 1:793dbd6d6498 557 oled.printf("%d %d %d %d %d",dcf_status.DCFsample50,dcf_status.DCFsample150,dcf_status.DCFsample300,dcf_status.DCFsample500,dcf_status.DCFsample600);
star297 1:793dbd6d6498 558 oled.setPenSize(0);
star297 1:793dbd6d6498 559 if (!dcf_status.DCFsample50) {oled.drawRectangle(170,190,11,12, oled.toRGB(0,0,0));}
star297 1:793dbd6d6498 560 else {oled.drawRectangle(170,190,11,12, oled.toRGB(255,255,255));}
star297 1:793dbd6d6498 561 if (!dcf_status.DCFsample150) {oled.drawRectangle(182,190,11,12, oled.toRGB(0,0,0));}
star297 1:793dbd6d6498 562 else {oled.drawRectangle(182,190,11,12, oled.toRGB(255,255,255));}
star297 1:793dbd6d6498 563 if (!dcf_status.DCFsample300) {oled.drawRectangle(194,190,11,12, oled.toRGB(0,0,0));}
star297 1:793dbd6d6498 564 else {oled.drawRectangle(194,190,11,12, oled.toRGB(255,255,255));}
star297 1:793dbd6d6498 565 if (!dcf_status.DCFsample500) {oled.drawRectangle(206,190,23,12, oled.toRGB(0,0,0));}
star297 1:793dbd6d6498 566 else {oled.drawRectangle(206,190,23,12, oled.toRGB(255,255,255));}
star297 1:793dbd6d6498 567 if (!dcf_status.DCFsample600) {oled.drawRectangle(230,190,56,12, oled.toRGB(0,0,0));}
star297 1:793dbd6d6498 568 else {oled.drawRectangle(230,190,56,12, oled.toRGB(0,0,255));}
star297 1:793dbd6d6498 569 }
star297 1:793dbd6d6498 570
star297 1:793dbd6d6498 571 void DCFparitycalc()
star297 1:793dbd6d6498 572 {
star297 1:793dbd6d6498 573 //calculate summer/winter time----------------------------------------------------------------------
star297 1:793dbd6d6498 574 summertime = dcf_array[17] & 1;
star297 1:793dbd6d6498 575 //calculate hour--------------------------------------------------------------------------------------
star297 1:793dbd6d6498 576 hourh = dcf_array[34] * 20 + dcf_array[33] * 10;
star297 1:793dbd6d6498 577 hourl = dcf_array[32] * 8 + dcf_array[31] * 4 + dcf_array[30] * 2 + dcf_array[29] * 1;
star297 1:793dbd6d6498 578 p_hour = hourh + hourl;
star297 1:793dbd6d6498 579 //calculate minutes------------------------------------------------------------------------------------
star297 1:793dbd6d6498 580 minl = dcf_array[24] * 8 + dcf_array[23] * 4 + dcf_array[22] * 2 + dcf_array[21] * 1;
star297 1:793dbd6d6498 581 minh = dcf_array[27] * 40 + dcf_array[26] * 20 +dcf_array[25] * 10;
star297 1:793dbd6d6498 582 p_minute = minh + minl;
star297 1:793dbd6d6498 583 //calculate day of week--------------------------------------------------------------------------------
star297 1:793dbd6d6498 584 p_dayofweek = dcf_array[44] * 4 +dcf_array[43] * 2 + dcf_array[42] * 1;
star297 1:793dbd6d6498 585 //calculate day----------------------------------------------------------------------------------------
star297 1:793dbd6d6498 586 dayl = dcf_array[39] * 8 + dcf_array[38] * 4 + dcf_array[37] * 2 + dcf_array[36] * 1;
star297 1:793dbd6d6498 587 dayh = dcf_array[41] * 20 + dcf_array[40] * 10;
star297 1:793dbd6d6498 588 p_dayofmonth=dayh+dayl;
star297 1:793dbd6d6498 589 //calculate month--------------------------------------------------------------------------------------
star297 1:793dbd6d6498 590 monthh = dcf_array[49] * 10;
star297 1:793dbd6d6498 591 monthl = dcf_array[48] * 8 + dcf_array[47] * 4 + dcf_array[46] * 2 + dcf_array[45] * 1;
star297 1:793dbd6d6498 592 p_month = monthh +monthl;
star297 1:793dbd6d6498 593 //calculate year---------------------------------------------------------------------------------------
star297 1:793dbd6d6498 594 yearh = dcf_array[57] * 80 + dcf_array[56] * 40 + dcf_array[55] * 20 + dcf_array[54] * 10;
star297 1:793dbd6d6498 595 yearl = dcf_array[53] * 8 +dcf_array[52] * 4 + dcf_array[51] * 2 + dcf_array[50] * 1;
star297 1:793dbd6d6498 596 p_year = yearh+yearl;
star297 1:793dbd6d6498 597 //calculate parity
star297 1:793dbd6d6498 598 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:793dbd6d6498 599 parityu =dcf_array[29] + dcf_array[30] + dcf_array[31] + dcf_array[32] + dcf_array[33] + dcf_array[34] + dcf_array[35];
star297 1:793dbd6d6498 600 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:793dbd6d6498 601 //test parity------------------------------
star297 1:793dbd6d6498 602 testu=parityu & 1;
star297 1:793dbd6d6498 603 testm=paritym & 1;
star297 1:793dbd6d6498 604 testdmy=paritydmy & 1;
star297 1:793dbd6d6498 605 }
star297 1:793dbd6d6498 606
star297 1:793dbd6d6498 607 void dcfIRQ(void)
star297 1:793dbd6d6498 608 {
star297 1:793dbd6d6498 609 if (sync==0){
star297 1:793dbd6d6498 610 interrupt_counter = 0;sync=1;dcf_sec=0;error_count=0;
star297 1:793dbd6d6498 611 Ticker50ms.attach(& dcfISR, .05);
star297 1:793dbd6d6498 612 }
star297 1:793dbd6d6498 613 }
star297 1:793dbd6d6498 614
star297 1:793dbd6d6498 615 void dcfISR() //This is the interrupt service routine (ISR) that is called every 50ms
star297 1:793dbd6d6498 616 {
star297 1:793dbd6d6498 617 interrupt_counter++;loop=0;
star297 1:793dbd6d6498 618
star297 1:793dbd6d6498 619 SignalLED = SignalIn; // Show dcfSignal state on LED
star297 1:793dbd6d6498 620
star297 1:793dbd6d6498 621 if (interrupt_counter == 20) { // 50mS x 20 = 1000mS = 1 Second
star297 1:793dbd6d6498 622 interrupt_counter = 0;second++;dcf_sec++;
star297 1:793dbd6d6498 623 if (start==0) dcf_sec=0;
star297 1:793dbd6d6498 624 }
star297 1:793dbd6d6498 625 if (interrupt_counter == 0){
star297 1:793dbd6d6498 626 if (dcf_sec==58) {SignalStatus = 3;}
star297 1:793dbd6d6498 627 if (dcf_sec==59) {DCFtestparity();}
star297 1:793dbd6d6498 628 if (dcf_good==1 && dcf_sec==1) {DCFsetTime();}
star297 1:793dbd6d6498 629 }
star297 1:793dbd6d6498 630 if (second >= 60) {++minute;second -=60;}
star297 1:793dbd6d6498 631 if (minute >= 60) {++hour;minute-=60;}
star297 1:793dbd6d6498 632 if (hour >= 24) {hour -=24;++dayofweek;++dayofmonth;}
star297 1:793dbd6d6498 633 if (dayofweek > 6) dayofweek = 0;
star297 1:793dbd6d6498 634 if (dayofmonth > maxDay(year, month)) {dayofmonth = 1;month++;}
star297 1:793dbd6d6498 635 if (month > 12) {month = 1;year++;}
star297 1:793dbd6d6498 636 if (year > 99) year = 1;
star297 1:793dbd6d6498 637
star297 1:793dbd6d6498 638 switch (interrupt_counter) {
star297 1:793dbd6d6498 639 case 1: { // 50mS after start of second pulse
star297 1:793dbd6d6498 640 dcf_status.DCFsample50 = (SignalIn);
star297 1:793dbd6d6498 641 break;}
star297 1:793dbd6d6498 642 case 3: { // 150mS after start of second pulse (bit "1" dcf Data)
star297 1:793dbd6d6498 643 dcf_status.DCFsample150 = (SignalIn);
star297 1:793dbd6d6498 644 break;}
star297 1:793dbd6d6498 645 case 6: { // 300mS after start of second (signal error if true)
star297 1:793dbd6d6498 646 dcf_status.DCFsample300 = (SignalIn);
star297 1:793dbd6d6498 647 if (SignalIn) {dcf_error = 1;}
star297 1:793dbd6d6498 648 break;}
star297 1:793dbd6d6498 649 case 10: { // 500mS after start of second (signal error if true)
star297 1:793dbd6d6498 650 dcf_status.DCFsample500 = (SignalIn);
star297 1:793dbd6d6498 651 if (SignalIn) {dcf_error = 1;}
star297 1:793dbd6d6498 652 break;}
star297 1:793dbd6d6498 653 case 12: { // 600mS after start of second (signal error if true)
star297 1:793dbd6d6498 654 dcf_status.DCFsample600 = (SignalIn);
star297 1:793dbd6d6498 655 if (SignalIn) {dcf_error = 1;}
star297 1:793dbd6d6498 656 break;}
star297 1:793dbd6d6498 657 }
star297 1:793dbd6d6498 658 if (dcf_status.DCFsample50==0 && dcf_sec<58){sync=0;}
star297 1:793dbd6d6498 659
star297 1:793dbd6d6498 660 if (interrupt_counter==1){
star297 1:793dbd6d6498 661 if (SignalIn){nosignal=1;}
star297 1:793dbd6d6498 662 else nosignal++;
star297 1:793dbd6d6498 663 if (nosignal>5){nosignal=2; SignalStatus = 5;signal_error=1;}
star297 1:793dbd6d6498 664 }
star297 0:94bf5ec759da 665
star297 1:793dbd6d6498 666 if (interrupt_counter==15){
star297 1:793dbd6d6498 667 if (!dcf_status.DCFsample150 && !dcf_status.DCFsample50) {sync=0;start=1;}
star297 1:793dbd6d6498 668 }
star297 1:793dbd6d6498 669 if (interrupt_counter==18){
star297 1:793dbd6d6498 670 if (dcf_error==1) {error_count++;dcf_error=0;}
star297 1:793dbd6d6498 671 if (error_count > 3 && sync==1) {error_count = 0;signal_error=1;}
star297 1:793dbd6d6498 672 }
star297 0:94bf5ec759da 673
star297 1:793dbd6d6498 674 } // End of ISR
star297 1:793dbd6d6498 675