PDA

View Full Version : Its "02 June 2006" !



Kman
- 2nd October 2006, 20:08
I have trying everything to get a the formant of a 1302 to display at month.
ie: "02/10/06" Should be " 02 October 2006 "!
Anyone have an "Code Sniplet" That I can lool at?
"Select case" is a Code HOG!
Here is my code.

Printit:
SerOut2 SO,16468,["TIME: ",HEX2 hh,":",HEX2 mm,":",HEX2 ss,10,13]
Pause 500
Select Case mo
'Case mo=01
' SerOut2 SO,16468,[HEX2 day," January, 20",HEX2 yr,13]
'Case mo=02
'SerOut2 SO,16468,[HEX2 day," Febuary, 20",HEX2 yr,13]
'Case mo=03
'SerOut2 SO,16468,[HEX2 day," March, 20",HEX2 yr,13]
'Case mo=04
'SerOut2 SO,16468,[HEX2 day," April, 20",HEX2 yr,13]
'Case mo=05
'SerOut2 SO,16468,[HEX2 day," May, 20",HEX2 yr,13]
Case mo=$06
SerOut2 SO,16468,[HEX2 day," June, 20",HEX2 yr,13]
Case mo=$07
SerOut2 SO,16468,[HEX2 day," July, 20",HEX2 yr,13]
Case mo=$08
SerOut2 SO,16468,[HEX2 day," Augest, 20",HEX2 yr,13]
Case mo=$09
SerOut2 SO,16468,[HEX2 day," Setember, 20",HEX2 yr,13]
Case mo=$10
SerOut2 SO,16468,[HEX2 day," October, 20",HEX2 yr,13]
Case mo=$11
SerOut2 SO,16468,[HEX2 day," November, 20",HEX2 yr,13]
Case mo=$12
SerOut2 SO,16468,[HEX2 day," December, 20",HEX2 yr,13]
End Select
Pause 1000
SerOut2 SO,16468,[" momth= ",HEX2 mo,13,12]
Kman

SteveB
- 2nd October 2006, 20:21
Just a quick comment before I get back to work...

The code hog is all those SEROUT commands! Your duplicating the Day and Year portion of the commands 12 times!!!! Eliminate this by doing the day before the case select, and the the year afterwards.

Steve

SteveB
- 3rd October 2006, 03:24
I don't know what pic you are using, but here is a stab at one technique to help you out. It worked on my 18F series pic just fine.

But fisrt look at Darrel Taylors technique on how to store and retrieve strings in Code Space. (http://www.pbpgroup.com/modules/wfsection/article.php?articleid=10) This will help you understand what I did. If you are using a 16F, you will need to read this to modify the code.

Not saying this is the most efficient method, but it's what I came up with at the end of a long day on the quick. :)


Month_addr var word
CntMonthletters var byte
MonthOut var byte
MonthOffset var byte

MonthString:
@ da "January "
@ da "February "
@ da "March "
@ da "April "
@ da "May "
@ da "June "
@ da "July "
@ da "August "
@ da "September"
@ da "October "
@ da "November "
@ da "December "

'------------GetAddress Macro - Location insensitive -------------------------
ASM
GetAddress macro Label, Wout ; Returns the Address of a Label as a Word
CHK?RP Wout
movlw low Label
movwf Wout
movlw High Label
movwf Wout + 1
endm
ENDASM


@ GetAddress _MonthString, _Month_addr ' Get address of String


'-----------------------------------------------------------------------------
'
'
' Whatever code for main program
'
'
'
'

'Start your printout here after any other code
Printit:
SerOut2 SO,16468,["TIME: ",HEX2 hh,":",HEX2 mm,":",HEX2 ss,10,13]
Pause 500
SerOut2 SO,16468,[HEX2 day," "]
'Printout the stored Month Strings
monthoffset = ((mo & %00001111) + (10 * (mo >> 4)) - 1) * 10
for CntMonthletters = 0 to 8
Readcode (Month_addr + monthoffset + CntMonthletters), monthout
IF monthout = " " THEN GOTO QuitMonthPrint
SerOut2 SO,16468, [monthout]
next CntMonthletters
QuitMonthPrint:
SerOut2 SO,16468,[" 20",HEX2 yr,13]
End Select
Pause 1000
SerOut2 SO,16468,[" momth= ",HEX2 mo,13,12]

HTH,
Steve

mister_e
- 3rd October 2006, 05:03
Yup, or use almost the same method but load your strings in the internal EEPROM. you need 9 bytes*12 months=108.

SteveB
- 4th October 2006, 04:09
A slight refinement to the previous code. I eliminated the macro and made the starting address a constant. Saves a little space. Again, needs a slight modifaction to unpack the character if using a 16F. (I might get to that example later)



;Removed variable declaration
CntMonthletters var byte
MonthOut var byte
MonthOffset var byte

MonthString:
@ da "January "
@ da "February "
@ da "March "
@ da "April "
@ da "May "
@ da "June "
@ da "July "
@ da "August "
@ da "September"
@ da "October "
@ da "November "
@ da "December "

;Added 2 lines for new constant
Month_addr CON EXT
@Month_addr EQU _MonthString

;Removed the macro and the macro call

'-----------------------------------------------------------------------------
'
'
' Whatever code for main program
'
'
'
'

'Start your printout here after any other code
Printit:
SerOut2 SO,16468,["TIME: ",HEX2 hh,":",HEX2 mm,":",HEX2 ss,10,13]
Pause 500
SerOut2 SO,16468,[HEX2 day," "]
'Printout the stored Month Strings
monthoffset = ((mo & %00001111) + (10 * (mo >> 4)) - 1) * 10
for CntMonthletters = 0 to 8
Readcode (Month_addr + monthoffset + CntMonthletters), monthout
IF monthout = " " THEN GOTO QuitMonthPrint
SerOut2 SO,16468, [monthout]
next CntMonthletters
QuitMonthPrint:
SerOut2 SO,16468,[" 20",HEX2 yr,13]
;This should have been removed in the original!! --> End Select
Pause 1000
SerOut2 SO,16468,[" momth= ",HEX2 mo,13,12]

Steve