writing a longword to eeprom

General discussion on mikroBasic PRO for AVR.
Post Reply
Author
Message
hudyboy1
Posts: 5
Joined: 22 May 2011 21:52

writing a longword to eeprom

#1 Post by hudyboy1 » 22 May 2011 22:13

Hi people!
Does anyone have any idea how to save longword to internal mega32 eeprom?
Please, heelp! :)

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: writing a longword to eeprom

#2 Post by filip » 25 May 2011 13:57

Hi,

Just break the longword into bytes and put each byte into consecutive locations in EEPROM.

Regards,
Filip.

Muphy
Posts: 318
Joined: 24 Feb 2008 14:05
Location: Stonehaven Scotland

Re: writing a longword to eeprom

#3 Post by Muphy » 25 May 2011 21:06

That was my first response but I held off to see what other responses came :D but perhaps the chap dunno how to do the split

hudyboy1, if you need more help how to split the longword into bytes then please
ask


M

octal
Posts: 534
Joined: 09 Feb 2005 14:15
Location: France
Contact:

Re: writing a longword to eeprom

#4 Post by octal » 26 May 2011 09:48

Muphy wrote: but perhaps the chap dunno how to do the split
Check user manual of mikroBasic for AVR.
On chapter 3, section "Built-In Routines" ... page 95++
Check : Lo(), Hi(), Higher(), Highest() functions

and if you can read french language, I remember we already discussed this stuff on mikroBasic for PIC forum long time ago http://www.mikroe.com/forum/viewtopic.p ... int+eeprom

Regards
http://www.pocketmt.com

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: writing a longword to eeprom

#5 Post by Dany » 26 May 2011 09:58

Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

hudyboy1
Posts: 5
Joined: 22 May 2011 21:52

Re: writing a longword to eeprom

#6 Post by hudyboy1 » 26 May 2011 14:18

Hi guys!
Thanks for the effort, I was browsing a bit and found out two procedures (one for read, the other one for...you know what for :) ).
I had the idea with hi and lo,but I made an error when I tried to divide already divided (lo and hi) long word.
Tnx again! (and special thanks to Dany for writing and to Corallaro for posting:) )
Btw, here's the code:


Hi Guys

There is a conversion of beautful routine wrote by Dany for mikropascal

http://users.edpnet.be/rosseel01/DRO/PI ... iable.mpas
http://users.edpnet.be/rosseel01/DRO/PIC/index.htm

tested in mikrobasic 6 and mikrobasic PRO 2.50 to write/read word variable in EEprom of a 16f88 and it works perfectly...


Code: Select all
'------------------------------------------------------------------------------
'-------- Unit EepromVariable --- version: 2009-09-16 for Mikrobasic-----------
'------------------------------------------------------------------------------
'
'INTERFACE:

'procedure EEPromWriteVariable(Dat as ^byte, Number, EEpromAddress as byte)
'procedure EEPromReadVariable(Dat as ^byte, Number, EEpromAddress as byte)

'These procedures/functions do write and read the content
'of any type of variable to/from Eeprom.
'
' The procedures/functions need following parameters:
' - the address of the variable
' - the size of the variable (8–bit=1, 16-bit=2, 32-bit=4)
' - the first (lowest) address in Eeprom to write to or read from'
' Take care of the mapping of the variables in Eeprom so that they do not overlap!

'CALLING THE ROUTINES:

'EePromWriteVariable(@Variable, sizeof(Variable), EePromAddress)

'EePromReadVariable(@Variable, sizeof(Variable), EePromAddress)

'IMPLEMENTATION:

'sub procedure EePromWriteVariable(dim Dat as ^byte, dim Number, EEpromAddress as byte)
'dim I as byte
' for I = 0 to Number -1
' EEProm_Write(EEPromAddress, Dat^)' // write the "I"th byte
' Delay_ms(25)
' Inc(Dat)
' Inc(EEpromAddress)
' next I
'end sub

'sub procedure EePromReadVariable(dim Dat as ^byte, dim Number, EEpromAddress as byte)
' dim I as byte
' for I = 0 to Number -1
' Dat^ = EEProm_Read(EEPromAddress)' // read the "I"th byte
' Delay_ms(25)
' Inc(Dat)
' Inc(EEpromAddress)
' next I
'end sub

'EXAMPLE:

'dim CurrentValue as word
'dim StoredValue as word

'CurrentValue = 1023
'EePromWriteVariable(@CurrentValue, 2, 10)
'Delay_us(500)

'EePromReadVariable(@StoredValue, 2, 10)
'Delay_us(500)
'WordToStr(StoredValue, Text)
'Lcd_Out(1, 1, Text)

'So in LCD display you view "1023"

'-------------------------------------------------------------------------------


Giovanni

Edited by Administrator: Added code Tag!

Post Reply

Return to “mikroBasic PRO for AVR General”