View previous topic :: View next topic |
Author |
Message |
jcswright
Joined: 15 Sep 2006 Posts: 27

|
Posted: Wed Jan 17, 2007 1:20 pm Post subject: Random access of long strings in ROM |
|
|
Hello,
I have been struggling to find a neat way of randomly accessing parts of a constant stored in Flash-ROM for the LCD scrolling requirement I described in my last topic.
I'm sure there must be a better way than the one I am currently using, so I thought I would phrase the question a little better and see if anyone has any better ideas...
If I have (for example) a sentence "The quick brown fox jumps over the lazy dog" in, maybe a 'const' or 'data' line like this:
Code: | data "The quick brown fox jumps over the lazy dog" | How could I access the 14th (for example) letter of that string, without loading the whole sentence into RAM - which is what I am trying to avoid? At the moment, I am using: Code: | data "T" , "h" , "e" , ..... | and 'lookupstr' but I guess I could break it up into slightly larger segments: Code: | data "The quic" , "k brown ", ... | which I could then use mid (str,x,1) on, but it still isn't a very nice solution.
Another application might be the sending to a printer of a large amount of text - again without consuming large amounts of RAM...
Does anyone have any suggestions?
Thanks,
Jon |
|
Back to top |
|
 |
Luciano
Joined: 29 Nov 2004 Posts: 3149 Location: Italy

|
Posted: Wed Jan 17, 2007 1:46 pm Post subject: |
|
|
Hi Jon,
The code below will work with addresses from 0 to 65535.
If you use a micro with more than 64KB, and you know that
the string with the text is located in the upper 64KB, then just
replace in the sample code below CPEEK with CPEEKH.
(This will work with chips with up to 128KB of flash).
Best regards,
Luciano
Code: | $regfile = "m48def.dat"
$crystal = 4000000
$baud = 9600
$hwstack = 32
$swstack = 10
$framesize = 40
Dim my_label_address as word
Dim my_current_address as word
Dim my_index as word
Dim my_byte as byte
my_label_address = LOADLABEL(Datatext)
For my_index = 0 To 42
my_current_address = my_label_address + my_index
my_byte = CPEEK(my_current_address)
Print Chr(my_byte)
Next
End
Datatext:
Data "The quick brown fox jumps over the lazy dog" |
|
|
Back to top |
|
 |
jcswright
Joined: 15 Sep 2006 Posts: 27

|
Posted: Wed Jan 17, 2007 3:11 pm Post subject: |
|
|
Just what I was after - thank you very much!
Jon |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|