Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Random access of long strings in ROM

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
jcswright

Bascom Member



Joined: 15 Sep 2006
Posts: 27

blank.gif
PostPosted: Wed Jan 17, 2007 1:20 pm    Post subject: Random access of long strings in ROM Reply with quote

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
View user's profile
Luciano

Bascom Member



Joined: 29 Nov 2004
Posts: 3149
Location: Italy

blank.gif
PostPosted: Wed Jan 17, 2007 1:46 pm    Post subject: Reply with quote

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
View user's profile
jcswright

Bascom Member



Joined: 15 Sep 2006
Posts: 27

blank.gif
PostPosted: Wed Jan 17, 2007 3:11 pm    Post subject: Reply with quote

Just what I was after - thank you very much!

Jon
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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