\r
spi(RTC_WRITE,0x26,inbuf,outbuf,3);\r
}\r
+ \r
+ if(mode==MODE_DEBUG && changed)\r
+ spi(RTC_READ,settime[1],settime,outbuf,1);\r
}\r
else if(P2IFG&0x02) // button A\r
{\r
mode=MODE_SETCOUNTDOWN;\r
settime[1]=lastcdn[0];\r
settime[2]=lastcdn[1];\r
+ changed=0;\r
digit=3;\r
}\r
break;\r
+ case MODE_DEBUGADDR:\r
+ case MODE_DEBUGVAL:\r
+ mode=MODE_DEBUG;\r
+ break;\r
case MODE_SETCOUNTDOWN:\r
case MODE_COUNTDOWN:\r
- if(((settime[1] | settime[2])&&((settime[1]^lastcdn[0])|(settime[1]^lastcdn[0])))||digit!=3||mode==MODE_COUNTDOWN)\r
+ if(changed || mode==MODE_COUNTDOWN)\r
{\r
mode=MODE_SETCOUNTDOWN;\r
- settime[1]=0x00;\r
- settime[2]=0x00;\r
+ settime[1]=lastcdn[0];\r
+ settime[2]=lastcdn[1];\r
+ changed=0;\r
digit=3;\r
break;\r
}\r
//case MODE_SETALARM:\r
//case MODE_ALARM:\r
//case MODE_CALIBRATE:\r
- //case MODE_SHOWVERSION:\r
+ //case MODE_DEBUG:\r
default:\r
mode=MODE_TIME;\r
break;\r
break;\r
case MODE_SETCOUNTDOWN:\r
if(digit)\r
+ {\r
--digit;\r
+ changed=1;\r
+ }\r
else\r
{\r
lastcdn[0]=settime[1];\r
digit=3;\r
}\r
break;\r
+ case MODE_DEBUGADDR:\r
+ if(digit)\r
+ --digit;\r
+ else\r
+ {\r
+ spi(RTC_READ,settime[1],settime,outbuf,1);\r
+ mode=MODE_DEBUG;\r
+ changed=1;\r
+ }\r
+ break;\r
+ case MODE_DEBUGVAL:\r
+ if(digit)\r
+ --digit;\r
+ else\r
+ {\r
+ spi(RTC_WRITE,settime[1],inbuf,settime,1);\r
+ mode=MODE_DEBUG;\r
+ }\r
+ break;\r
case MODE_SETTIME:\r
if(digit)\r
{\r
--digit;\r
if(settime[0]>((settime[1]==0x02)?(leap?0x29:0x28):(((settime[1]&0x18) && !(settime[1]&0x01) || !(settime[1]&0x18) && (settime[1]&0x01))?0x31:0x30)))\r
settime[0]&=(digit?0x00:0xf0);\r
+ if(settime[0]==0x00)\r
+ settime[0]=0x01;\r
}\r
else\r
{\r
time[5]=settime[0];\r
time[6]=settime[1];\r
settime[2]=time[7];\r
- spi(RTC_WRITE,0x05,inbuf,settime,3);\r
+ spi(RTC_WRITE,0x06,inbuf,settime+1,2);\r
+ spi(RTC_WRITE,0x05,inbuf,settime,1);\r
}\r
mode=MODE_DATE;\r
}\r
spi(RTC_WRITE,0x20,inbuf,outbuf,1);\r
mode=MODE_TIME;\r
break;\r
+ case MODE_DEBUG:\r
+ //changed=1;\r
+ digit=1;\r
+ mode=MODE_DEBUGADDR;\r
+ break; \r
default:\r
break;\r
}\r
case MODE_COUNTDOWN:\r
settime[1]=lastcdn[0];\r
settime[2]=lastcdn[1];\r
+ changed=0;\r
mode=MODE_SETCOUNTDOWN;\r
digit=3;\r
break;\r
case MODE_CALIBRATE:\r
if(digit==2)\r
settime[1]^=0x80;\r
- else if(digit<2)\r
- settime[0]+=(digit==1?0x10:(((settime[0]&0x0f)==0x0f)?0xf1:0x01));\r
+ if(digit>=2)\r
+ break;\r
+ case MODE_DEBUGADDR:\r
+ case MODE_DEBUGVAL:\r
+ settime[(mode==MODE_DEBUGADDR)?1:0]+=(digit==1?0x10:(((settime[(mode==MODE_DEBUGADDR)?1:0]&0x0f)==0x0f)?0xf1:0x01));\r
break;\r
case MODE_SETTIME:\r
case MODE_SETALARM:\r
case MODE_SETYEAR:\r
- changed=1;\r
case MODE_SETCOUNTDOWN:\r
+ changed=1;\r
//these 4 lines replaced a larger switch structure\r
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))))\r
settime[digit&0x02?2:1]+=((digit&0x01)?0x10:0x01);\r
else\r
settime[digit&0x02?2:1]&=((digit&0x01)?0x0f:0xf0);\r
break;\r
- //case MODE_SETYEAR:\r
- // changed=1;\r
- // if(digit)\r
- // {\r
- // if(settime[0]<0x90)\r
- // settime[0]+=0x10;\r
- // else\r
- // settime[0]&=0x0f;\r
- // }\r
- // else\r
- // {\r
- // if((settime[0]&0x0f)<0x09)\r
- // ++settime[0];\r
- // else\r
- // settime[0]&=0xf0;\r
- // }\r
- // break;\r
case MODE_SETDATE:\r
changed=1;\r
switch (digit)\r
++settime[0];\r
else\r
settime[0]&=0xf0;\r
+ if(settime[0]==0x00)\r
+ settime[0]=0x01;\r
break;\r
}\r
break;\r
spi(RTC_WRITE,0x20,inbuf,outbuf,1);\r
mode=MODE_TIME;\r
break;\r
+ case MODE_DEBUG:\r
+ if(changed)\r
+ {\r
+ digit=1;\r
+ mode=MODE_DEBUGVAL;\r
+ }\r
+ break;\r
default:\r
break;\r
}\r
dispvalue[2]=(symbol[settime[2]&0x0f] | ((digit!=2 && (time[1]&0x01))?SYMB_NUL:SYMB_8)) ;\r
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);\r
break;\r
- //case MODE_SETYEAR:\r
- // dispvalue[0]=(symbol[settime[0]&0x0f]|((digit!=0 && (time[1]&0x01))?SYMB_NUL:SYMB_8));\r
- // dispvalue[1]=(symbol[(settime[0]&0xf0)>>4]|((digit!=1 && (time[1]&0x01))?SYMB_NUL:SYMB_8));\r
- // dispvalue[2]=(SYMB_0|((time[1]&0x01)?SYMB_NUL:SYMB_8));\r
- // dispvalue[3]=(SYMB_2|((time[1]&0x01)?SYMB_NUL:SYMB_8))&(alarm[0]?SYMB_DOT:SYMB_NUL);\r
- // break;\r
+ case MODE_DEBUGADDR:\r
+ case MODE_DEBUGVAL:\r
+ dispvalue[0]=(symbol[settime[(mode==MODE_DEBUGADDR)?1:0]&0x0f] | ((digit!=0 && (time[1]&0x01))?SYMB_NUL:SYMB_8)) &SYMB_DOT;\r
+ dispvalue[1]=(symbol[(settime[(mode==MODE_DEBUGADDR)?1:0]&0xf0)>>4] | ((digit!=1 && (time[1]&0x01))?SYMB_NUL:SYMB_8)) &SYMB_DOT;\r
+ dispvalue[2]=(mode==MODE_DEBUGADDR)?SYMB_A:SYMB_NUL; \r
+ dispvalue[3]=alarm[0]?SYMB_DOT:SYMB_NUL;\r
+ break;\r
case MODE_SETDATE:\r
dispvalue[0]=(symbol[settime[1]&0x0f]|((digit!=2 && (time[1]&0x01))?SYMB_NUL:SYMB_8));\r
dispvalue[1]=(symbol[(settime[1]&0xf0)>>4]|((digit!=2 && (time[1]&0x01))?SYMB_NUL:SYMB_8))&SYMB_DOT;\r
dispvalue[2]=symbol[settime[2]&0x0f];\r
dispvalue[3]=((settime[2]&0xf0)?symbol[(settime[2]&0xf0)>>4]:SYMB_NUL)&(alarm[0]?SYMB_DOT:SYMB_NUL);\r
break;\r
- case MODE_SHOWVERSION:\r
- dispvalue[0]=SYMB_NUL;\r
- dispvalue[1]=SYMB_2&SYMB_DOT;\r
- dispvalue[2]=SYMB_1;\r
- dispvalue[3]=SYMB_NUL;\r
+ case MODE_DEBUG:\r
+ if(changed)\r
+ {\r
+ dispvalue[0]=symbol[settime[0]&0x0f]&SYMB_DOT;\r
+ dispvalue[1]=symbol[(settime[0]&0xf0)>>4]&SYMB_DOT;\r
+ dispvalue[2]=symbol[settime[1]&0x0f];\r
+ dispvalue[3]=symbol[(settime[1]&0xf0)>>4]&(alarm[0]?SYMB_DOT:SYMB_NUL);\r
+ }\r
+ else\r
+ {\r
+ dispvalue[0]=SYMB_NUL;\r
+ dispvalue[1]=SYMB_3&SYMB_DOT;\r
+ dispvalue[2]=SYMB_1;\r
+ dispvalue[3]=SYMB_NUL&(alarm[0]?SYMB_DOT:SYMB_NUL);\r
+ }\r
break;\r
case MODE_ALARM:\r
case MODE_TIME:\r
digit=3;\r
}\r
else if(!(P2IN&0x20)) //button C pressed at start?\r
- mode=MODE_SHOWVERSION;\r
+ {\r
+ mode=MODE_DEBUG;\r
+ settime[1]=0x00;\r
+ changed=0;\r
+ }\r
else\r
mode=MODE_TIME;\r
\r