>-----Original Message----- >From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] >Sent: 26 May 2005 09:23 >To: Microcontroller discussion list - Public. >Subject: [PIC] GSM RealTimeClock > > >The result of a AT+CCLK? is for example: >XX+CCLK: "21/08/18,06:39:40" (note - not the correct date/time) > >Approx every 50sec I call this routine to update the Hour and >Minute register. > >The result of the above string is : >0x04 in the Hour register (should be 6dec or 0x06) >0x07 in the Minute register (should be 30+9=39dec or 0x27) for 06h39 > >I have attached the suspect code. > >Where am I going wrong? movlw .0 ;If Hour tens is zero then load Hour register with zero etc. subwf Temp, w btfsc STATUS, Z #movlf .0, Hours ;(macro for literal to w and then w to f) movlw .1 subwf Temp, w btfsc STATUS, Z ;#movlf .10, Hours You have fallen for a classic macro problem. Your macro expands out to two instructions, but the btfsc will only jump the first one! If you expand out the macro you will see the problem movlw 0x30 subwf D20, w ; D23 could be '0','1' or '2' movwf Temp ; Temp could be 0,1 or 2 movlw .0 ; subwf Temp, w ; W could be 0,1 or 2 btfsc STATUS, Z ; if W is 0 skip next instruction movlw .0 movwf Hours ; Hours could be 0,1 or 2 !!!! Something like this might be better (untested!!!) ; get the Hour tens movlw 0x30 ; convert ASCII to binary subwf D20,W ; D20 holds Hours_Tens movwf Hours ; Hours = Hour_Tens addwf Hours,W ; W = Hour_Tens*2 addwf Hours,F ; Hours = Hour_Tens*3 addwf Hours,F ; Hours = Hour_Tens*5 movf Hours,W ; W = Hour_Tens*5 addwf Hours,F ; Hours = Hour_Tens*10 ; add the Hour units movlw 0x30 subwf D21, W ; D21 holds Hours_Units addwf Hours,F ; Hours = Hour_Tens + Hours_Units ; get the Minute tens movlw 0x30 ; convert ASCII to binary subwf D23,W ; D20 holds Minutes_Tens movwf Minutes ; Minutes = Minutes_Tens addwf Minutes,W ; W = Minutes_Tens*2 addwf Minutes,F ; Minutes = Minutes_Tens*3 addwf Minutes,F ; Minutes = Minutes_Tens*5 movf Minutes,W ; W = Minutes_Tens*5 addwf Minutes,F ; Minutes = Minutes_Tens*10 ; add the Minute units movlw 0x30 subwf D24,W ; D24 holds Minutes_Units addwf Minutes,F ; Minutes = Minutes_Tens + Minutes_Units Regards Mike ======================================================================= This e-mail is intended for the person it is addressed to only. The information contained in it may be confidential and/or protected by law. If you are not the intended recipient of this message, you must not make any use of this information, or copy or show it to any person. Please contact us immediately to tell us that you have received this e-mail, and return the original to us. Any use, forwarding, printing or copying of this message is strictly prohibited. No part of this message can be considered a request for goods or services. ======================================================================= -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist