Demo program for the Oled display
main.cpp@2:1eac3ea8c6e8, 2015-01-09 (annotated)
- Committer:
- star297
- Date:
- Fri Jan 09 18:21:01 2015 +0000
- Revision:
- 2:1eac3ea8c6e8
- Parent:
- 1:793dbd6d6498
- Child:
- 3:1fb597da3fdf
Updated DCF code
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:1eac3ea8c6e8 | 6 | InterruptIn dcfSignalIn(PTC0); // 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 | 2:1eac3ea8c6e8 | 122 | oled.printf("printf time %3.2f mS",T2.read()*1000);T2.reset(); |
star297 | 2:1eac3ea8c6e8 | 123 | oled.locate (4,12); |
star297 | 2:1eac3ea8c6e8 | 124 | oled.printf("%d",seconds); |
star297 | 1:793dbd6d6498 | 125 | } |
star297 | 1:793dbd6d6498 | 126 | T3.reset(); |
star297 | 1:793dbd6d6498 | 127 | while(1){ |
star297 | 1:793dbd6d6498 | 128 | IRQ=0; |
star297 | 1:793dbd6d6498 | 129 | SignalLED=1; |
star297 | 1:793dbd6d6498 | 130 | RTCclock(); |
star297 | 1:793dbd6d6498 | 131 | } |
star297 | 1:793dbd6d6498 | 132 | |
star297 | 1:793dbd6d6498 | 133 | } |
star297 | 1:793dbd6d6498 | 134 | |
star297 | 1:793dbd6d6498 | 135 | void RTCclock() |
star297 | 1:793dbd6d6498 | 136 | { |
star297 | 1:793dbd6d6498 | 137 | while(IRQ==0){ |
star297 | 1:793dbd6d6498 | 138 | oled.disableTouch();oled.clear(); |
star297 | 1:793dbd6d6498 | 139 | oled.setTextBackgroundType (TEXT_TRANSPARENT); |
star297 | 1:793dbd6d6498 | 140 | RTCclockdraw(); |
star297 | 1:793dbd6d6498 | 141 | oled.drawTextButton(1, 200, 210,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "DCF Clock"); |
star297 | 1:793dbd6d6498 | 142 | oled.drawTextButton(1, 252, 185,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "Set RTC"); |
star297 | 1:793dbd6d6498 | 143 | oled.setTextBackgroundType (TEXT_OPAQUE); |
star297 | 2:1eac3ea8c6e8 | 144 | oled.drawText(0,0,(FONT12X16),"RTC Clock",oled.toRGB(0,255,0)); |
star297 | 2:1eac3ea8c6e8 | 145 | oled.drawText(38,7,(FONT5X7),"Touch position",oled.toRGB(255,0,0)); |
star297 | 2:1eac3ea8c6e8 | 146 | oled.enableTouch();oled.resetTouchArea(); |
star297 | 2:1eac3ea8c6e8 | 147 | T1.start(); |
star297 | 1:793dbd6d6498 | 148 | |
star297 | 1:793dbd6d6498 | 149 | while(IRQ==0){ |
star297 | 1:793dbd6d6498 | 150 | oled.setFontSize(FONT12X16);oled.locate(0,1); |
star297 | 1:793dbd6d6498 | 151 | oled.setFontColor(oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 152 | time_t seconds = time(NULL); |
star297 | 2:1eac3ea8c6e8 | 153 | strftime(timebuf, 32, "%I:%M:%S.", localtime(&seconds)); |
star297 | 1:793dbd6d6498 | 154 | strftime(datebuf, 32, "%a %d %b %Y ", localtime(&seconds)); |
star297 | 2:1eac3ea8c6e8 | 155 | oled.drawText(11,0,(FONT12X16),timebuf,oled.toRGB(255,255,255)); |
star297 | 2:1eac3ea8c6e8 | 156 | oled.drawText(11,1,(FONT12X16),datebuf,oled.toRGB(255,255,255)); |
star297 | 2:1eac3ea8c6e8 | 157 | |
star297 | 2:1eac3ea8c6e8 | 158 | if (seconds != nextsec){T1.reset();RTCclockupdate();nextsec=seconds;} |
star297 | 2:1eac3ea8c6e8 | 159 | oled.locate(20,0); |
star297 | 2:1eac3ea8c6e8 | 160 | oled.printf("%02.f ",T1.read()*100); |
star297 | 2:1eac3ea8c6e8 | 161 | oled.getTouch(&xbuffer,&ybuffer); |
star297 | 1:793dbd6d6498 | 162 | |
star297 | 2:1eac3ea8c6e8 | 163 | oled.setFontSize(FONT5X7);oled.locate(40,9); // this indicates touch position |
star297 | 2:1eac3ea8c6e8 | 164 | oled.printf("X %03d Y %03d ",xbuffer,ybuffer); // can be removed |
star297 | 1:793dbd6d6498 | 165 | |
star297 | 1:793dbd6d6498 | 166 | if((xbuffer>195 && xbuffer<300) && (ybuffer>205 && ybuffer<220)){DCFclock();} |
star297 | 1:793dbd6d6498 | 167 | if((xbuffer>240 && xbuffer<300) && (ybuffer>182 && ybuffer<200)){RTCsetclock();} |
star297 | 1:793dbd6d6498 | 168 | } |
star297 | 1:793dbd6d6498 | 169 | } |
star297 | 1:793dbd6d6498 | 170 | } |
star297 | 1:793dbd6d6498 | 171 | |
star297 | 1:793dbd6d6498 | 172 | void RTCclockdraw() |
star297 | 1:793dbd6d6498 | 173 | { |
star297 | 1:793dbd6d6498 | 174 | (x)=0; |
star297 | 1:793dbd6d6498 | 175 | while ((x)<60){ |
star297 | 1:793dbd6d6498 | 176 | x++;angleS=(x)*6; // clock minute markers in angle form |
star297 | 1:793dbd6d6498 | 177 | xs=(sin((angleS*3.14)/180)) * 90; // X component of markers |
star297 | 1:793dbd6d6498 | 178 | ys=(cos((angleS*3.14)/180)) * 90; // Y component of markers |
star297 | 1:793dbd6d6498 | 179 | oled.drawLine(clkx,clky,clkx+xs,clky-ys,oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 180 | } |
star297 | 1:793dbd6d6498 | 181 | (x)=0; |
star297 | 1:793dbd6d6498 | 182 | while ((x)<13){ |
star297 | 1:793dbd6d6498 | 183 | x++;angleS=(x)*30; // clock hour markers in angle form |
star297 | 1:793dbd6d6498 | 184 | xs=(sin((angleS*3.14)/180)) * 90; // X component of markers |
star297 | 1:793dbd6d6498 | 185 | ys=(cos((angleS*3.14)/180)) * 90; // Y component of markers |
star297 | 1:793dbd6d6498 | 186 | oled.drawLine(clkx,clky,clkx+xs,clky-ys,oled.toRGB(0,255,255)); |
star297 | 1:793dbd6d6498 | 187 | if (x==1) oled.drawTextGraphic(numposx +(xs+8),numposy + (ys+8), FONT5X7, "5", 1, 1, oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 188 | if (x==2) oled.drawTextGraphic(numposx +(xs+10),numposy + (ys+4), FONT5X7, "4", 1, 1, oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 189 | if (x==3) oled.drawTextGraphic(numposx +(xs+10),numposy + (ys), FONT5X7, "3", 1, 1, oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 190 | if (x==4) oled.drawTextGraphic(numposx +(xs+10),numposy + (ys-4), FONT5X7, "2", 1, 1, oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 191 | if (x==5) oled.drawTextGraphic(numposx +(xs+8),numposy + (ys-8), FONT5X7, "1", 1, 1, oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 192 | if (x==6) oled.drawTextGraphic(numposx +(xs),numposy + (ys-8), FONT5X7, "12", 1, 1, oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 193 | if (x==7) oled.drawTextGraphic(numposx +(xs-4),numposy + (ys-8), FONT5X7, "11", 1, 1, oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 194 | if (x==8) oled.drawTextGraphic(numposx +(xs-10),numposy + (ys-4), FONT5X7, "10", 1, 1, oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 195 | if (x==9) oled.drawTextGraphic(numposx +(xs-4),numposy + (ys), FONT5X7, "9", 1, 1, oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 196 | if (x==10) oled.drawTextGraphic(numposx +(xs-4),numposy + (ys+4), FONT5X7, "8", 1, 1, oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 197 | if (x==11) oled.drawTextGraphic(numposx +(xs),numposy + (ys+8), FONT5X7, "7", 1, 1, oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 198 | if (x==12) oled.drawTextGraphic(numposx +(xs+3),numposy + (ys+8), FONT5X7, "6", 1, 1, oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 199 | } |
star297 | 1:793dbd6d6498 | 200 | oled.setPenSize(0); |
star297 | 1:793dbd6d6498 | 201 | oled.drawCircle(clkx,clky,80,oled.toRGB(0,0,0)); |
star297 | 1:793dbd6d6498 | 202 | oled.setPenSize(1); |
star297 | 1:793dbd6d6498 | 203 | oled.drawCircle(clkx,clky,80,oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 204 | oled.drawCircle(clkx,clky,90,oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 205 | (x)=0; |
star297 | 1:793dbd6d6498 | 206 | } |
star297 | 1:793dbd6d6498 | 207 | |
star297 | 1:793dbd6d6498 | 208 | void RTCsetclock() |
star297 | 1:793dbd6d6498 | 209 | { |
star297 | 1:793dbd6d6498 | 210 | oled.disableTouch();oled.clear(); |
star297 | 1:793dbd6d6498 | 211 | oled.drawText(0,0,(FONT12X16)," --Manual set RTC Time--",oled.toRGB(0,255,0)); |
star297 | 1:793dbd6d6498 | 212 | oled.setTextBackgroundType (TEXT_TRANSPARENT); |
star297 | 1:793dbd6d6498 | 213 | oled.drawTextButton(1, 265, 200,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(255,255,255)), 1, 1, " Back "); |
star297 | 1:793dbd6d6498 | 214 | oled.drawTextButton(1, 10, 200,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " Reset RTC "); |
star297 | 1:793dbd6d6498 | 215 | oled.drawTextButton(1, 120, 200,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " Set RTC "); |
star297 | 1:793dbd6d6498 | 216 | oled.drawTextButton(1, 16, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "+"); |
star297 | 1:793dbd6d6498 | 217 | oled.drawTextButton(1, 16, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "-"); |
star297 | 1:793dbd6d6498 | 218 | oled.drawTextButton(1, 52, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "+"); |
star297 | 1:793dbd6d6498 | 219 | oled.drawTextButton(1, 52, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "-"); |
star297 | 1:793dbd6d6498 | 220 | oled.drawTextButton(1, 88, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "+"); |
star297 | 2:1eac3ea8c6e8 | 221 | oled.drawTextButton(1, 88, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "-"); |
star297 | 1:793dbd6d6498 | 222 | oled.drawTextButton(1, 174, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "+"); |
star297 | 1:793dbd6d6498 | 223 | oled.drawTextButton(1, 174, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "-"); |
star297 | 1:793dbd6d6498 | 224 | oled.drawTextButton(1, 208, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " + "); |
star297 | 1:793dbd6d6498 | 225 | oled.drawTextButton(1, 208, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " - "); |
star297 | 1:793dbd6d6498 | 226 | oled.drawTextButton(1, 270, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " + "); |
star297 | 1:793dbd6d6498 | 227 | oled.drawTextButton(1, 270, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " - "); |
star297 | 1:793dbd6d6498 | 228 | oled.setTextBackgroundType (TEXT_OPAQUE); |
star297 | 2:1eac3ea8c6e8 | 229 | oled.setFontSize(FONT8X12);oled.locate (6,14); |
star297 | 2:1eac3ea8c6e8 | 230 | oled.setFontColor(oled.toRGB(255,255,255)); |
star297 | 2:1eac3ea8c6e8 | 231 | time_t seconds = time(NULL); |
star297 | 2:1eac3ea8c6e8 | 232 | oled.printf("time_t = %d seconds",seconds); |
star297 | 1:793dbd6d6498 | 233 | RTCread(); |
star297 | 1:793dbd6d6498 | 234 | second=RTCsecond;minute=RTCminute;hour=RTChour;dayofweek=RTCdayofweek;dayofmonth=RTCdayofmonth;month=RTCmonth;year=RTCyear; |
star297 | 1:793dbd6d6498 | 235 | |
star297 | 2:1eac3ea8c6e8 | 236 | while(IRQ==0){ |
star297 | 1:793dbd6d6498 | 237 | oled.enableTouch(); |
star297 | 1:793dbd6d6498 | 238 | time_t seconds = time(NULL); |
star297 | 2:1eac3ea8c6e8 | 239 | strftime(timebuf, 26, "%H:%M:%S", localtime(&seconds)); |
star297 | 2:1eac3ea8c6e8 | 240 | strftime(datebuf, 26, "%a %d %b' %Y", localtime(&seconds)); |
star297 | 2:1eac3ea8c6e8 | 241 | oled.drawText(1,2,(FONT12X16),timebuf,oled.toRGB(255,255,0)); |
star297 | 2:1eac3ea8c6e8 | 242 | oled.drawText(10,2,(FONT12X16),datebuf,oled.toRGB(255,255,0)); |
star297 | 2:1eac3ea8c6e8 | 243 | oled.setFontSize(FONT8X12);oled.locate (6,5); |
star297 | 2:1eac3ea8c6e8 | 244 | oled.setFontColor(oled.toRGB(255,255,255)); |
star297 | 2:1eac3ea8c6e8 | 245 | oled.printf("time_t = %d seconds",seconds); |
star297 | 1:793dbd6d6498 | 246 | |
star297 | 1:793dbd6d6498 | 247 | oled.getTouch(&xbuffer,&ybuffer); |
star297 | 2:1eac3ea8c6e8 | 248 | if((xbuffer>240 && xbuffer<290) && (ybuffer>190 && ybuffer<210)){IRQ=1;} |
star297 | 2:1eac3ea8c6e8 | 249 | if((xbuffer>20 && xbuffer<109) && (ybuffer>190 && ybuffer<210)){ |
star297 | 2:1eac3ea8c6e8 | 250 | set_time(1420070400);time_t seconds = time(NULL);RTCread(); |
star297 | 1:793dbd6d6498 | 251 | second=RTCsecond;minute=RTCminute;hour=RTChour;dayofweek=RTCdayofweek;dayofmonth=RTCdayofmonth;month=RTCmonth;year=RTCyear; |
star297 | 2:1eac3ea8c6e8 | 252 | oled.setFontSize(FONT8X12);oled.locate (6,14); |
star297 | 2:1eac3ea8c6e8 | 253 | oled.setFontColor(oled.toRGB(255,255,255)); |
star297 | 2:1eac3ea8c6e8 | 254 | oled.printf("time_t = %d seconds",seconds); |
star297 | 2:1eac3ea8c6e8 | 255 | } |
star297 | 2:1eac3ea8c6e8 | 256 | if((xbuffer>120 && xbuffer<195) && (ybuffer>195 && ybuffer<210)){RTCset();time_t seconds = time(NULL);RTCread(); |
star297 | 2:1eac3ea8c6e8 | 257 | second=RTCsecond;minute=RTCminute;hour=RTChour;dayofweek=RTCdayofweek;dayofmonth=RTCdayofmonth;month=RTCmonth;year=RTCyear; |
star297 | 2:1eac3ea8c6e8 | 258 | oled.setFontSize(FONT8X12);oled.locate (6,14); |
star297 | 2:1eac3ea8c6e8 | 259 | oled.setFontColor(oled.toRGB(255,255,255)); |
star297 | 2:1eac3ea8c6e8 | 260 | oled.printf("time_t = %d seconds",seconds); |
star297 | 1:793dbd6d6498 | 261 | } |
star297 | 1:793dbd6d6498 | 262 | |
star297 | 1:793dbd6d6498 | 263 | if((xbuffer>25 && xbuffer<40) && (ybuffer>124 && ybuffer<140)){hour++;} |
star297 | 1:793dbd6d6498 | 264 | if((xbuffer>25 && xbuffer<40) && (ybuffer>146 && ybuffer<160)){hour--;} |
star297 | 1:793dbd6d6498 | 265 | if((xbuffer>58 && xbuffer<74) && (ybuffer>124 && ybuffer<140)){minute++;} |
star297 | 1:793dbd6d6498 | 266 | if((xbuffer>58 && xbuffer<74) && (ybuffer>146 && ybuffer<160)){minute--;} |
star297 | 1:793dbd6d6498 | 267 | if((xbuffer>90 && xbuffer<105) && (ybuffer>124 && ybuffer<140)){second++;} |
star297 | 1:793dbd6d6498 | 268 | if((xbuffer>90 && xbuffer<105) && (ybuffer>146 && ybuffer<160)){second--;} |
star297 | 1:793dbd6d6498 | 269 | if((xbuffer>170 && xbuffer<186) && (ybuffer>124 && ybuffer<140)){dayofmonth++;} |
star297 | 1:793dbd6d6498 | 270 | if((xbuffer>170 && xbuffer<186) && (ybuffer>146 && ybuffer<160)){dayofmonth--;} |
star297 | 1:793dbd6d6498 | 271 | if((xbuffer>200 && xbuffer<230) && (ybuffer>124 && ybuffer<140)){month++;} |
star297 | 1:793dbd6d6498 | 272 | if((xbuffer>200 && xbuffer<230) && (ybuffer>146 && ybuffer<160)){month--;} |
star297 | 1:793dbd6d6498 | 273 | if((xbuffer>258 && xbuffer<288) && (ybuffer>124 && ybuffer<140)){year++;} |
star297 | 1:793dbd6d6498 | 274 | if((xbuffer>258 && xbuffer<288) && (ybuffer>146 && ybuffer<160)){year--;} |
star297 | 1:793dbd6d6498 | 275 | oled.disableTouch(); |
star297 | 1:793dbd6d6498 | 276 | |
star297 | 1:793dbd6d6498 | 277 | if (second >= 60) {second = 0;} |
star297 | 1:793dbd6d6498 | 278 | if (second < 0) {second = 59;} |
star297 | 1:793dbd6d6498 | 279 | if (minute >= 60) {minute = 0;} |
star297 | 1:793dbd6d6498 | 280 | if (minute < 0) {minute = 59;} |
star297 | 1:793dbd6d6498 | 281 | if (hour >= 24) {hour = 0;} |
star297 | 1:793dbd6d6498 | 282 | if (hour < 0) {hour = 23;} |
star297 | 1:793dbd6d6498 | 283 | if (dayofweek > 6){dayofweek = 0;} |
star297 | 1:793dbd6d6498 | 284 | if (dayofweek < 0){dayofweek = 6;} |
star297 | 1:793dbd6d6498 | 285 | if (month > 12) {month = 1;} |
star297 | 1:793dbd6d6498 | 286 | if (month < 1) {month = 12;} |
star297 | 1:793dbd6d6498 | 287 | if (dayofmonth <1) {dayofmonth = maxDay(year, month);} |
star297 | 1:793dbd6d6498 | 288 | if (dayofmonth > maxDay(year, month)) {dayofmonth = 1;} |
star297 | 1:793dbd6d6498 | 289 | if (year > 99) {year = 1;} |
star297 | 1:793dbd6d6498 | 290 | if (year < 0) {year = 99;} |
star297 | 1:793dbd6d6498 | 291 | |
star297 | 1:793dbd6d6498 | 292 | |
star297 | 1:793dbd6d6498 | 293 | oled.setFontSize(FONT12X16);oled.locate(1,6); |
star297 | 2:1eac3ea8c6e8 | 294 | oled.setFontColor(oled.toRGB(128,255,255)); |
star297 | 1:793dbd6d6498 | 295 | oled.printf("%2d:%02d:%02d ",hour,minute,second); |
star297 | 2:1eac3ea8c6e8 | 296 | oled.printf("%s %02d %s' 20%02d",weekDayName[dayofweek],dayofmonth,monthName[month-1],year); |
star297 | 1:793dbd6d6498 | 297 | } |
star297 | 0:94bf5ec759da | 298 | |
star297 | 1:793dbd6d6498 | 299 | } |
star297 | 1:793dbd6d6498 | 300 | void RTCclockupdate() |
star297 | 1:793dbd6d6498 | 301 | { |
star297 | 1:793dbd6d6498 | 302 | RTCread(); |
star297 | 1:793dbd6d6498 | 303 | fsecond = (RTCsecond/12); |
star297 | 1:793dbd6d6498 | 304 | fminute = (RTCminute/12); |
star297 | 1:793dbd6d6498 | 305 | if (x==1){ //Erase all hands |
star297 | 1:793dbd6d6498 | 306 | oled.drawLine(clkx,clky,clkx+xs,clky-ys,oled.toRGB(0,0,0)); // Erase Second's hand |
star297 | 1:793dbd6d6498 | 307 | oled.drawLine(clkx,clky,clkx+xm,clky-ym,oled.toRGB(0,0,0)); // Erase Minute's hand |
star297 | 1:793dbd6d6498 | 308 | oled.drawLine(clkx,clky,clkx+xh,clky-yh,oled.toRGB(0,0,0)); // Erase Hour's hand |
star297 | 1:793dbd6d6498 | 309 | } |
star297 | 1:793dbd6d6498 | 310 | //Calculations to get the second point of the clock hands. (first point is always the center of the clock) |
star297 | 1:793dbd6d6498 | 311 | angleS=(RTCsecond*6); //seconds in angle form, 360 degrees divided by 60 seconds = 6, x6 to get current angle |
star297 | 1:793dbd6d6498 | 312 | xs=(sin((angleS*3.14)/180)) * handSec; //get X component of the second's hand |
star297 | 1:793dbd6d6498 | 313 | ys=(cos((angleS*3.14)/180)) * handSec; //get Y component of the second's hand |
star297 | 1:793dbd6d6498 | 314 | 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 | 315 | xm=(sin((angleM*3.14)/180)) * handMin; //get X component of the minutes's hand |
star297 | 1:793dbd6d6498 | 316 | ym=(cos((angleM*3.14)/180)) * handMin; //get Y component of the minutes's hand |
star297 | 1:793dbd6d6498 | 317 | 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 | 318 | xh=(sin((angleH*3.14)/180)) * handHour; //get X component of the hours's hand |
star297 | 1:793dbd6d6498 | 319 | yh=(cos((angleH*3.14)/180)) * handHour; //get Y component of the hours's hand |
star297 | 1:793dbd6d6498 | 320 | x=1; |
star297 | 1:793dbd6d6498 | 321 | //Draw current time hands |
star297 | 1:793dbd6d6498 | 322 | oled.drawLine(clkx,clky,clkx+xm,clky-ym,oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 323 | oled.drawLine(clkx,clky,clkx+xh,clky-yh,oled.toRGB(0,255,255)); |
star297 | 1:793dbd6d6498 | 324 | oled.drawLine(clkx,clky,clkx+xs,clky-ys,oled.toRGB(255,255,0)); |
star297 | 1:793dbd6d6498 | 325 | oled.setPenSize(0); |
star297 | 1:793dbd6d6498 | 326 | oled.drawCircle(clkx,clky,5,oled.toRGB(255,255,255)); // Draw the center of the second's hand |
star297 | 1:793dbd6d6498 | 327 | } |
star297 | 1:793dbd6d6498 | 328 | |
star297 | 1:793dbd6d6498 | 329 | void RTCread() |
star297 | 1:793dbd6d6498 | 330 | { |
star297 | 1:793dbd6d6498 | 331 | time_t seconds = time(NULL); |
star297 | 1:793dbd6d6498 | 332 | char buffer[80]; |
star297 | 1:793dbd6d6498 | 333 | strftime(buffer, 2,"%S", localtime(&seconds)); |
star297 | 1:793dbd6d6498 | 334 | RTCsecond = atoi(buffer); |
star297 | 1:793dbd6d6498 | 335 | strftime(buffer, 2,"%M", localtime(&seconds)); |
star297 | 1:793dbd6d6498 | 336 | RTCminute = atoi(buffer); |
star297 | 1:793dbd6d6498 | 337 | strftime(buffer, 2,"%H", localtime(&seconds)); |
star297 | 1:793dbd6d6498 | 338 | RTChour = atoi(buffer); |
star297 | 1:793dbd6d6498 | 339 | strftime(buffer, 2,"%d", localtime(&seconds)); |
star297 | 1:793dbd6d6498 | 340 | RTCdayofmonth = atoi(buffer); |
star297 | 1:793dbd6d6498 | 341 | strftime(buffer, 2,"%w", localtime(&seconds)); |
star297 | 1:793dbd6d6498 | 342 | RTCdayofweek = atoi(buffer); |
star297 | 1:793dbd6d6498 | 343 | strftime(buffer, 2,"%m", localtime(&seconds)); |
star297 | 1:793dbd6d6498 | 344 | RTCmonth = atoi(buffer); |
star297 | 1:793dbd6d6498 | 345 | strftime(buffer, 2,"%y", localtime(&seconds)); |
star297 | 1:793dbd6d6498 | 346 | RTCyear = atoi(buffer); |
star297 | 1:793dbd6d6498 | 347 | } |
star297 | 1:793dbd6d6498 | 348 | |
star297 | 1:793dbd6d6498 | 349 | void RTCset() |
star297 | 1:793dbd6d6498 | 350 | { |
star297 | 1:793dbd6d6498 | 351 | t.tm_sec = (second); // 0-59 |
star297 | 1:793dbd6d6498 | 352 | t.tm_min = (minute); // 0-59 |
star297 | 1:793dbd6d6498 | 353 | t.tm_hour = (hour); // 0-23 |
star297 | 1:793dbd6d6498 | 354 | t.tm_mday = (dayofmonth); // 1-31 |
star297 | 1:793dbd6d6498 | 355 | t.tm_mon = (month-1); // 0-11 DCF "0" = Jan, -1 added for Mbed RCT clock format |
star297 | 1:793dbd6d6498 | 356 | t.tm_year = ((year)+100); // year since 1900, current DCF year + 100 + 1900 = correct year |
star297 | 1:793dbd6d6498 | 357 | if (DCF==1) {set_time(mktime(&t)-3600);} // set RTC clock to DCF -1 hour for GMT time zone |
star297 | 1:793dbd6d6498 | 358 | else {set_time(mktime(&t));} // set RTC clock to local time zone |
star297 | 1:793dbd6d6498 | 359 | DCF=0; |
star297 | 1:793dbd6d6498 | 360 | } |
star297 | 1:793dbd6d6498 | 361 | |
star297 | 1:793dbd6d6498 | 362 | // **************************** DCF clock ********************************************** |
star297 | 1:793dbd6d6498 | 363 | |
star297 | 1:793dbd6d6498 | 364 | void DCFclock() |
star297 | 1:793dbd6d6498 | 365 | { |
star297 | 2:1eac3ea8c6e8 | 366 | oled.clear(); |
star297 | 2:1eac3ea8c6e8 | 367 | oled.drawText(0,1,(FONT12X16),("--- DCF77 Atomic Clock ---"),oled.toRGB(255,255,255)); |
star297 | 2:1eac3ea8c6e8 | 368 | oled.drawText(3,3,(FONT12X16),("Checking Signal..."),oled.toRGB(255,255,255)); |
star297 | 2:1eac3ea8c6e8 | 369 | T1.reset();T1.start(); |
star297 | 2:1eac3ea8c6e8 | 370 | while(dcfSignalIn == 1 && T1.read()<.5){} |
star297 | 2:1eac3ea8c6e8 | 371 | while(dcfSignalIn == 0 && T1.read()<.5){} |
star297 | 2:1eac3ea8c6e8 | 372 | T1.stop(); |
star297 | 2:1eac3ea8c6e8 | 373 | if (T1.read()>.5){ |
star297 | 2:1eac3ea8c6e8 | 374 | T1.stop(); |
star297 | 2:1eac3ea8c6e8 | 375 | oled.drawText(0,5,(FONT12X16),(" !! No signal detected !! "),oled.toRGB(255,0,0)); |
star297 | 2:1eac3ea8c6e8 | 376 | oled.drawText(2,9,(FONT8X12),("Connect Non inverting signal of DCF"),oled.toRGB(255,255,255)); |
star297 | 2:1eac3ea8c6e8 | 377 | oled.drawText(2,10,(FONT8X12),("receiver module to specified Pin."),oled.toRGB(255,255,255)); |
star297 | 2:1eac3ea8c6e8 | 378 | oled.drawText(5,12,(FONT8X12),("Running Demo mode."),oled.toRGB(255,255,255)); |
star297 | 2:1eac3ea8c6e8 | 379 | wait(5); |
star297 | 2:1eac3ea8c6e8 | 380 | } |
star297 | 2:1eac3ea8c6e8 | 381 | wait(1); |
star297 | 1:793dbd6d6498 | 382 | oled.clear();DCFbitmapdraw();RTCread(); |
star297 | 1:793dbd6d6498 | 383 | second=RTCsecond;minute=RTCminute;hour=RTChour;dayofweek=RTCdayofweek;dayofmonth=RTCdayofmonth;month=RTCmonth;year=RTCyear; |
star297 | 1:793dbd6d6498 | 384 | if(tz==0) {oled.drawText(0,0,(FONT8X12)," RTC Clock Time (GMT)",oled.toRGB(255,0,0));} |
star297 | 1:793dbd6d6498 | 385 | if (tz==1) {oled.drawText(0,0,(FONT8X12)," RTC Clock Time (CET)",oled.toRGB(255,0,0));} |
star297 | 1:793dbd6d6498 | 386 | if (tz==2) {oled.drawText(0,0,(FONT8X12)," RTC Clock Time (EET)",oled.toRGB(255,0,0));} |
star297 | 1:793dbd6d6498 | 387 | if (tz==3) {oled.drawText(0,0,(FONT8X12)," RTC Clock Time (MSK)",oled.toRGB(255,0,0));} |
star297 | 1:793dbd6d6498 | 388 | oled.drawText(22,5,(FONT8X12)," DCF Time (CET)",oled.toRGB(255,255,0)); |
star297 | 1:793dbd6d6498 | 389 | oled.setTextBackgroundType (TEXT_TRANSPARENT); |
star297 | 1:793dbd6d6498 | 390 | oled.drawTextButton(1, 270, 140,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(255,255,255)), 1, 1, " Back "); |
star297 | 1:793dbd6d6498 | 391 | oled.setTextBackgroundType (TEXT_OPAQUE); |
star297 | 1:793dbd6d6498 | 392 | draw_graph=0;DCFdrawgraph(); |
star297 | 1:793dbd6d6498 | 393 | oled.drawLine(155,190,169,190, oled.toRGB(225, 255, 255)); |
star297 | 1:793dbd6d6498 | 394 | oled.drawLine(169,190,169,203, oled.toRGB(225, 255, 255)); |
star297 | 1:793dbd6d6498 | 395 | oled.drawLine(170,203,287,203, oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 396 | oled.drawLine(287,190,287,203, oled.toRGB(225, 255, 255)); |
star297 | 1:793dbd6d6498 | 397 | oled.drawLine(288,190,305,190, oled.toRGB(225, 255, 255)); |
star297 | 1:793dbd6d6498 | 398 | oled.drawText(0,26,(FONT5X7)," 0 start min hour Dt dy mon year 60",oled.toRGB(255,0,0)); |
star297 | 1:793dbd6d6498 | 399 | oled.setTouchArea(240,140,290,160); |
star297 | 2:1eac3ea8c6e8 | 400 | start=0;sync=1;x=0;y=5;r=0;SignalStatus=0; |
star297 | 2:1eac3ea8c6e8 | 401 | laststart=2; |
star297 | 2:1eac3ea8c6e8 | 402 | loop=0; |
star297 | 2:1eac3ea8c6e8 | 403 | //RTCset=0; |
star297 | 2:1eac3ea8c6e8 | 404 | interrupt_counter = 0;dcf_sec=0;error_count=0,display=0;signal_error=0;rtcset_times=0; |
star297 | 2:1eac3ea8c6e8 | 405 | hour = 0;minute = 0,second = 0,dayofweek = 6;dayofmonth = 1;month = 1;year = 0; |
star297 | 1:793dbd6d6498 | 406 | |
star297 | 2:1eac3ea8c6e8 | 407 | T1.start(); |
star297 | 2:1eac3ea8c6e8 | 408 | while(dcfSignalIn == 1 && T1.read()<.5){} |
star297 | 2:1eac3ea8c6e8 | 409 | while(dcfSignalIn == 0 && T1.read()<.5){} |
star297 | 2:1eac3ea8c6e8 | 410 | T1.stop(); |
star297 | 2:1eac3ea8c6e8 | 411 | dcfSignalIn.rise(dcfIRQ); //Trigger dcfISR Ticker on rising edge of DCF pulse |
star297 | 2:1eac3ea8c6e8 | 412 | interrupt_counter = 0;sync=0; |
star297 | 2:1eac3ea8c6e8 | 413 | |
star297 | 1:793dbd6d6498 | 414 | Ticker50ms.attach(& dcfISR, .05); |
star297 | 1:793dbd6d6498 | 415 | |
star297 | 1:793dbd6d6498 | 416 | while (IRQ==0) { |
star297 | 1:793dbd6d6498 | 417 | if (loop==0) { |
star297 | 1:793dbd6d6498 | 418 | DCFloop(); // Continuously get dcf time and Display data every second interrupted by the Ticker every 50ms |
star297 | 1:793dbd6d6498 | 419 | loop=1;} |
star297 | 1:793dbd6d6498 | 420 | } |
star297 | 1:793dbd6d6498 | 421 | oled.clear(); |
star297 | 1:793dbd6d6498 | 422 | } |
star297 | 1:793dbd6d6498 | 423 | |
star297 | 1:793dbd6d6498 | 424 | void DCFloop() |
star297 | 1:793dbd6d6498 | 425 | { |
star297 | 1:793dbd6d6498 | 426 | if (interrupt_counter == 0) { |
star297 | 1:793dbd6d6498 | 427 | if (start == 0) {dcf_sec=0;} |
star297 | 1:793dbd6d6498 | 428 | if (dcf_sec == 0){dcf_array[58] = 0;} |
star297 | 1:793dbd6d6498 | 429 | if (dcf_good==1 && dcf_sec==2) {DCF=1;RTCset();} |
star297 | 1:793dbd6d6498 | 430 | } |
star297 | 1:793dbd6d6498 | 431 | |
star297 | 1:793dbd6d6498 | 432 | if (interrupt_counter == 1) { |
star297 | 1:793dbd6d6498 | 433 | oled.setFontSize(FONT12X16); |
star297 | 1:793dbd6d6498 | 434 | oled.locate(15,5);oled.setFontColor(oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 435 | oled.printf("%02d:%02d:%02d", hour, minute, second); |
star297 | 1:793dbd6d6498 | 436 | oled.locate(3,13);oled.setFontColor(oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 437 | oled.setFontSize(FONT12X16);oled.printf("%02d",dcf_sec); |
star297 | 1:793dbd6d6498 | 438 | } |
star297 | 1:793dbd6d6498 | 439 | |
star297 | 1:793dbd6d6498 | 440 | if (interrupt_counter==2){ |
star297 | 1:793dbd6d6498 | 441 | if (rtcset==0) { |
star297 | 1:793dbd6d6498 | 442 | oled.drawText(33,2,(FONT5X7),"RTC -- un-set -- ",oled.toRGB(255,0,0));} |
star297 | 1:793dbd6d6498 | 443 | if (rtcset==1) { |
star297 | 1:793dbd6d6498 | 444 | oled.drawText(33,2,(FONT5X7),"RTC *** set *** ",oled.toRGB(0,255,0));} |
star297 | 1:793dbd6d6498 | 445 | oled.setFontSize(FONT12X16);oled.locate(0,1); |
star297 | 1:793dbd6d6498 | 446 | oled.setFontColor(oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 447 | RTCread(); |
star297 | 1:793dbd6d6498 | 448 | oled.printf("%2d:%02d:%02d",RTChour,RTCminute,RTCsecond); |
star297 | 1:793dbd6d6498 | 449 | } |
star297 | 1:793dbd6d6498 | 450 | |
star297 | 1:793dbd6d6498 | 451 | if (interrupt_counter == 4) { |
star297 | 1:793dbd6d6498 | 452 | if (dcf_sec > 59) {dcf_sec = 0;} |
star297 | 1:793dbd6d6498 | 453 | if (dcf_sec>20 && signal_error==1) {DCFbitmapdraw();DCFdrawgraph();start=0;signal_error=0;SignalStatus=5;} |
star297 | 1:793dbd6d6498 | 454 | if (dcf_sec == 57) {oled.drawText(36,7,(FONT8X12)," ",oled.toRGB(0,0,0));} |
star297 | 1:793dbd6d6498 | 455 | if (start == 0 && signal_error==0) {SignalStatus=0;} |
star297 | 1:793dbd6d6498 | 456 | } |
star297 | 1:793dbd6d6498 | 457 | |
star297 | 1:793dbd6d6498 | 458 | if (interrupt_counter == 6 && dcf_sec > 0){ |
star297 | 1:793dbd6d6498 | 459 | if (dcf_sec==1){DCFdrawgraph();SignalStatus = 1;} |
star297 | 1:793dbd6d6498 | 460 | oled.setPenSize(1); oled.drawRectangle(11, 229, (dcf_sec*5), 8, oled.toRGB(0,255,0));draw_graph=0; |
star297 | 1:793dbd6d6498 | 461 | if (signal_error==1) {DCFdrawgraph();signal_error=0;SignalStatus=5;} |
star297 | 1:793dbd6d6498 | 462 | } |
star297 | 1:793dbd6d6498 | 463 | |
star297 | 1:793dbd6d6498 | 464 | if (interrupt_counter == 7){ |
star297 | 1:793dbd6d6498 | 465 | DCFbitstatus(); |
star297 | 1:793dbd6d6498 | 466 | if (dcf_sec == 21){SignalStatus=2;r = !r;} |
star297 | 1:793dbd6d6498 | 467 | if (dcf_sec > 20 && dcf_sec < 59 ) {DCFbitprint();} |
star297 | 1:793dbd6d6498 | 468 | } |
star297 | 1:793dbd6d6498 | 469 | |
star297 | 1:793dbd6d6498 | 470 | if (interrupt_counter == 8){ |
star297 | 1:793dbd6d6498 | 471 | if (start==1){dcf_array[dcf_sec]=dcf_status.DCFsample150;} |
star297 | 1:793dbd6d6498 | 472 | oled.setFontSize(FONT12X16);oled.locate(0,2); |
star297 | 1:793dbd6d6498 | 473 | oled.setFontColor(oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 474 | oled.printf("%s %02d %s' 20%02d",weekDayName[RTCdayofweek],RTCdayofmonth,monthName[RTCmonth-1],RTCyear); |
star297 | 1:793dbd6d6498 | 475 | } |
star297 | 1:793dbd6d6498 | 476 | |
star297 | 1:793dbd6d6498 | 477 | if (interrupt_counter == 10) { |
star297 | 1:793dbd6d6498 | 478 | oled.setFontSize(FONT8X12);oled.locate(23,8);oled.setFontColor(oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 479 | oled.printf("%s %02d %s' 20%02d", weekDayName[dayofweek], dayofmonth, monthName[month-1], year); |
star297 | 1:793dbd6d6498 | 480 | if (summertime) oled.drawText(23,9,(FONT8X12),"Summer Time",oled.toRGB(255,128,0)); |
star297 | 1:793dbd6d6498 | 481 | else oled.drawText(23,9,(FONT8X12),"Winter Time",oled.toRGB(0,255,255)); |
star297 | 1:793dbd6d6498 | 482 | oled.drawText(23,10,(FONT8X12),leapSymbol[dcf_status.is_leap],oled.toRGB(0,255,160)); |
star297 | 1:793dbd6d6498 | 483 | } |
star297 | 1:793dbd6d6498 | 484 | |
star297 | 1:793dbd6d6498 | 485 | if (interrupt_counter == 11 & second == 1) { |
star297 | 1:793dbd6d6498 | 486 | oled.setFontSize(FONT5X7);oled.locate(34,5); |
star297 | 1:793dbd6d6498 | 487 | oled.setFontColor(oled.toRGB(255,255,255)); |
star297 | 2:1eac3ea8c6e8 | 488 | oled.printf("RTC set x %d", rtcset_times); |
star297 | 1:793dbd6d6498 | 489 | } |
star297 | 1:793dbd6d6498 | 490 | |
star297 | 1:793dbd6d6498 | 491 | if (interrupt_counter == 12){ |
star297 | 1:793dbd6d6498 | 492 | if (SignalStatus==0) {oled.drawText(26,20,(FONT5X7),statusText[SignalStatus],oled.toRGB(255,255,255));} |
star297 | 1:793dbd6d6498 | 493 | if (SignalStatus==1) {oled.drawText(26,20,(FONT5X7),statusText[SignalStatus],oled.toRGB(255,255,0));} |
star297 | 1:793dbd6d6498 | 494 | if (SignalStatus==2) {oled.drawText(26,20,(FONT5X7),statusText[SignalStatus],oled.toRGB(0,255,255));} |
star297 | 1:793dbd6d6498 | 495 | if (SignalStatus==3) {oled.drawText(26,20,(FONT5X7),statusText[SignalStatus],oled.toRGB(0,0,255));} |
star297 | 1:793dbd6d6498 | 496 | if (SignalStatus==4) {oled.drawText(26,20,(FONT5X7),statusText[SignalStatus],oled.toRGB(0,255,0));} |
star297 | 1:793dbd6d6498 | 497 | if (SignalStatus==5) { |
star297 | 1:793dbd6d6498 | 498 | oled.drawText(26,20,(FONT5X7),statusText[SignalStatus],oled.toRGB(255,0,0)); |
star297 | 1:793dbd6d6498 | 499 | oled.drawText(36,7,(FONT8X12)," ",oled.toRGB(0,0,0)); |
star297 | 1:793dbd6d6498 | 500 | start=0;SignalStatus=0;sync=0; |
star297 | 1:793dbd6d6498 | 501 | } |
star297 | 1:793dbd6d6498 | 502 | } |
star297 | 1:793dbd6d6498 | 503 | |
star297 | 1:793dbd6d6498 | 504 | if (interrupt_counter==13){ |
star297 | 2:1eac3ea8c6e8 | 505 | if (start==0 && laststart != start) {oled.drawText(26,18,(FONT5X7),("No Sync "),oled.toRGB(255,0,0));laststart=start;} |
star297 | 2:1eac3ea8c6e8 | 506 | if (start==1 && laststart != start) {oled.drawText(26,18,(FONT5X7),("In Sync - running"),oled.toRGB(0,255,0));laststart=start;} |
star297 | 1:793dbd6d6498 | 507 | } |
star297 | 0:94bf5ec759da | 508 | |
star297 | 1:793dbd6d6498 | 509 | if (interrupt_counter>13){ |
star297 | 1:793dbd6d6498 | 510 | oled.getTouch(&xbuffer,&ybuffer); |
star297 | 1:793dbd6d6498 | 511 | if (display==0){ |
star297 | 1:793dbd6d6498 | 512 | if((xbuffer>2 && xbuffer<318) && (ybuffer>2 && ybuffer<238)){ |
star297 | 1:793dbd6d6498 | 513 | oled.displayControl(0x01,0x01);display=1; |
star297 | 1:793dbd6d6498 | 514 | oled.resetTouchArea();}} |
star297 | 1:793dbd6d6498 | 515 | if((xbuffer>240 && xbuffer<290) && (ybuffer>140 && ybuffer<160)){ |
star297 | 2:1eac3ea8c6e8 | 516 | dcfSignalIn.rise(NULL);Ticker50ms.detach();IRQ=1;} |
star297 | 1:793dbd6d6498 | 517 | } |
star297 | 1:793dbd6d6498 | 518 | |
star297 | 1:793dbd6d6498 | 519 | if (interrupt_counter == 19){DCFbitstatus();} |
star297 | 1:793dbd6d6498 | 520 | |
star297 | 1:793dbd6d6498 | 521 | } |
star297 | 1:793dbd6d6498 | 522 | |
star297 | 1:793dbd6d6498 | 523 | void DCFtestparity() |
star297 | 1:793dbd6d6498 | 524 | { |
star297 | 1:793dbd6d6498 | 525 | rtcset=0;DCFparitycalc(); |
star297 | 1:793dbd6d6498 | 526 | paritycheck= testu or testm or testdmy; |
star297 | 1:793dbd6d6498 | 527 | if (p_year>99) paritycheck=1; |
star297 | 1:793dbd6d6498 | 528 | if (p_month>12) paritycheck=1; |
star297 | 1:793dbd6d6498 | 529 | if (p_dayofmonth>31) paritycheck=1; |
star297 | 1:793dbd6d6498 | 530 | if (p_hour>23) paritycheck=1; |
star297 | 1:793dbd6d6498 | 531 | if (p_minute>59) paritycheck=1; |
star297 | 1:793dbd6d6498 | 532 | if (paritycheck) {dcf_good=0;SignalStatus = 5;} // bad parity |
star297 | 1:793dbd6d6498 | 533 | else {dcf_good=1;SignalStatus = 4;} // good parity |
star297 | 1:793dbd6d6498 | 534 | } |
star297 | 1:793dbd6d6498 | 535 | |
star297 | 1:793dbd6d6498 | 536 | void DCFsetTime() |
star297 | 1:793dbd6d6498 | 537 | { |
star297 | 1:793dbd6d6498 | 538 | second = dcf_sec; |
star297 | 1:793dbd6d6498 | 539 | minute=p_minute; |
star297 | 1:793dbd6d6498 | 540 | hour=p_hour; |
star297 | 1:793dbd6d6498 | 541 | dayofweek=p_dayofweek; |
star297 | 1:793dbd6d6498 | 542 | dayofmonth=p_dayofmonth; |
star297 | 1:793dbd6d6498 | 543 | month=p_month; |
star297 | 1:793dbd6d6498 | 544 | year=p_year; |
star297 | 1:793dbd6d6498 | 545 | oled.drawText(36,7,(FONT8X12),"*",oled.toRGB(0,255,0)); |
star297 | 2:1eac3ea8c6e8 | 546 | rtcset_times++; |
star297 | 1:793dbd6d6498 | 547 | } |
star297 | 1:793dbd6d6498 | 548 | void DCFbitprint() |
star297 | 1:793dbd6d6498 | 549 | { |
star297 | 1:793dbd6d6498 | 550 | if (r==1) {oled.setFontColor(oled.toRGB(0,0,255));} // alternate bit draw colour |
star297 | 1:793dbd6d6498 | 551 | else {oled.setFontColor(oled.toRGB(255,255,255));} |
star297 | 1:793dbd6d6498 | 552 | oled.setFontSize(FONT8X12); |
star297 | 1:793dbd6d6498 | 553 | if (dcf_sec==21){x=5;y=7;} |
star297 | 1:793dbd6d6498 | 554 | if (dcf_sec==28){x=5;y=15;oled.locate(5,15);oled.printf(" ");} |
star297 | 1:793dbd6d6498 | 555 | if (dcf_sec==29){x=7;y=7;} |
star297 | 1:793dbd6d6498 | 556 | if (dcf_sec==35){x=7;y=15;} |
star297 | 1:793dbd6d6498 | 557 | if (dcf_sec==36){x=9;y=7;} |
star297 | 1:793dbd6d6498 | 558 | if (dcf_sec==42){x=11;y=7;} |
star297 | 1:793dbd6d6498 | 559 | if (dcf_sec==45){x=13;y=7;} |
star297 | 1:793dbd6d6498 | 560 | if (dcf_sec==50){x=15;y=7;} |
star297 | 1:793dbd6d6498 | 561 | oled.locate(x,y); |
star297 | 1:793dbd6d6498 | 562 | oled.printf("%d",dcf_status.DCFsample150); |
star297 | 1:793dbd6d6498 | 563 | y++; |
star297 | 1:793dbd6d6498 | 564 | } |
star297 | 1:793dbd6d6498 | 565 | |
star297 | 1:793dbd6d6498 | 566 | void DCFbitmapdraw() |
star297 | 1:793dbd6d6498 | 567 | { |
star297 | 1:793dbd6d6498 | 568 | x=2,y=6; |
star297 | 1:793dbd6d6498 | 569 | oled.drawText(x-2,y,(FONT8X12)," Dcf M H D d M Y",oled.toRGB(255,255,0)); |
star297 | 1:793dbd6d6498 | 570 | oled.drawText(x,y+1,(FONT8X12)," 1 i o a a o e",oled.toRGB(255,255,0)); |
star297 | 1:793dbd6d6498 | 571 | oled.drawText(x,y+2,(FONT8X12)," 2 n u t y n a",oled.toRGB(255,255,0)); |
star297 | 1:793dbd6d6498 | 572 | oled.drawText(x,y+3,(FONT8X12)," 4 u r e t r",oled.toRGB(255,255,0)); |
star297 | 1:793dbd6d6498 | 573 | oled.drawText(x,y+4,(FONT8X12)," 8 t h ",oled.toRGB(255,255,0)); |
star297 | 1:793dbd6d6498 | 574 | oled.drawText(x,y+5,(FONT8X12),"10 e ",oled.toRGB(255,255,0)); |
star297 | 1:793dbd6d6498 | 575 | oled.drawText(x,y+6,(FONT8X12),"20 ",oled.toRGB(255,255,0)); |
star297 | 1:793dbd6d6498 | 576 | oled.drawText(x,y+7,(FONT8X12),"40 ",oled.toRGB(255,255,0)); |
star297 | 1:793dbd6d6498 | 577 | oled.drawText(x,y+8,(FONT8X12),"80 ",oled.toRGB(255,255,0)); |
star297 | 1:793dbd6d6498 | 578 | oled.drawText(x,y+9,(FONT8X12)," P arity ",oled.toRGB(255,255,0)); |
star297 | 1:793dbd6d6498 | 579 | oled.drawLine(8,83,135,83, oled.toRGB(0, 255, 0)); |
star297 | 1:793dbd6d6498 | 580 | oled.drawLine(35,70,35,195, oled.toRGB(0, 255, 0)); |
star297 | 1:793dbd6d6498 | 581 | } |
star297 | 1:793dbd6d6498 | 582 | void DCFdrawgraph() |
star297 | 1:793dbd6d6498 | 583 | { |
star297 | 1:793dbd6d6498 | 584 | if (draw_graph==0){ |
star297 | 1:793dbd6d6498 | 585 | oled.setPenSize(0); |
star297 | 1:793dbd6d6498 | 586 | oled.drawRectangle(10,228,300,8,oled.toRGB(0,0,0)); |
star297 | 1:793dbd6d6498 | 587 | oled.setPenSize(1); |
star297 | 1:793dbd6d6498 | 588 | oled.drawRectangle(10,227,302,10,oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 589 | oled.drawLine(10,220,10,237,oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 590 | oled.drawLine(312,220,312,237,oled.toRGB(255,255,255)); |
star297 | 1:793dbd6d6498 | 591 | oled.drawLine(111,220,111,237,oled.toRGB(255,255,255)); //start |
star297 | 1:793dbd6d6498 | 592 | oled.drawLine(156,220,156,237,oled.toRGB(225,255,255)); //min |
star297 | 1:793dbd6d6498 | 593 | oled.drawLine(186,220,186,237,oled.toRGB(255,255,225)); //hour |
star297 | 1:793dbd6d6498 | 594 | oled.drawLine(216,220,216,237,oled.toRGB(225,255,225)); //date |
star297 | 1:793dbd6d6498 | 595 | oled.drawLine(231,220,231,237, oled.toRGB(225, 255, 225));//day |
star297 | 1:793dbd6d6498 | 596 | oled.drawLine(256,220,256,237, oled.toRGB(225, 255, 225));//month |
star297 | 1:793dbd6d6498 | 597 | oled.drawLine(301,220,301,237, oled.toRGB(225, 255, 225));//year |
star297 | 1:793dbd6d6498 | 598 | draw_graph=1; |
star297 | 1:793dbd6d6498 | 599 | } |
star297 | 1:793dbd6d6498 | 600 | } |
star297 | 1:793dbd6d6498 | 601 | void DCFbitstatus() |
star297 | 1:793dbd6d6498 | 602 | { |
star297 | 1:793dbd6d6498 | 603 | oled.locate(29,22); |
star297 | 1:793dbd6d6498 | 604 | oled.setFontSize(FONT5X7); |
star297 | 1:793dbd6d6498 | 605 | oled.setFontColor(oled.toRGB(255,0,0)); |
star297 | 1:793dbd6d6498 | 606 | 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 | 607 | oled.setPenSize(0); |
star297 | 1:793dbd6d6498 | 608 | if (!dcf_status.DCFsample50) {oled.drawRectangle(170,190,11,12, oled.toRGB(0,0,0));} |
star297 | 1:793dbd6d6498 | 609 | else {oled.drawRectangle(170,190,11,12, oled.toRGB(255,255,255));} |
star297 | 1:793dbd6d6498 | 610 | if (!dcf_status.DCFsample150) {oled.drawRectangle(182,190,11,12, oled.toRGB(0,0,0));} |
star297 | 1:793dbd6d6498 | 611 | else {oled.drawRectangle(182,190,11,12, oled.toRGB(255,255,255));} |
star297 | 1:793dbd6d6498 | 612 | if (!dcf_status.DCFsample300) {oled.drawRectangle(194,190,11,12, oled.toRGB(0,0,0));} |
star297 | 1:793dbd6d6498 | 613 | else {oled.drawRectangle(194,190,11,12, oled.toRGB(255,255,255));} |
star297 | 1:793dbd6d6498 | 614 | if (!dcf_status.DCFsample500) {oled.drawRectangle(206,190,23,12, oled.toRGB(0,0,0));} |
star297 | 1:793dbd6d6498 | 615 | else {oled.drawRectangle(206,190,23,12, oled.toRGB(255,255,255));} |
star297 | 1:793dbd6d6498 | 616 | if (!dcf_status.DCFsample600) {oled.drawRectangle(230,190,56,12, oled.toRGB(0,0,0));} |
star297 | 1:793dbd6d6498 | 617 | else {oled.drawRectangle(230,190,56,12, oled.toRGB(0,0,255));} |
star297 | 1:793dbd6d6498 | 618 | } |
star297 | 1:793dbd6d6498 | 619 | |
star297 | 1:793dbd6d6498 | 620 | void DCFparitycalc() |
star297 | 1:793dbd6d6498 | 621 | { |
star297 | 1:793dbd6d6498 | 622 | //calculate summer/winter time---------------------------------------------------------------------- |
star297 | 1:793dbd6d6498 | 623 | summertime = dcf_array[17] & 1; |
star297 | 1:793dbd6d6498 | 624 | //calculate hour-------------------------------------------------------------------------------------- |
star297 | 1:793dbd6d6498 | 625 | hourh = dcf_array[34] * 20 + dcf_array[33] * 10; |
star297 | 1:793dbd6d6498 | 626 | hourl = dcf_array[32] * 8 + dcf_array[31] * 4 + dcf_array[30] * 2 + dcf_array[29] * 1; |
star297 | 1:793dbd6d6498 | 627 | p_hour = hourh + hourl; |
star297 | 1:793dbd6d6498 | 628 | //calculate minutes------------------------------------------------------------------------------------ |
star297 | 1:793dbd6d6498 | 629 | minl = dcf_array[24] * 8 + dcf_array[23] * 4 + dcf_array[22] * 2 + dcf_array[21] * 1; |
star297 | 1:793dbd6d6498 | 630 | minh = dcf_array[27] * 40 + dcf_array[26] * 20 +dcf_array[25] * 10; |
star297 | 1:793dbd6d6498 | 631 | p_minute = minh + minl; |
star297 | 1:793dbd6d6498 | 632 | //calculate day of week-------------------------------------------------------------------------------- |
star297 | 1:793dbd6d6498 | 633 | p_dayofweek = dcf_array[44] * 4 +dcf_array[43] * 2 + dcf_array[42] * 1; |
star297 | 1:793dbd6d6498 | 634 | //calculate day---------------------------------------------------------------------------------------- |
star297 | 1:793dbd6d6498 | 635 | dayl = dcf_array[39] * 8 + dcf_array[38] * 4 + dcf_array[37] * 2 + dcf_array[36] * 1; |
star297 | 1:793dbd6d6498 | 636 | dayh = dcf_array[41] * 20 + dcf_array[40] * 10; |
star297 | 1:793dbd6d6498 | 637 | p_dayofmonth=dayh+dayl; |
star297 | 1:793dbd6d6498 | 638 | //calculate month-------------------------------------------------------------------------------------- |
star297 | 1:793dbd6d6498 | 639 | monthh = dcf_array[49] * 10; |
star297 | 1:793dbd6d6498 | 640 | monthl = dcf_array[48] * 8 + dcf_array[47] * 4 + dcf_array[46] * 2 + dcf_array[45] * 1; |
star297 | 1:793dbd6d6498 | 641 | p_month = monthh +monthl; |
star297 | 1:793dbd6d6498 | 642 | //calculate year--------------------------------------------------------------------------------------- |
star297 | 1:793dbd6d6498 | 643 | yearh = dcf_array[57] * 80 + dcf_array[56] * 40 + dcf_array[55] * 20 + dcf_array[54] * 10; |
star297 | 1:793dbd6d6498 | 644 | yearl = dcf_array[53] * 8 +dcf_array[52] * 4 + dcf_array[51] * 2 + dcf_array[50] * 1; |
star297 | 1:793dbd6d6498 | 645 | p_year = yearh+yearl; |
star297 | 1:793dbd6d6498 | 646 | //calculate parity |
star297 | 1:793dbd6d6498 | 647 | 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 | 648 | 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 | 649 | 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 | 650 | //test parity------------------------------ |
star297 | 1:793dbd6d6498 | 651 | testu=parityu & 1; |
star297 | 1:793dbd6d6498 | 652 | testm=paritym & 1; |
star297 | 1:793dbd6d6498 | 653 | testdmy=paritydmy & 1; |
star297 | 1:793dbd6d6498 | 654 | } |
star297 | 1:793dbd6d6498 | 655 | |
star297 | 1:793dbd6d6498 | 656 | void dcfIRQ(void) |
star297 | 1:793dbd6d6498 | 657 | { |
star297 | 1:793dbd6d6498 | 658 | if (sync==0){ |
star297 | 1:793dbd6d6498 | 659 | interrupt_counter = 0;sync=1;dcf_sec=0;error_count=0; |
star297 | 1:793dbd6d6498 | 660 | Ticker50ms.attach(& dcfISR, .05); |
star297 | 1:793dbd6d6498 | 661 | } |
star297 | 1:793dbd6d6498 | 662 | } |
star297 | 1:793dbd6d6498 | 663 | |
star297 | 1:793dbd6d6498 | 664 | void dcfISR() //This is the interrupt service routine (ISR) that is called every 50ms |
star297 | 1:793dbd6d6498 | 665 | { |
star297 | 1:793dbd6d6498 | 666 | interrupt_counter++;loop=0; |
star297 | 1:793dbd6d6498 | 667 | |
star297 | 2:1eac3ea8c6e8 | 668 | SignalLED = !dcfSignalIn; // Show dcfSignal state on LED |
star297 | 1:793dbd6d6498 | 669 | |
star297 | 1:793dbd6d6498 | 670 | if (interrupt_counter == 20) { // 50mS x 20 = 1000mS = 1 Second |
star297 | 1:793dbd6d6498 | 671 | interrupt_counter = 0;second++;dcf_sec++; |
star297 | 1:793dbd6d6498 | 672 | if (start==0) dcf_sec=0; |
star297 | 1:793dbd6d6498 | 673 | } |
star297 | 1:793dbd6d6498 | 674 | if (interrupt_counter == 0){ |
star297 | 1:793dbd6d6498 | 675 | if (dcf_sec==58) {SignalStatus = 3;} |
star297 | 1:793dbd6d6498 | 676 | if (dcf_sec==59) {DCFtestparity();} |
star297 | 1:793dbd6d6498 | 677 | if (dcf_good==1 && dcf_sec==1) {DCFsetTime();} |
star297 | 1:793dbd6d6498 | 678 | } |
star297 | 1:793dbd6d6498 | 679 | if (second >= 60) {++minute;second -=60;} |
star297 | 1:793dbd6d6498 | 680 | if (minute >= 60) {++hour;minute-=60;} |
star297 | 1:793dbd6d6498 | 681 | if (hour >= 24) {hour -=24;++dayofweek;++dayofmonth;} |
star297 | 1:793dbd6d6498 | 682 | if (dayofweek > 6) dayofweek = 0; |
star297 | 1:793dbd6d6498 | 683 | if (dayofmonth > maxDay(year, month)) {dayofmonth = 1;month++;} |
star297 | 1:793dbd6d6498 | 684 | if (month > 12) {month = 1;year++;} |
star297 | 1:793dbd6d6498 | 685 | if (year > 99) year = 1; |
star297 | 1:793dbd6d6498 | 686 | |
star297 | 1:793dbd6d6498 | 687 | switch (interrupt_counter) { |
star297 | 1:793dbd6d6498 | 688 | case 1: { // 50mS after start of second pulse |
star297 | 2:1eac3ea8c6e8 | 689 | dcf_status.DCFsample50 = (dcfSignalIn); |
star297 | 1:793dbd6d6498 | 690 | break;} |
star297 | 1:793dbd6d6498 | 691 | case 3: { // 150mS after start of second pulse (bit "1" dcf Data) |
star297 | 2:1eac3ea8c6e8 | 692 | dcf_status.DCFsample150 = (dcfSignalIn); |
star297 | 1:793dbd6d6498 | 693 | break;} |
star297 | 1:793dbd6d6498 | 694 | case 6: { // 300mS after start of second (signal error if true) |
star297 | 2:1eac3ea8c6e8 | 695 | dcf_status.DCFsample300 = (dcfSignalIn); |
star297 | 2:1eac3ea8c6e8 | 696 | if (dcfSignalIn) {dcf_error = 1;} |
star297 | 1:793dbd6d6498 | 697 | break;} |
star297 | 1:793dbd6d6498 | 698 | case 10: { // 500mS after start of second (signal error if true) |
star297 | 2:1eac3ea8c6e8 | 699 | dcf_status.DCFsample500 = (dcfSignalIn); |
star297 | 2:1eac3ea8c6e8 | 700 | if (dcfSignalIn) {dcf_error = 1;} |
star297 | 1:793dbd6d6498 | 701 | break;} |
star297 | 1:793dbd6d6498 | 702 | case 12: { // 600mS after start of second (signal error if true) |
star297 | 2:1eac3ea8c6e8 | 703 | dcf_status.DCFsample600 = (dcfSignalIn); |
star297 | 2:1eac3ea8c6e8 | 704 | if (dcfSignalIn) {dcf_error = 1;} |
star297 | 1:793dbd6d6498 | 705 | break;} |
star297 | 1:793dbd6d6498 | 706 | } |
star297 | 1:793dbd6d6498 | 707 | if (dcf_status.DCFsample50==0 && dcf_sec<58){sync=0;} |
star297 | 1:793dbd6d6498 | 708 | |
star297 | 1:793dbd6d6498 | 709 | if (interrupt_counter==1){ |
star297 | 2:1eac3ea8c6e8 | 710 | if (dcfSignalIn){nosignal=1;} |
star297 | 1:793dbd6d6498 | 711 | else nosignal++; |
star297 | 1:793dbd6d6498 | 712 | if (nosignal>5){nosignal=2; SignalStatus = 5;signal_error=1;} |
star297 | 1:793dbd6d6498 | 713 | } |
star297 | 0:94bf5ec759da | 714 | |
star297 | 1:793dbd6d6498 | 715 | if (interrupt_counter==15){ |
star297 | 1:793dbd6d6498 | 716 | if (!dcf_status.DCFsample150 && !dcf_status.DCFsample50) {sync=0;start=1;} |
star297 | 1:793dbd6d6498 | 717 | } |
star297 | 1:793dbd6d6498 | 718 | if (interrupt_counter==18){ |
star297 | 1:793dbd6d6498 | 719 | if (dcf_error==1) {error_count++;dcf_error=0;} |
star297 | 1:793dbd6d6498 | 720 | if (error_count > 3 && sync==1) {error_count = 0;signal_error=1;} |
star297 | 1:793dbd6d6498 | 721 | } |
star297 | 0:94bf5ec759da | 722 | |
star297 | 1:793dbd6d6498 | 723 | } // End of ISR |
star297 | 1:793dbd6d6498 | 724 |