From: b Date: Mon, 31 Aug 2015 20:48:30 +0000 (+0200) Subject: debug mode X-Git-Tag: v1.3 X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=6b32ca301e10ae643b429f3b8d8f4657e92cd2aa;p=staf%2Fstaf debug mode --- diff --git a/definitions.h b/definitions.h index 825ab1b..a869b44 100644 --- a/definitions.h +++ b/definitions.h @@ -63,7 +63,10 @@ #define MODE_COUNTUP 8 #define MODE_SETCOUNTDOWN 9 #define MODE_COUNTDOWN 10 + #define MODE_CALIBRATE 11 -#define MODE_SHOWVERSION 12 +#define MODE_DEBUG 12 +#define MODE_DEBUGADDR 13 +#define MODE_DEBUGVAL 14 #define ALARMVALUE 0xa5 \ No newline at end of file diff --git a/main.c b/main.c index 4264315..86fb16f 100644 --- a/main.c +++ b/main.c @@ -213,6 +213,9 @@ __interrupt void P2_ISR() spi(RTC_WRITE,0x26,inbuf,outbuf,3); } + + if(mode==MODE_DEBUG && changed) + spi(RTC_READ,settime[1],settime,outbuf,1); } else if(P2IFG&0x02) // button A { @@ -242,16 +245,22 @@ __interrupt void P2_ISR() mode=MODE_SETCOUNTDOWN; settime[1]=lastcdn[0]; settime[2]=lastcdn[1]; + changed=0; digit=3; } break; + case MODE_DEBUGADDR: + case MODE_DEBUGVAL: + mode=MODE_DEBUG; + break; case MODE_SETCOUNTDOWN: case MODE_COUNTDOWN: - if(((settime[1] | settime[2])&&((settime[1]^lastcdn[0])|(settime[1]^lastcdn[0])))||digit!=3||mode==MODE_COUNTDOWN) + if(changed || mode==MODE_COUNTDOWN) { mode=MODE_SETCOUNTDOWN; - settime[1]=0x00; - settime[2]=0x00; + settime[1]=lastcdn[0]; + settime[2]=lastcdn[1]; + changed=0; digit=3; break; } @@ -259,7 +268,7 @@ __interrupt void P2_ISR() //case MODE_SETALARM: //case MODE_ALARM: //case MODE_CALIBRATE: - //case MODE_SHOWVERSION: + //case MODE_DEBUG: default: mode=MODE_TIME; break; @@ -292,7 +301,10 @@ __interrupt void P2_ISR() break; case MODE_SETCOUNTDOWN: if(digit) + { --digit; + changed=1; + } else { lastcdn[0]=settime[1]; @@ -318,6 +330,25 @@ __interrupt void P2_ISR() digit=3; } break; + case MODE_DEBUGADDR: + if(digit) + --digit; + else + { + spi(RTC_READ,settime[1],settime,outbuf,1); + mode=MODE_DEBUG; + changed=1; + } + break; + case MODE_DEBUGVAL: + if(digit) + --digit; + else + { + spi(RTC_WRITE,settime[1],inbuf,settime,1); + mode=MODE_DEBUG; + } + break; case MODE_SETTIME: if(digit) { @@ -375,6 +406,8 @@ __interrupt void P2_ISR() --digit; if(settime[0]>((settime[1]==0x02)?(leap?0x29:0x28):(((settime[1]&0x18) && !(settime[1]&0x01) || !(settime[1]&0x18) && (settime[1]&0x01))?0x31:0x30))) settime[0]&=(digit?0x00:0xf0); + if(settime[0]==0x00) + settime[0]=0x01; } else { @@ -383,7 +416,8 @@ __interrupt void P2_ISR() time[5]=settime[0]; time[6]=settime[1]; settime[2]=time[7]; - spi(RTC_WRITE,0x05,inbuf,settime,3); + spi(RTC_WRITE,0x06,inbuf,settime+1,2); + spi(RTC_WRITE,0x05,inbuf,settime,1); } mode=MODE_DATE; } @@ -419,6 +453,11 @@ __interrupt void P2_ISR() spi(RTC_WRITE,0x20,inbuf,outbuf,1); mode=MODE_TIME; break; + case MODE_DEBUG: + //changed=1; + digit=1; + mode=MODE_DEBUGADDR; + break; default: break; } @@ -436,43 +475,30 @@ __interrupt void P2_ISR() case MODE_COUNTDOWN: settime[1]=lastcdn[0]; settime[2]=lastcdn[1]; + changed=0; mode=MODE_SETCOUNTDOWN; digit=3; break; case MODE_CALIBRATE: if(digit==2) settime[1]^=0x80; - else if(digit<2) - settime[0]+=(digit==1?0x10:(((settime[0]&0x0f)==0x0f)?0xf1:0x01)); + if(digit>=2) + break; + case MODE_DEBUGADDR: + case MODE_DEBUGVAL: + settime[(mode==MODE_DEBUGADDR)?1:0]+=(digit==1?0x10:(((settime[(mode==MODE_DEBUGADDR)?1:0]&0x0f)==0x0f)?0xf1:0x01)); break; case MODE_SETTIME: case MODE_SETALARM: case MODE_SETYEAR: - changed=1; case MODE_SETCOUNTDOWN: + changed=1; //these 4 lines replaced a larger switch structure 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_SETDATE: changed=1; switch (digit) @@ -495,6 +521,8 @@ __interrupt void P2_ISR() ++settime[0]; else settime[0]&=0xf0; + if(settime[0]==0x00) + settime[0]=0x01; break; } break; @@ -524,6 +552,13 @@ __interrupt void P2_ISR() spi(RTC_WRITE,0x20,inbuf,outbuf,1); mode=MODE_TIME; break; + case MODE_DEBUG: + if(changed) + { + digit=1; + mode=MODE_DEBUGVAL; + } + break; default: break; } @@ -542,12 +577,13 @@ __interrupt void P2_ISR() 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_DEBUGADDR: + case MODE_DEBUGVAL: + dispvalue[0]=(symbol[settime[(mode==MODE_DEBUGADDR)?1:0]&0x0f] | ((digit!=0 && (time[1]&0x01))?SYMB_NUL:SYMB_8)) &SYMB_DOT; + dispvalue[1]=(symbol[(settime[(mode==MODE_DEBUGADDR)?1:0]&0xf0)>>4] | ((digit!=1 && (time[1]&0x01))?SYMB_NUL:SYMB_8)) &SYMB_DOT; + dispvalue[2]=(mode==MODE_DEBUGADDR)?SYMB_A:SYMB_NUL; + dispvalue[3]=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; @@ -595,11 +631,21 @@ __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; + case MODE_DEBUG: + if(changed) + { + dispvalue[0]=symbol[settime[0]&0x0f]&SYMB_DOT; + dispvalue[1]=symbol[(settime[0]&0xf0)>>4]&SYMB_DOT; + dispvalue[2]=symbol[settime[1]&0x0f]; + dispvalue[3]=symbol[(settime[1]&0xf0)>>4]&(alarm[0]?SYMB_DOT:SYMB_NUL); + } + else + { + dispvalue[0]=SYMB_NUL; + dispvalue[1]=SYMB_3&SYMB_DOT; + dispvalue[2]=SYMB_1; + dispvalue[3]=SYMB_NUL&(alarm[0]?SYMB_DOT:SYMB_NUL); + } break; case MODE_ALARM: case MODE_TIME: @@ -796,7 +842,11 @@ int main( void ) digit=3; } else if(!(P2IN&0x20)) //button C pressed at start? - mode=MODE_SHOWVERSION; + { + mode=MODE_DEBUG; + settime[1]=0x00; + changed=0; + } else mode=MODE_TIME;