[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] AVR eeprom
From: |
Ron Kreymborg |
Subject: |
RE: [avr-gcc-list] AVR eeprom |
Date: |
Wed, 1 Aug 2001 21:18:25 +1000 |
> Hi all,
>
> Is it possible to write to the eeprom with the avr-gcc tools? Is
> this done
> automatically for static variables in the code? Any on chip eeprom
> write/read routines floating around in hyperspace are welcome in this
> quadrant! :)
>
> best regards,
> Jamie Morken
Here are some functions I use. You can see what the additional functions
would be for ints, chars, etc.
Regards, Ron
============================================================================
========
#include <eeprom.h>
// An example eeprom variable definition. Use type specifiers to define
// various other types (int, char, etc).
//
float eSomeVariableName __attribute__((section(".eeprom"))) = 10.0; //
initial value
//--------------------------------------------------------------------------
---
// Write a 4-byte float to the specified eeprom address.
//
void eWriteFloat(float *numPtr, void *addr)
{
BYTE *ptr, *num;
ptr = (BYTE*)addr;
num = (BYTE*)numPtr;
eeprom_wb((int)ptr++, *num++); // use gcc AVR extension
eeprom_wb((int)ptr++, *num++);
eeprom_wb((int)ptr++, *num++);
eeprom_wb((int)ptr++, *num++);
}
//--------------------------------------------------------------------------
---
// Read a 4-byte float from the specified address.
//
float eFloat(float *ptr)
{
float a;
eeprom_read_block(&a, (int)ptr, 4); // use gcc AVR extension
return a;
}
// An example of accessing an eeprom variable:
float localFloat;
localFloat = 23.4 + eFloat(&eSomeVariableName);
============================================================================
========