avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] int to EEPROM


From: Gines Martinez
Subject: Re: [avr-gcc-list] int to EEPROM
Date: Sat, 8 Sep 2001 15:25:22 +0200

One question:
Don't you have to call after each eeprom_wb() to the function
eeprom_is_ready() ?
ie:

void eWriteFloat(float *numPtr, void *addr)
{
    BYTE *ptr, *num;

    ptr = (BYTE*)addr;
    num = (BYTE*)numPtr;
    eeprom_wb((int)ptr++, *num++);
    while(!eeprom_is_ready());
    eeprom_wb((int)ptr++, *num++);
    while(!eeprom_is_ready());
    eeprom_wb((int)ptr++, *num++);
    while(!eeprom_is_ready());
    eeprom_wb((int)ptr++, *num++);
    while(!eeprom_is_ready());
}

----- Original Message -----
From: "Ron Kreymborg" <address@hidden>
To: <address@hidden>
Sent: Thursday, August 09, 2001 2:24 PM
Subject: RE: [avr-gcc-list] int to EEPROM


> >
> > Saw nice example of storing float to eeprom, could some one please post
> > the same kind of example of storing & retreiving and int type variable
> > from/to eeprom ?
> >
> > With regards,
> >
> > Pasi
> >
>
> Well here is one possible organisation. For the int case where (for
example)
> the variable in eeprom you are concerned with is called "TheVariable ". It
> is declared in the usual way:
>
> #define EEPROM __attribute__((section(".eeprom")))
>
> int TheVariable EEPROM = 0;
>
> You extract it with:
>
>     int x = eInt(&TheVariable);
>
> and you can write it back with:
>
>     eWriteInt(&x, &TheVariable);
>
> Don't forget the ampersand! Here is a complete set...
>
>
//--------------------------------------------------------------------------
> ---
> float eFloat(float *ptr)
> {
>     float a;
>
>     eeprom_read_block(&a, (int)ptr, 4);
>     return a;
> }
>
>
//--------------------------------------------------------------------------
> ---
> long eLong(long *ptr)
> {
>     long a;
>
>     eeprom_read_block(&a, (int)ptr, 4);
>     return a;
> }
>
>
//--------------------------------------------------------------------------
> ---
> int eInt(int *ptr)
> {
>     int a;
>
>     eeprom_read_block(&a, (int)ptr, 2);
>     return a;
> }
>
>
//--------------------------------------------------------------------------
> ---
> BYTE eByte(BYTE *ptr)
> {
>     BYTE a;
>
>     eeprom_read_block(&a, (int)ptr, 1);
>     return a;
> }
>
>
//--------------------------------------------------------------------------
> ---
> void eWriteFloat(float *numPtr, void *addr)
> {
>     BYTE *ptr, *num;
>
>     ptr = (BYTE*)addr;
>     num = (BYTE*)numPtr;
>     eeprom_wb((int)ptr++, *num++);
>     eeprom_wb((int)ptr++, *num++);
>     eeprom_wb((int)ptr++, *num++);
>     eeprom_wb((int)ptr++, *num++);
> }
>
>
//--------------------------------------------------------------------------
> ---
> void eWriteLong(long *numPtr, void *addr)
> {
>     BYTE *ptr, *num;
>
>     ptr = (BYTE*)addr;
>     num = (BYTE*)numPtr;
>     eeprom_wb((int)ptr++, *num++);
>     eeprom_wb((int)ptr++, *num++);
>     eeprom_wb((int)ptr++, *num++);
>     eeprom_wb((int)ptr++, *num++);
> }
>
>
//--------------------------------------------------------------------------
> ---
> void eWriteInt(int *numPtr, void *addr)
> {
>     BYTE *ptr, *num;
>
>     ptr = (BYTE*)addr;
>     num = (BYTE*)numPtr;
>     eeprom_wb((int)ptr++, *num++);
>     eeprom_wb((int)ptr++, *num++);
> }
>
>
//--------------------------------------------------------------------------
> ---
> void eWriteByte(BYTE *numPtr, void *addr)
> {
>     BYTE *ptr, *num;
>
>     ptr = (BYTE*)addr;
>     num = (BYTE*)numPtr;
>     eeprom_wb((int)ptr++, *num++);
> }
>
>
> -------------------------------------------
> Ron Kreymborg
> Jennaron Research
> Melbourne, Australia
>
>
> _______________________________________________
> avr-gcc-list mailing list
> address@hidden
> http://avr.jpk.co.nz/mailman/listinfo/avr-gcc-list




reply via email to

[Prev in Thread] Current Thread [Next in Thread]