EEPROM

From uCtrl.net

Jump to: navigation, search
EEPROM

Electronically Erasable Programmable Read-Only Memory.

Contents

Information

EEPROM can, as the name implies, be programmed and erased electronically. The memory is saved through a power-loss. This is commonly used for storing user configurations, etc. But EEPROM memory has it's limits, around 100.000 write operations. This may sound like a lot, but it's really not if the save operation is inside a running loop. So only save to EEPROM when you need to.

EEPROM and AVR

Most AVR devices have built-in EEPROM memory, but it's possible to add a extra EEPROM device.

Schematic drawing

EEPROM interface.png

Source code

The program is written in basic, using Bascom-AVR.

*****************************************************************************
' * Title : EEPROM 24C32.bas
' * Last Updated : 05.03.2006
' * Target device: At90s2313, 24C32
' * Author : www.avrprojects.net
' * Program code : BASCOM-AVR
' * Hardware req. :
' * Description :
' * This application reads and write a byte to an 24c32 EEPROM connected to an
' * AT2313 microcontroller.
' *****************************************************************************
Dim D_w As Byte , D_r As Byte
 
Config Lcdpin = Pin , Db4 = Portb.3 , Db5 = Portb.2 , Db6 = Portb.1 , Db7 = Portb.0 , E = Portb.6 , Rs = Portb.7
 
Config Lcd = 16 * 2
Cls
Cursor Off
 
Config Scl = Portd.0 'assign the SCl line to PORTD.0
Config Sda = Portd.1 'assign the SDA line to PORTD.1
 
D_w = 100
 
'********** write byte to EEPROM ***************************************************
I2cstart 'generate start
I2cwbyte &B1010_0000 'send device address
I2cwbyte 0 'H adress of EEPROM
I2cwbyte 0 'L adress of EEPROM
I2cwbyte D_w 'data to EEPROM
I2cstop 'stop condition
Waitms 10
 
'********** read byte from EEPROM **************************************************
I2cstart 'generate start
I2cwbyte &B1010_0000 'send device adsress
I2cwbyte 0 'H address of EEPROM
I2cwbyte 0 'L address of EEPROM
I2cstart 'repeated start
I2cwbyte &B1010_0001 'slave address (read)
I2crbyte D_r , Nack 'read byte from EEPROM
I2cstop 'generate stop
 
Lcd "D_w= "
Lcd D_w 'show byte on LCD
Lowerline
Lcd "D_r= "
Lcd D_r
End

Resources

Retrieved from "http://uctrl.net/w/EEPROM"
Personal tools
Namespaces
Variants
Actions
Navigation
Categories
projects
Toolbox