From: b Date: Fri, 28 Aug 2015 09:38:22 +0000 (+0200) Subject: 4 digit year, show version X-Git-Tag: v1.2 X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=90358c50d6e498e627f6853893b3dae09b4ba5b1;p=staf%2Fstaf 4 digit year, show version --- diff --git a/definitions.h b/definitions.h index 1f5f1b8..825ab1b 100644 --- a/definitions.h +++ b/definitions.h @@ -1,68 +1,69 @@ -//RTC commands: -#define RTC_EEREAD 0x03 -#define RTC_EEWRITE 0x02 -#define RTC_EEWRDI 0x04 -#define RTC_EEWREN 0x06 -#define RTC_SRREAD 0x05 -#define RTC_SRWRITE 0x01 -#define RTC_READ 0x13 -#define RTC_WRITE 0x12 -#define RTC_UNLOCK 0x14 -#define RTC_IDWRITE 0x32 -#define RTC_IDREAD 0x33 -#define RTC_CLRRAM 0x54 - -//SPI function flags: -#define ADDRFLAG 0x01 -#define WRITEFLAG 0x02 -#define READFLAG 0x04 - -//7 segment display - -#define SEG_A 0xdf -#define SEG_B 0xef // aaaa -#define SEG_C 0xbf // f b -#define SEG_D 0x7f // f b -#define SEG_E 0xfd //hh gggg -#define SEG_F 0xfb // e c -#define SEG_G 0xf7 // e c -#define SEG_H 0xfe // dddd - -#define SYMB_0 (SEG_A & SEG_B & SEG_C & SEG_D & SEG_E & SEG_F ) -#define SYMB_1 ( SEG_B & SEG_C ) -#define SYMB_2 (SEG_A & SEG_B & SEG_D & SEG_E & SEG_G) -#define SYMB_3 (SEG_A & SEG_B & SEG_C & SEG_D & SEG_G) -#define SYMB_4 ( SEG_B & SEG_C & SEG_F & SEG_G) -#define SYMB_5 (SEG_A & SEG_C & SEG_D & SEG_F & SEG_G) -#define SYMB_6 (SEG_A & SEG_C & SEG_D & SEG_E & SEG_F & SEG_G) -#define SYMB_7 (SEG_A & SEG_B & SEG_C ) -#define SYMB_8 (SEG_A & SEG_B & SEG_C & SEG_D & SEG_E & SEG_F & SEG_G) -#define SYMB_9 (SEG_A & SEG_B & SEG_C & SEG_F & SEG_G) -#define SYMB_A (SEG_A & SEG_B & SEG_C & SEG_E & SEG_F & SEG_G) -#define SYMB_B ( SEG_C & SEG_D & SEG_E & SEG_F & SEG_G) -#define SYMB_C ( SEG_D & SEG_E & SEG_G) -#define SYMB_D ( SEG_B & SEG_C & SEG_D & SEG_E & SEG_G) -#define SYMB_E (SEG_A & SEG_D & SEG_E & SEG_F & SEG_G) -#define SYMB_F (SEG_A & SEG_E & SEG_F & SEG_G) -#define SYMB_NUL (0xFF) -#define SYMB_o (SEG_A & SEG_B & SEG_F & SEG_G) -#define SYMB_n (SEG_A & SEG_B & SEG_F ) -#define SYMB_g (SEG_A & SEG_B & SEG_C & SEG_D & SEG_F & SEG_G) -#define SYMB_MIN ( SEG_G) -#define SYMB_DOT (SEG_H) - -//operation modes -#define MODE_INIT 0 -#define MODE_TIME 1 -#define MODE_SETTIME 2 -#define MODE_SETALARM 3 -#define MODE_ALARM 4 -#define MODE_DATE 5 -#define MODE_SETDATE 6 -#define MODE_SETYEAR 7 -#define MODE_COUNTUP 8 -#define MODE_SETCOUNTDOWN 9 -#define MODE_COUNTDOWN 10 -#define MODE_CALIBRATE 11 - +//RTC commands: +#define RTC_EEREAD 0x03 +#define RTC_EEWRITE 0x02 +#define RTC_EEWRDI 0x04 +#define RTC_EEWREN 0x06 +#define RTC_SRREAD 0x05 +#define RTC_SRWRITE 0x01 +#define RTC_READ 0x13 +#define RTC_WRITE 0x12 +#define RTC_UNLOCK 0x14 +#define RTC_IDWRITE 0x32 +#define RTC_IDREAD 0x33 +#define RTC_CLRRAM 0x54 + +//SPI function flags: +#define ADDRFLAG 0x01 +#define WRITEFLAG 0x02 +#define READFLAG 0x04 + +//7 segment display + +#define SEG_A 0xdf +#define SEG_B 0xef // aaaa +#define SEG_C 0xbf // f b +#define SEG_D 0x7f // f b +#define SEG_E 0xfd //hh gggg +#define SEG_F 0xfb // e c +#define SEG_G 0xf7 // e c +#define SEG_H 0xfe // dddd + +#define SYMB_0 (SEG_A & SEG_B & SEG_C & SEG_D & SEG_E & SEG_F ) +#define SYMB_1 ( SEG_B & SEG_C ) +#define SYMB_2 (SEG_A & SEG_B & SEG_D & SEG_E & SEG_G) +#define SYMB_3 (SEG_A & SEG_B & SEG_C & SEG_D & SEG_G) +#define SYMB_4 ( SEG_B & SEG_C & SEG_F & SEG_G) +#define SYMB_5 (SEG_A & SEG_C & SEG_D & SEG_F & SEG_G) +#define SYMB_6 (SEG_A & SEG_C & SEG_D & SEG_E & SEG_F & SEG_G) +#define SYMB_7 (SEG_A & SEG_B & SEG_C ) +#define SYMB_8 (SEG_A & SEG_B & SEG_C & SEG_D & SEG_E & SEG_F & SEG_G) +#define SYMB_9 (SEG_A & SEG_B & SEG_C & SEG_F & SEG_G) +#define SYMB_A (SEG_A & SEG_B & SEG_C & SEG_E & SEG_F & SEG_G) +#define SYMB_B ( SEG_C & SEG_D & SEG_E & SEG_F & SEG_G) +#define SYMB_C ( SEG_D & SEG_E & SEG_G) +#define SYMB_D ( SEG_B & SEG_C & SEG_D & SEG_E & SEG_G) +#define SYMB_E (SEG_A & SEG_D & SEG_E & SEG_F & SEG_G) +#define SYMB_F (SEG_A & SEG_E & SEG_F & SEG_G) +#define SYMB_NUL (0xFF) +#define SYMB_o (SEG_A & SEG_B & SEG_F & SEG_G) +#define SYMB_n (SEG_A & SEG_B & SEG_F ) +#define SYMB_g (SEG_A & SEG_B & SEG_C & SEG_D & SEG_F & SEG_G) +#define SYMB_MIN ( SEG_G) +#define SYMB_DOT (SEG_H) + +//operation modes +#define MODE_INIT 0 +#define MODE_TIME 1 +#define MODE_SETTIME 2 +#define MODE_SETALARM 3 +#define MODE_ALARM 4 +#define MODE_DATE 5 +#define MODE_SETDATE 6 +#define MODE_SETYEAR 7 +#define MODE_COUNTUP 8 +#define MODE_SETCOUNTDOWN 9 +#define MODE_COUNTDOWN 10 +#define MODE_CALIBRATE 11 +#define MODE_SHOWVERSION 12 + #define ALARMVALUE 0xa5 \ No newline at end of file diff --git a/main.c b/main.c index 4869f29..4264315 100644 --- a/main.c +++ b/main.c @@ -9,6 +9,8 @@ unsigned char leap; unsigned char settime[3]; unsigned char mode; unsigned char alarm[3]; +unsigned char lastcdn[2]; +unsigned char lastyear[2]; unsigned char digit; unsigned char changed; unsigned char run; @@ -156,7 +158,7 @@ __interrupt void P2_ISR() time[7]=inbuf[7];//year leap=inbuf[6]&0x20; - spi(RTC_READ,0x0f,inbuf,outbuf,1); + spi(RTC_READ,0x0f,inbuf,outbuf,1); // <- because of RTC bug (?) if(!((time[2]^alarm[1])|(time[3]^alarm[2])) && alarm[0]) { mode=MODE_ALARM; @@ -197,6 +199,20 @@ __interrupt void P2_ISR() //P2DIR&= ~0x40; //P2SEL&= ~0x40; } + + if (time[7]!=lastyear[0]) + { + if(time[7]0x19)?0x03:0x09)))) + if((settime[digit&0x02?2:1]&((digit&0x01)?0xf0:0x0f))<(digit==1?((mode==MODE_SETYEAR)?0x90:0x50):(digit==3?((mode==MODE_SETCOUNTDOWN||mode==MODE_SETYEAR)?0x90:0x20):((mode!=MODE_SETCOUNTDOWN&&mode!=MODE_SETYEAR&&digit==2&&settime[2]>0x19)?0x03:0x09)))) settime[digit&0x02?2:1]+=((digit&0x01)?0x10:0x01); else settime[digit&0x02?2:1]&=((digit&0x01)?0x0f:0xf0); break; - case MODE_SETYEAR: - changed=1; - if(digit) - { - if(settime[0]<0x90) - settime[0]+=0x10; - else - settime[0]&=0x0f; - } - else - { - if((settime[0]&0x0f)<0x09) - ++settime[0]; - else - settime[0]&=0xf0; - } - break; + //case MODE_SETYEAR: + // changed=1; + // if(digit) + // { + // if(settime[0]<0x90) + // settime[0]+=0x10; + // else + // settime[0]&=0x0f; + // } + // else + // { + // if((settime[0]&0x0f)<0x09) + // ++settime[0]; + // else + // settime[0]&=0xf0; + // } + // break; case MODE_SETDATE: changed=1; switch (digit) @@ -466,10 +500,11 @@ __interrupt void P2_ISR() break; case MODE_DATE: mode=MODE_SETYEAR; - digit=1; + digit=3; changed=0; - settime[0]=time[7]; + settime[1]=time[7]; + settime[2]=lastyear[1]; break; case MODE_TIME: mode=MODE_SETALARM; @@ -501,17 +536,18 @@ __interrupt void P2_ISR() case MODE_SETTIME: case MODE_SETALARM: case MODE_SETCOUNTDOWN: - dispvalue[0]=(symbol[settime[1]&0x0f]|((digit!=0 && (time[1]&0x01))?SYMB_NUL:SYMB_8))&(((((time[1]+0x01)&0x02)^((time[1]&0x10)>>3))&&mode==MODE_SETCOUNTDOWN)?SYMB_NUL:SYMB_DOT); - dispvalue[1]=(symbol[(settime[1]&0xf0)>>4]|((digit!=1 && (time[1]&0x01))?SYMB_NUL:SYMB_8))&((((time[1]&0x02)^((time[1]&0x10)>>3))&&mode==MODE_SETCOUNTDOWN)?SYMB_NUL:SYMB_DOT); - dispvalue[2]=(symbol[settime[2]&0x0f]|((digit!=2 && (time[1]&0x01))?SYMB_NUL:SYMB_8)); - dispvalue[3]=(symbol[(settime[2]&0xf0)>>4]|((digit!=3 && (time[1]&0x01))?SYMB_NUL:SYMB_8))&((mode!=MODE_SETALARM && alarm[0] || mode==MODE_SETALARM && !(time[1]&0x01))?SYMB_DOT:SYMB_NUL); - break; case MODE_SETYEAR: - dispvalue[0]=(symbol[settime[0]&0x0f]|((digit!=0 && (time[1]&0x01))?SYMB_NUL:SYMB_8)); - dispvalue[1]=(symbol[(settime[0]&0xf0)>>4]|((digit!=1 && (time[1]&0x01))?SYMB_NUL:SYMB_8)); - dispvalue[2]=(SYMB_0|((time[1]&0x01)?SYMB_NUL:SYMB_8)); - dispvalue[3]=(SYMB_2|((time[1]&0x01)?SYMB_NUL:SYMB_8))&(alarm[0]?SYMB_DOT:SYMB_NUL); + dispvalue[0]=(symbol[settime[1]&0x0f] | ((digit!=0 && (time[1]&0x01))?SYMB_NUL:SYMB_8)) & ((((((time[1]+0x01)&0x02)^((time[1]&0x10)>>3))&&mode==MODE_SETCOUNTDOWN)||mode==MODE_SETYEAR)?SYMB_NUL:SYMB_DOT); + dispvalue[1]=(symbol[(settime[1]&0xf0)>>4] | ((digit!=1 && (time[1]&0x01))?SYMB_NUL:SYMB_8)) & (((((time[1]&0x02)^((time[1]&0x10)>>3))&&mode==MODE_SETCOUNTDOWN)||mode==MODE_SETYEAR)?SYMB_NUL:SYMB_DOT); + dispvalue[2]=(symbol[settime[2]&0x0f] | ((digit!=2 && (time[1]&0x01))?SYMB_NUL:SYMB_8)) ; + dispvalue[3]=(symbol[(settime[2]&0xf0)>>4] | ((digit!=3 && (time[1]&0x01))?SYMB_NUL:SYMB_8)) & ((mode!=MODE_SETALARM && alarm[0] || mode==MODE_SETALARM && !(time[1]&0x01))?SYMB_DOT:SYMB_NUL); break; + //case MODE_SETYEAR: + // dispvalue[0]=(symbol[settime[0]&0x0f]|((digit!=0 && (time[1]&0x01))?SYMB_NUL:SYMB_8)); + // dispvalue[1]=(symbol[(settime[0]&0xf0)>>4]|((digit!=1 && (time[1]&0x01))?SYMB_NUL:SYMB_8)); + // dispvalue[2]=(SYMB_0|((time[1]&0x01)?SYMB_NUL:SYMB_8)); + // dispvalue[3]=(SYMB_2|((time[1]&0x01)?SYMB_NUL:SYMB_8))&(alarm[0]?SYMB_DOT:SYMB_NUL); + // break; case MODE_SETDATE: dispvalue[0]=(symbol[settime[1]&0x0f]|((digit!=2 && (time[1]&0x01))?SYMB_NUL:SYMB_8)); dispvalue[1]=(symbol[(settime[1]&0xf0)>>4]|((digit!=2 && (time[1]&0x01))?SYMB_NUL:SYMB_8))&SYMB_DOT; @@ -529,8 +565,8 @@ __interrupt void P2_ISR() { dispvalue[0]=symbol[time[7]&0x0f]; dispvalue[1]=symbol[(time[7]&0xf0)>>4]; - dispvalue[2]=SYMB_0; - dispvalue[3]=SYMB_2&(alarm[0]?SYMB_DOT:SYMB_NUL); + dispvalue[2]=symbol[lastyear[1]&0x0f]; + dispvalue[3]=symbol[(lastyear[1]&0xf0)>>4]&(alarm[0]?SYMB_DOT:SYMB_NUL); } else { @@ -559,6 +595,12 @@ __interrupt void P2_ISR() dispvalue[2]=symbol[settime[2]&0x0f]; dispvalue[3]=((settime[2]&0xf0)?symbol[(settime[2]&0xf0)>>4]:SYMB_NUL)&(alarm[0]?SYMB_DOT:SYMB_NUL); break; + case MODE_SHOWVERSION: + dispvalue[0]=SYMB_NUL; + dispvalue[1]=SYMB_2&SYMB_DOT; + dispvalue[2]=SYMB_1; + dispvalue[3]=SYMB_NUL; + break; case MODE_ALARM: case MODE_TIME: if(((time[1]&0x01) && mode==MODE_ALARM) || (time[3]==0x04 && time[2]==0x33 && time[1]==0x00)) @@ -684,6 +726,36 @@ int main( void ) alarm[1]=inbuf[1]; alarm[2]=inbuf[2]; + spi(RTC_READ,0x0f,inbuf,outbuf,1); // <- because of RTC bug (?) + + //get last countdown value from RTC SRAM + spi(RTC_READ,0x23,inbuf,outbuf,3); + if(inbuf[0]==ALARMVALUE) + { + lastcdn[0]=inbuf[1]; + lastcdn[1]=inbuf[2]; + } + else + { + lastcdn[0]=0; + lastcdn[1]=0; + } + + spi(RTC_READ,0x0f,inbuf,outbuf,1); // <- because of RTC bug (?) + + //get last year value from RTC SRAM + spi(RTC_READ,0x26,inbuf,outbuf,3); + if(inbuf[0]==ALARMVALUE) + { + lastyear[0]=inbuf[1]; + lastyear[1]=inbuf[2]; + } + else + { + lastyear[0]=0x00; + lastyear[1]=0x20; + } + //start oscillator spi(RTC_READ,0x01,inbuf,outbuf,1); if(!(inbuf[0]&0x80)) @@ -714,9 +786,7 @@ int main( void ) P2IES&= ~0x08; //RTC int. on rising edge P2IFG=0x00; - if(P2IN&0x02) //button A pressed at start? - mode=MODE_TIME; - else + if(!(P2IN&0x02)) //button A pressed at start? { mode=MODE_CALIBRATE; spi(RTC_READ,0x03,inbuf,outbuf,1); @@ -725,7 +795,11 @@ int main( void ) settime[0]=inbuf[0]; digit=3; } - + else if(!(P2IN&0x20)) //button C pressed at start? + mode=MODE_SHOWVERSION; + else + mode=MODE_TIME; + __enable_interrupt();