PDA

View Full Version : Best way to store text in a pic



atwoz
- 6th December 2007, 05:37
Hello fellow PBP'ers, I'm currently working on a project where I need to display many text lines in a LCD.

The text outputs depend on the situation, say:

if the count reaches 100 I'll display: "Good Morning, blah blah blah"

then when the count reaches 150, it'll display: "good afternoon, blah blah"

and so on..
I want my program to be able to give many text strings..

Suppose I'm using a pic 16f887,what is the best way to save space or to do this?

I was thinking about doing many if...then's but that will probably eat my pic's memory in no time.
I'll appreciate any piece of advice, thanks!

WoZ

Jumper
- 6th December 2007, 06:41
Hi

Maybe you can use an external EE-prom for your text strings. 24LC512 using I2C is a very cheap and simple way. Then you can use the PIC for program code and the EE-prom for text messages. This way will also allow you to change the text without having to recompile every time.



/me

Jerson
- 6th December 2007, 09:20
This is how I do it



prn_SetDate: PokeCode "Date changed",0
prn_SetTime: PokeCode "Time changed",0
prn_LogPrinted: PokeCode "Log printed",0
prn_SafeClosedByMaster: PokeCode "Key interlock cleared by master",0

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
Address var word

'----snip------
' This is how to use it
' Prt_puts uses the Variable Address to print the contents pointed at by it
@ GetAddress _prn_SetDate, _Address ;macro from this site
gosub Prt_puts ; put the string to printer
'----snip------

' Print an ASCIIZ string
' Input - Address points to the string
Prt_puts:
repeat
peekcode Address, gr[0] ' gr[0] is a byte sized user register
if gr[0] then
gosub Prt_putc ' print 1 character
Address = Address+1
endif
until gr[0]=0 ' print till end of string '0'
return


Hope this helps

mister_e
- 6th December 2007, 14:50
Variant of the above

STRINGS - How to store and retrieve strings in Code Space
http://www.pbpgroup.com/modules/wfsection/article.php?articleid=10

which is also explain/discussed + few variant & mods

Embedded Strings in your Code Space
http://www.picbasic.co.uk/forum/showthread.php?t=1999&highlight=codespace