Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

question about store word variable in eeprom

Status
Not open for further replies.

mehran.rivandi

Newbie level 4
Joined
Mar 13, 2012
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,337
how can store a word variable in eeprom ?

i have a word array .

for example : m var word [10]

i want to store my array in eeprom .

and then read form eeprom .

it is very important for me .

please help me .

software : pic basic pro .
microprocessor : pic16f877a
 

ok i work basic not c .

and then i want store just highbyte of word array in to the eeprom .
 

I don't know BASIC but there is obviously some method to split words into bytes. Then you just store them the way you like.
 
ok .

thanks .

this is my method to store word into the eeprom

Code:
    for  i = 1 to 10

            write   i          ,    m.LowByte[i]
            write   i+10     ,    m.HighByte[i]

        next i

and this is my method to read word from eeprom .

Code:
   for i = 1 to 10

           read   i          ,      m.LowByte[i]
           read   i+10     ,      m.HighByte[i]
     
     next i


this code is for pic basic pro software .

you think it is correct ?

---------- Post added at 22:44 ---------- Previous post was at 22:43 ----------

you think is it correct ?
 
Last edited by a moderator:

If you look to the compiler manual, you'll notice, that word and long entities can be written with a single instruction.
 
Code:
WRITE Address,{WORD}{LONG}Value {,Value...}

Write byte, word or long (if PBPL used) Values to the on-chip EEPROM at the specified Address.
 
excuse me can you write an example of my code ?

---------- Post added at 23:45 ---------- Previous post was at 23:28 ----------

THIS IS MY CODE
PHP:
'******************************************************************************************
' this program is for testing of read and write word array in to eeprom and display on lcd 
'******************************************************************************************

define LCD_DREG   PORTD
define LCD_DBIT   4
define LCD_RSREG  PORTD       
define LCD_RSBIT  2
define LCD_EREG   PORTD       
define LCD_EBIT   3
define LCD_BITS   4         
define LCD_LINES  2     


H var byte
L var byte

m var word [1] 
 
main:

m[0] = $4142   ' 41 = A   and  42 = B


write 1,m.highbyte [0] 
write 2,m.lowbyte [0] 


read 1,H 
read 2,L  

LCDOut $FE,1,H
Pause 2000


LCDOut $FE,1,L
Pause 2000


goto main
end
 

Sorry, I'm not using BASIC since 20 years or so. The manual syntax is obvious in my view.

It implements, what most programmers would do in this case, storing a word in two consecutive memory cells. The memory addresses have to be incremented by two.

Something like
Code:
write 2*i, word m[i]
 

THIS CODE WORKS CORRECTLY .

BUT I WANT YOUR CODE .
PHP:
WRITE Address,{WORD}{LONG}Value {,Value...}

Write byte, word or long (if PBPL used) Values to the on-chip EEPROM at the specified Address.


---------- Post added 15-03-12 at 00:05 ---------- Previous post was 14-03-12 at 23:51 ----------

OK THANKS YOUR CODE WORK CORRECTLY . I CHANGE MY CODE AND COMPILE IT AND IT WORKS CORRECTLY .
THIS IS a new code .
PHP:
'******************************************************************************************
' this program is for testing of read and write word array in to eeprom and display on lcd 
'******************************************************************************************

define LCD_DREG   PORTD
define LCD_DBIT   4
define LCD_RSREG  PORTD       
define LCD_RSBIT  2
define LCD_EREG   PORTD       
define LCD_EBIT   3
define LCD_BITS   4         
define LCD_LINES  2     


H var byte
L var byte
 I VAR BYTE
m var word [1] 
 
main:

m[0] = $4142   ' 41 = A   and  42 = B

 
write 1, WORD m[0]
 
read 1,L 
read 2,H  

LCDOut $FE,1,H
Pause 2000


LCDOut $FE,1,L
Pause 2000


goto main
end


---------- Post added at 00:10 ---------- Previous post was at 00:05 ----------

i think it is better
PHP:
'******************************************************************************************
' this program is for testing of read and write word array in to eeprom and display on lcd 
'******************************************************************************************

define LCD_DREG   PORTD
define LCD_DBIT   4
define LCD_RSREG  PORTD       
define LCD_RSBIT  2
define LCD_EREG   PORTD       
define LCD_EBIT   3
define LCD_BITS   4         
define LCD_LINES  2     


H var byte
L var byte
 I VAR BYTE
m var word [1] 
 
main:

m[0] = $4142   ' 41 = A   and  42 = B

for i = 0 to 10 
write (2*i)+1, WORD m[0]
next i 
      
read 1,L 
read 2,H  

LCDOut $FE,1,H
Pause 2000


LCDOut $FE,1,L
Pause 2000


goto main
end


---------- Post added at 00:11 ---------- Previous post was at 00:10 ----------

PHP:
for i = 0 to 10 
write (2*i)+1, WORD m[i]
next i
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top