DCF77 atomic clock using 1602 type LCD, sets MCU RTC and goes into Deep Sleep, waking every second to update LCD time. Re acquires DCF time every 24 hours, tests for available signal and indicates DCF pulse width in millisecond's. Time zone can be changed at the beginning of the code. If no signal detected, the program sleeps updating the display with the current RTC time then try's again in 1 hour. The RTC will remain accurate until power is cycled where it will reset the RTC registers. Hard reset will not effect RTC registers. Tested using a project MCU board, MCU Deep Sleep power is 3uA, 1602 LCD is 900uA. Wake up takes around 12mS to update display time every second. The current FRDM board has a PCB track issue that does not allow the power to be monitored.

Dependencies:   TextLCD WakeUp mbed

Committer:
star297
Date:
Wed Feb 26 21:39:57 2014 +0000
Revision:
0:f40db885ccfb
Initial version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
star297 0:f40db885ccfb 1 #include "mbed.h"
star297 0:f40db885ccfb 2 #include "TextLCD.h"
star297 0:f40db885ccfb 3 #include "WakeUp.h"
star297 0:f40db885ccfb 4
star297 0:f40db885ccfb 5 TextLCD lcd(PTB6, PTA12, PTB5, PTA11, PTB1, PTB2, TextLCD::LCD20x4); // rs, e, d4, d5, d6, d7
star297 0:f40db885ccfb 6 InterruptIn dcfSignalIn(PTB0); //DCF signal input,conection of output non-inverting module
star297 0:f40db885ccfb 7
star297 0:f40db885ccfb 8 // Include the definition for required Time Zone
star297 0:f40db885ccfb 9 #define TimeZone 1 //GMT
star297 0:f40db885ccfb 10 //#define TimeZine 2 //CET
star297 0:f40db885ccfb 11 //#define TimeZone 3 //EET
star297 0:f40db885ccfb 12
star297 0:f40db885ccfb 13 DigitalOut dcfLED(LED1);
star297 0:f40db885ccfb 14 DigitalOut WakeLED(LED3);
star297 0:f40db885ccfb 15
star297 0:f40db885ccfb 16 //variable
star297 0:f40db885ccfb 17 char paritycheck,paritym,parityu,paritydmy;
star297 0:f40db885ccfb 18 char testu,testm,testdmy;
star297 0:f40db885ccfb 19 char minh,minl;
star297 0:f40db885ccfb 20 char hourh,hourl;
star297 0:f40db885ccfb 21 char day,dayh,dayl;
star297 0:f40db885ccfb 22 char monthh,monthl;
star297 0:f40db885ccfb 23 char yearh,yearl;
star297 0:f40db885ccfb 24 char summertime;
star297 0:f40db885ccfb 25 char buffer[32];
star297 0:f40db885ccfb 26 int interrupt_counter = 0;
star297 0:f40db885ccfb 27 int hour = 0;
star297 0:f40db885ccfb 28 int minute = 0;
star297 0:f40db885ccfb 29 int second = 0;
star297 0:f40db885ccfb 30 int dayofweek = 6;
star297 0:f40db885ccfb 31 int dayofmonth = 1;
star297 0:f40db885ccfb 32 int month = 1;
star297 0:f40db885ccfb 33 int year = 0;
star297 0:f40db885ccfb 34 int nosignal,signal_error,start,dcf_sec,sync,RTCset,getDCF;
star297 0:f40db885ccfb 35 int p_minute,p_hour,p_dayofweek,p_dayofmonth,p_month,p_year;
star297 0:f40db885ccfb 36 int dcf_error,error_count,dcf_good,signal_good,ISRlock;
star297 0:f40db885ccfb 37 int n,loop;
star297 0:f40db885ccfb 38 int dcf_array[61];
star297 0:f40db885ccfb 39
star297 0:f40db885ccfb 40 typedef unsigned char byte;
star297 0:f40db885ccfb 41
star297 0:f40db885ccfb 42 //makro,s
star297 0:f40db885ccfb 43 void dcfISR(),dcf_check(),checkSIGNAL(),signal();
star297 0:f40db885ccfb 44 void parity_calc();
star297 0:f40db885ccfb 45 void RTC_reset(),RTC_set();
star297 0:f40db885ccfb 46 void Displayloop();
star297 0:f40db885ccfb 47 void setTIME();
star297 0:f40db885ccfb 48 void restart();
star297 0:f40db885ccfb 49 void dcfIRQ();
star297 0:f40db885ccfb 50
star297 0:f40db885ccfb 51 Ticker Ticker50ms;
star297 0:f40db885ccfb 52 Timer check;
star297 0:f40db885ccfb 53 #define ZERO 1e-10
star297 0:f40db885ccfb 54 #define isBetween(A, B, C) (((A-B) > -ZERO) && ((A-C) < ZERO))
star297 0:f40db885ccfb 55
star297 0:f40db885ccfb 56 struct status {
star297 0:f40db885ccfb 57 bool is_leap; // Leap year flag (NOT actually transmitted but calculated)
star297 0:f40db885ccfb 58 bool sample50; // dcf sample at 50mS into the start of the second
star297 0:f40db885ccfb 59 bool sample150; // dcf sample at 150mS into the start of the second
star297 0:f40db885ccfb 60 int second; // dcf second (NOT actually transmitted but calculated)
star297 0:f40db885ccfb 61 }
star297 0:f40db885ccfb 62 dcf_status;
star297 0:f40db885ccfb 63
star297 0:f40db885ccfb 64 struct dcf {
star297 0:f40db885ccfb 65 char dut1; // DUT1 (0.1 - 0.8)
star297 0:f40db885ccfb 66 char dut2; // DUT2 (-0.1 - -0.8)
star297 0:f40db885ccfb 67 char year; // Year (00 - 99)
star297 0:f40db885ccfb 68 char month; // Month (01 - 12)
star297 0:f40db885ccfb 69 char dayofmonth; // Day of month (01 - 31)
star297 0:f40db885ccfb 70 char dayofweek; // Day of week (Sunday=0 Saturday=6)
star297 0:f40db885ccfb 71 char hour; // Hour (00 - 23)
star297 0:f40db885ccfb 72 char minute; // Minute (00 - 59)
star297 0:f40db885ccfb 73 } dcf_time;
star297 0:f40db885ccfb 74
star297 0:f40db885ccfb 75 struct tm t;
star297 0:f40db885ccfb 76
star297 0:f40db885ccfb 77 // Various text strings used in display
star297 0:f40db885ccfb 78 char weekDayName[7][4] = {"Sun","Mon","Tue","Wed","Thu", "Fri","Sat"};
star297 0:f40db885ccfb 79 char monthName[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
star297 0:f40db885ccfb 80 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 0:f40db885ccfb 81 char leapText[2][4] = {" ", "L"};
star297 0:f40db885ccfb 82 char dstSymbol[2][3] = {"WT", "ST"};
star297 0:f40db885ccfb 83
star297 0:f40db885ccfb 84 byte maxDay(byte year, byte month) // Return the maximum day in month for a given month & year
star297 0:f40db885ccfb 85 {
star297 0:f40db885ccfb 86 byte lastday, leap;
star297 0:f40db885ccfb 87 leap = year%4 == 0 && year%100 !=0 || year%400 == 0;
star297 0:f40db885ccfb 88 lastday = MAX_DAY[month - 1];
star297 0:f40db885ccfb 89 dcf_status.is_leap = leap > 0 ? 1 : 0;
star297 0:f40db885ccfb 90 if ((leap > 0) && (month == 2))
star297 0:f40db885ccfb 91 lastday++;
star297 0:f40db885ccfb 92 return lastday;
star297 0:f40db885ccfb 93 }
star297 0:f40db885ccfb 94
star297 0:f40db885ccfb 95 int dayOfWeek(int y, int m, int d) // 0 = Sunday
star297 0:f40db885ccfb 96 {
star297 0:f40db885ccfb 97 static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
star297 0:f40db885ccfb 98 y -= m < 3;
star297 0:f40db885ccfb 99 return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
star297 0:f40db885ccfb 100 }
star297 0:f40db885ccfb 101
star297 0:f40db885ccfb 102 int main()
star297 0:f40db885ccfb 103 {
star297 0:f40db885ccfb 104 lcd.printf("DCF77 clock\n");
star297 0:f40db885ccfb 105 lcd.printf("Checking Signal");
star297 0:f40db885ccfb 106 WakeLED=1;dcfLED=1;
star297 0:f40db885ccfb 107 WakeUp::calibrate();
star297 0:f40db885ccfb 108 wait(1);
star297 0:f40db885ccfb 109 checkSIGNAL();dcfSignalIn.rise(NULL);lcd.cls();
star297 0:f40db885ccfb 110 if (signal_good==0) {
star297 0:f40db885ccfb 111 lcd.printf("No Signal!!\n");
star297 0:f40db885ccfb 112 lcd.printf("Retry in 1 hour");
star297 0:f40db885ccfb 113 wait(2);lcd.cls();n=3600;
star297 0:f40db885ccfb 114 getDCF=0;
star297 0:f40db885ccfb 115 }
star297 0:f40db885ccfb 116 else{
star297 0:f40db885ccfb 117 lcd.printf("DCF detected\n");
star297 0:f40db885ccfb 118 lcd.printf("Setting RTC");
star297 0:f40db885ccfb 119 wait(2);lcd.cls();
star297 0:f40db885ccfb 120 restart();lcd.cls();
star297 0:f40db885ccfb 121 }
star297 0:f40db885ccfb 122
star297 0:f40db885ccfb 123 while (true){
star297 0:f40db885ccfb 124
star297 0:f40db885ccfb 125 while (getDCF==1) { // Get dcf time and set cpu RTC
star297 0:f40db885ccfb 126 if (loop==0) {
star297 0:f40db885ccfb 127 Displayloop(); // update display every 50mS
star297 0:f40db885ccfb 128 loop=1;
star297 0:f40db885ccfb 129 }
star297 0:f40db885ccfb 130 }
star297 0:f40db885ccfb 131
star297 0:f40db885ccfb 132 while (getDCF==0) { // Deep Sleep mode, Wake and update display time every second
star297 0:f40db885ccfb 133 WakeLED=0;
star297 0:f40db885ccfb 134 time_t seconds = time(NULL);
star297 0:f40db885ccfb 135 strftime(buffer, 32, "%I:%M:%S %p", localtime(&seconds));
star297 0:f40db885ccfb 136 lcd.locate(0,0);lcd.printf("RTC %s", buffer);
star297 0:f40db885ccfb 137 strftime(buffer, 32, "%a %d %b %Y ", localtime(&seconds));
star297 0:f40db885ccfb 138 lcd.locate(0,1);lcd.printf("%s", buffer);
star297 0:f40db885ccfb 139 WakeLED=1;
star297 0:f40db885ccfb 140 n--;if (n==0) {getDCF=1;} // Restart and Synchronise DCF every 1 or 24 hours
star297 0:f40db885ccfb 141 WakeUp::set(1);
star297 0:f40db885ccfb 142 deepsleep();
star297 0:f40db885ccfb 143 }
star297 0:f40db885ccfb 144 checkSIGNAL();dcfSignalIn.rise(NULL);lcd.cls();
star297 0:f40db885ccfb 145 if (signal_good==1) {restart();}
star297 0:f40db885ccfb 146 else {n=3600;getDCF=0;}
star297 0:f40db885ccfb 147 }
star297 0:f40db885ccfb 148 }
star297 0:f40db885ccfb 149
star297 0:f40db885ccfb 150 void Displayloop()
star297 0:f40db885ccfb 151 {
star297 0:f40db885ccfb 152 if (interrupt_counter == 0) {
star297 0:f40db885ccfb 153 if (dcf_good == 1 && dcf_sec == 2) {
star297 0:f40db885ccfb 154 RTC_set(); // set cpu RTC if good data
star297 0:f40db885ccfb 155 }
star297 0:f40db885ccfb 156 time_t seconds = time(NULL);
star297 0:f40db885ccfb 157 strftime(buffer, 32, "%a %d %H:%M:%S", localtime(&seconds));
star297 0:f40db885ccfb 158 lcd.locate(0,1);lcd.printf("%s", buffer);
star297 0:f40db885ccfb 159 }
star297 0:f40db885ccfb 160
star297 0:f40db885ccfb 161 if (interrupt_counter==3){
star297 0:f40db885ccfb 162 if (start==1){
star297 0:f40db885ccfb 163 dcf_array[dcf_sec]=dcf_status.sample150;
star297 0:f40db885ccfb 164 if (dcf_sec==0){
star297 0:f40db885ccfb 165 dcf_array[58] = 0;
star297 0:f40db885ccfb 166 }
star297 0:f40db885ccfb 167 }
star297 0:f40db885ccfb 168 }
star297 0:f40db885ccfb 169
star297 0:f40db885ccfb 170 if (interrupt_counter==5) {
star297 0:f40db885ccfb 171 if (signal_error==1){
star297 0:f40db885ccfb 172 Ticker50ms.detach();dcfSignalIn.rise(NULL);getDCF=0;lcd.cls();
star297 0:f40db885ccfb 173 lcd.printf("10 Signal errors\n");
star297 0:f40db885ccfb 174 lcd.printf("detected,restart");
star297 0:f40db885ccfb 175 wait(2);
star297 0:f40db885ccfb 176 lcd.cls();restart();} // Restart DCF ISR if signal 10 errors detected
star297 0:f40db885ccfb 177 }
star297 0:f40db885ccfb 178 }
star297 0:f40db885ccfb 179
star297 0:f40db885ccfb 180 void setTIME() // Set time variables with Partity data
star297 0:f40db885ccfb 181 {
star297 0:f40db885ccfb 182 second = dcf_sec;
star297 0:f40db885ccfb 183 minute=p_minute;
star297 0:f40db885ccfb 184 hour=p_hour;
star297 0:f40db885ccfb 185 dayofweek=p_dayofweek;
star297 0:f40db885ccfb 186 dayofmonth=p_dayofmonth;
star297 0:f40db885ccfb 187 month=p_month;
star297 0:f40db885ccfb 188 year=p_year;
star297 0:f40db885ccfb 189 }
star297 0:f40db885ccfb 190
star297 0:f40db885ccfb 191 void checkSIGNAL()
star297 0:f40db885ccfb 192 {
star297 0:f40db885ccfb 193 n=10;dcfSignalIn.rise(signal);
star297 0:f40db885ccfb 194 while(n>0){
star297 0:f40db885ccfb 195 if (ISRlock==0){
star297 0:f40db885ccfb 196 lcd.locate(0,0);
star297 0:f40db885ccfb 197 if (signal_good==1) {lcd.printf ("Signal Good %d ",n);}
star297 0:f40db885ccfb 198 else {lcd.printf("No Signal %d ",n);}
star297 0:f40db885ccfb 199 signal_good=0;
star297 0:f40db885ccfb 200 }
star297 0:f40db885ccfb 201 wait(1);
star297 0:f40db885ccfb 202 n--;
star297 0:f40db885ccfb 203 }
star297 0:f40db885ccfb 204 }
star297 0:f40db885ccfb 205 void signal()
star297 0:f40db885ccfb 206 {
star297 0:f40db885ccfb 207 check.start();ISRlock=1,signal_good=1;
star297 0:f40db885ccfb 208 while (dcfSignalIn==1){};
star297 0:f40db885ccfb 209 check.stop();
star297 0:f40db885ccfb 210 lcd.locate(0,1);lcd.printf ("DCF pulse %3.f mS",(check.read()*1000));
star297 0:f40db885ccfb 211 check.reset();ISRlock=0;
star297 0:f40db885ccfb 212 }
star297 0:f40db885ccfb 213
star297 0:f40db885ccfb 214 void restart()
star297 0:f40db885ccfb 215 {
star297 0:f40db885ccfb 216 hour = 0;minute = 0,second = 0,dayofweek = 6;dayofmonth = 1;month = 1;year = 0;
star297 0:f40db885ccfb 217 signal_error=0;sync=0;getDCF=1;RTCset=0;error_count=0;
star297 0:f40db885ccfb 218 start=0;dcf_sec=0;dcf_good=0;
star297 0:f40db885ccfb 219 dcfSignalIn.rise(dcfIRQ); //Trigger dcfISR on rising edge of DCF pulse
star297 0:f40db885ccfb 220 while(dcfSignalIn == 1){}
star297 0:f40db885ccfb 221 while(dcfSignalIn == 0){}
star297 0:f40db885ccfb 222 interrupt_counter = 0;sync=1;dcf_sec=0;
star297 0:f40db885ccfb 223 }
star297 0:f40db885ccfb 224
star297 0:f40db885ccfb 225 void dcfIRQ(void) // DCF Signal Interrupt to synchronise Ticker ISR
star297 0:f40db885ccfb 226 {
star297 0:f40db885ccfb 227 if (sync==0){
star297 0:f40db885ccfb 228 Ticker50ms.attach(& dcfISR, .05);
star297 0:f40db885ccfb 229 interrupt_counter = 0;sync=1;dcf_sec=0;
star297 0:f40db885ccfb 230 }
star297 0:f40db885ccfb 231 }
star297 0:f40db885ccfb 232
star297 0:f40db885ccfb 233 void dcfISR() //Interrupt service routine (ISR) that is called every 50ms
star297 0:f40db885ccfb 234 {
star297 0:f40db885ccfb 235 interrupt_counter++;loop=0;
star297 0:f40db885ccfb 236
star297 0:f40db885ccfb 237 dcfLED = !dcfSignalIn; // Show dcf Signal state on LED
star297 0:f40db885ccfb 238
star297 0:f40db885ccfb 239 if (interrupt_counter == 20) { // 50mS x 20 = 1000mS = 1 Second
star297 0:f40db885ccfb 240 interrupt_counter = 0; second++;
star297 0:f40db885ccfb 241 if (start==1) {dcf_sec++;}
star297 0:f40db885ccfb 242 }
star297 0:f40db885ccfb 243 lcd.locate(0,0); lcd.printf("%2d:%02d:%02d.%d Dcf%02d",hour,minute,second,interrupt_counter*5/10,dcf_sec);
star297 0:f40db885ccfb 244
star297 0:f40db885ccfb 245 if (dcf_sec==59) {dcf_check();}
star297 0:f40db885ccfb 246 if (dcf_good==1 && dcf_sec==1) {setTIME();}
star297 0:f40db885ccfb 247 if (second >= 60) {++minute;second -=60;}
star297 0:f40db885ccfb 248 if (minute >= 60) {++hour;minute-=60;}
star297 0:f40db885ccfb 249 if (hour >= 24) {hour -=24;++dayofweek;++dayofmonth;}
star297 0:f40db885ccfb 250 if (dayofweek > 6) dayofweek = 0;
star297 0:f40db885ccfb 251 if (dayofmonth > maxDay(year, month)) {dayofmonth = 1;month++;}
star297 0:f40db885ccfb 252 if (month > 12) {month = 1;year++;}
star297 0:f40db885ccfb 253 if (year > 99) year = 1;
star297 0:f40db885ccfb 254 switch (interrupt_counter) {
star297 0:f40db885ccfb 255 case 1:{ // 50mS after start of second pulse
star297 0:f40db885ccfb 256 dcf_status.sample50 = (dcfSignalIn);
star297 0:f40db885ccfb 257 break;}
star297 0:f40db885ccfb 258 case 3: { // 150mS after start of second pulse (bit "1" dcf Data)
star297 0:f40db885ccfb 259 dcf_status.sample150 = (dcfSignalIn);
star297 0:f40db885ccfb 260 if (!dcf_status.sample150 && !dcf_status.sample50) {sync=0;start=1;} // Reset Ticker ISR to line up with 59th second pulse
star297 0:f40db885ccfb 261 break;}
star297 0:f40db885ccfb 262 case 6: { // 300mS after start of second (signal error if true)
star297 0:f40db885ccfb 263 if (dcfSignalIn) {dcf_error = 1;}
star297 0:f40db885ccfb 264 break;}
star297 0:f40db885ccfb 265 case 10: { // 500mS after start of second (signal error if true)
star297 0:f40db885ccfb 266 if (dcfSignalIn) {dcf_error = 1;}
star297 0:f40db885ccfb 267 break;}
star297 0:f40db885ccfb 268 case 15: { // 750mS after start of second (signal error if true)
star297 0:f40db885ccfb 269 if (dcfSignalIn) {dcf_error = 1;}
star297 0:f40db885ccfb 270 break;}
star297 0:f40db885ccfb 271 }
star297 0:f40db885ccfb 272 if (dcf_error==1) {error_count++;dcf_error=0;}
star297 0:f40db885ccfb 273 if (error_count > 9 && sync==1) {error_count = 0;signal_error=1;}
star297 0:f40db885ccfb 274 } // End of ISR
star297 0:f40db885ccfb 275
star297 0:f40db885ccfb 276 void dcf_check()
star297 0:f40db885ccfb 277 {
star297 0:f40db885ccfb 278 parity_calc(); // Get Parity data and test if correct
star297 0:f40db885ccfb 279 paritycheck= testu or testm or testdmy;
star297 0:f40db885ccfb 280 if (year>99) paritycheck=1;
star297 0:f40db885ccfb 281 if (month>12) paritycheck=1;
star297 0:f40db885ccfb 282 if (day>31) paritycheck=1;
star297 0:f40db885ccfb 283 if (hour>23) paritycheck=1;
star297 0:f40db885ccfb 284 if (minute>59) paritycheck=1;
star297 0:f40db885ccfb 285 if (paritycheck) {
star297 0:f40db885ccfb 286 dcf_good = 0;
star297 0:f40db885ccfb 287 }
star297 0:f40db885ccfb 288 else {
star297 0:f40db885ccfb 289 dcf_good = 1;
star297 0:f40db885ccfb 290 }
star297 0:f40db885ccfb 291 }
star297 0:f40db885ccfb 292
star297 0:f40db885ccfb 293 void RTC_set() // Set cpu RTC to required Time Zone
star297 0:f40db885ccfb 294 {
star297 0:f40db885ccfb 295 t.tm_sec = (second); // 0-59
star297 0:f40db885ccfb 296 t.tm_min = (minute); // 0-59
star297 0:f40db885ccfb 297 t.tm_hour = (hour); // 0-23
star297 0:f40db885ccfb 298 t.tm_mday = (dayofmonth); // 1-31
star297 0:f40db885ccfb 299 t.tm_mon = (month-1); // 0-11 DCF "0" = Jan, -1 added for Mbed RCT clock format
star297 0:f40db885ccfb 300 t.tm_year = ((year)+100); // year since 1900, current DCF year + 100 + 1900 = correct year
star297 0:f40db885ccfb 301 #if (TimeZone == 1)
star297 0:f40db885ccfb 302 set_time (mktime(&t)-3600); // set CPU RTC clock to DCF time zone -3600 for GMT
star297 0:f40db885ccfb 303 #elif (TimeZone==2)
star297 0:f40db885ccfb 304 set_time (mktime(&t)); // set CPU RTC clock to DCF time zone
star297 0:f40db885ccfb 305 #elif (TimeZone==3)
star297 0:f40db885ccfb 306 set_time (mktime(&t)+3600); // set CPU RTC clock to DCF time zone +3600 for EET
star297 0:f40db885ccfb 307 #endif
star297 0:f40db885ccfb 308 RTCset=1;getDCF=0;Ticker50ms.detach();dcfSignalIn.rise(NULL);dcfLED=1;lcd.cls();
star297 0:f40db885ccfb 309 lcd.printf("RTC set, run\n");
star297 0:f40db885ccfb 310 lcd.printf("Deep Sleep Mode");
star297 0:f40db885ccfb 311 n=3600*24;
star297 0:f40db885ccfb 312 wait(3);
star297 0:f40db885ccfb 313 }
star297 0:f40db885ccfb 314
star297 0:f40db885ccfb 315 void parity_calc()
star297 0:f40db885ccfb 316 {
star297 0:f40db885ccfb 317 //calculate summer/winter time----------------------------------------------------------------------
star297 0:f40db885ccfb 318 summertime = dcf_array[17] & 1;
star297 0:f40db885ccfb 319 //calculate hour--------------------------------------------------------------------------------------
star297 0:f40db885ccfb 320 hourh = dcf_array[34] * 20 + dcf_array[33] * 10;
star297 0:f40db885ccfb 321 hourl = dcf_array[32] * 8 + dcf_array[31] * 4 + dcf_array[30] * 2 + dcf_array[29] * 1;
star297 0:f40db885ccfb 322 p_hour = hourh + hourl;
star297 0:f40db885ccfb 323 //calculate minutes------------------------------------------------------------------------------------
star297 0:f40db885ccfb 324 minl = dcf_array[24] * 8 + dcf_array[23] * 4 + dcf_array[22] * 2 + dcf_array[21] * 1;
star297 0:f40db885ccfb 325 minh = dcf_array[27] * 40 + dcf_array[26] * 20 +dcf_array[25] * 10;
star297 0:f40db885ccfb 326 p_minute = minh + minl;
star297 0:f40db885ccfb 327 //calculate day of week--------------------------------------------------------------------------------
star297 0:f40db885ccfb 328 p_dayofweek = dcf_array[44] * 4 +dcf_array[43] * 2 + dcf_array[42] * 1;
star297 0:f40db885ccfb 329 //calculate day----------------------------------------------------------------------------------------
star297 0:f40db885ccfb 330 dayl = dcf_array[39] * 8 + dcf_array[38] * 4 + dcf_array[37] * 2 + dcf_array[36] * 1;
star297 0:f40db885ccfb 331 dayh = dcf_array[41] * 20 + dcf_array[40] * 10;
star297 0:f40db885ccfb 332 p_dayofmonth=dayh+dayl;
star297 0:f40db885ccfb 333 //calculate month--------------------------------------------------------------------------------------
star297 0:f40db885ccfb 334 monthh = dcf_array[49] * 10;
star297 0:f40db885ccfb 335 monthl = dcf_array[48] * 8 + dcf_array[47] * 4 + dcf_array[46] * 2 + dcf_array[45] * 1;
star297 0:f40db885ccfb 336 p_month = monthh +monthl;
star297 0:f40db885ccfb 337 //calculate year---------------------------------------------------------------------------------------
star297 0:f40db885ccfb 338 yearh = dcf_array[57] * 80 + dcf_array[56] * 40 + dcf_array[55] * 20 + dcf_array[54] * 10;
star297 0:f40db885ccfb 339 yearl = dcf_array[53] * 8 +dcf_array[52] * 4 + dcf_array[51] * 2 + dcf_array[50] * 1;
star297 0:f40db885ccfb 340 p_year = yearh+yearl;
star297 0:f40db885ccfb 341 //calculate parity
star297 0:f40db885ccfb 342 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 0:f40db885ccfb 343 parityu =dcf_array[29] + dcf_array[30] + dcf_array[31] + dcf_array[32] + dcf_array[33] + dcf_array[34] + dcf_array[35];
star297 0:f40db885ccfb 344 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 0:f40db885ccfb 345 //test parity------------------------------
star297 0:f40db885ccfb 346 testu=parityu & 1;
star297 0:f40db885ccfb 347 testm=paritym & 1;
star297 0:f40db885ccfb 348 testdmy=paritydmy & 1;
star297 0:f40db885ccfb 349 }
star297 0:f40db885ccfb 350