BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Thu Apr 26, 2018 3:02 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Storing a 16 bit word in the 8 bit EEPROM area
PostPosted: Fri Feb 06, 2015 3:49 am 
Offline
Citizen

Joined: Sun Apr 22, 2012 10:22 pm
Posts: 26
I am using the A/D in the Nano18 and reading the result as a decimal word (0 to 1024). Then I need to store this word in EEPROM so it remains when the power is shut off. Does anyone know a good way to do this? I think I have to break the word into an upper byte and a lower byte but I don't see any way to to this. Then after reading both memory locations I need to assemble the bytes into a word.
Thanks for any pointers.


Top
 Profile  
 
 Post subject: Re: Storing a 16 bit word in the 8 bit EEPROM area
PostPosted: Sun Feb 08, 2015 1:06 am 
Offline
Master

Joined: Wed Oct 19, 2011 2:28 am
Posts: 123
Hi,
You can try it using the follow commands.

ad_word_input var word ' Analog input value variable
read_mem_word var word ' Read memory data variable


'writing to device
write 0,ad_word_input.LowByte ' send data byte to memory low bytes 0 to 7
write 1,ad_word_input.highByte ' send data byte to memory high bytes 8 to 15

'reading from memory
read 0, read_mem_word.lowbyte 'read byte from memory and store it in the lower byte of the variable 0 to 7
read 1, read_mem_word.highbyte 'read byte from memory and store it in the upper byte of the variable 8 to 15


Top
 Profile  
 
 Post subject: Re: Storing a 16 bit word in the 8 bit EEPROM area
PostPosted: Wed Feb 11, 2015 3:47 am 
Offline
Citizen

Joined: Sun Apr 22, 2012 10:22 pm
Posts: 26
Perfect! That works nicely. I see that is on page 34 of the manual listed in the table of Variable Modifiers.
However I missed it because those are not listed in the Table of Contents.
I found a fairly easy way of doing it on the Stackoverflow site using bit shifts left and right.
However this is cleaner.
CASE CLOSED. Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


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 post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO