Reading and writing Atmega168 EEPROM Tutorial


Posted on Feb 7, 2014

EEPROM (Electrically Erasable Programmable Read Only Memory) Is non-volatile memory, meaning it persists after power is removed. The ATmega168 microcontroller has 512 bytes of EEPROM which can be used to store system parameters and small amounts of data. This tutorial shows you how to read and write EEPROM. This counts how many times the device ha


Reading and writing Atmega168 EEPROM Tutorial
Click here to download the full size of the above Circuit.

s been powered up or reset. In later examples we`ll be adding other datatypes and interracting with the EEPROM in slightly different ways. No need to reinvent the wheel here. We will use the circuit from the Character LCD Displays Part 2 post we did last year, but build it on a breadboard instead. First we need to build a basic Atmega168 breadboard circuit. See Atmega8 breadboard circuit  Part 1 and Part 2 but substitute an Atmega168 for the Atmega8. You will recall that the default values for an erase byte is 0xFF. At lines 11 & 12 we set num_executions to 0 if being run against an erase EEPROM (e. g. first execution). Reading and writing the 8 bit value is almost identical to reading and writing the 16 bit value. If you look at lines 20-25 you will see different functions and datatypes being used but the differences are minor. In c, void *  is used to denote a generic pointer. When we pass real pointers to the function we need to cast them as void * . This is shown in lines 28 and 36. The eeprom_read_block and eeprom_write_block function are very versatile as they can be used with any datatype. For example you could read/write structs or multi dimension arrays using these 2 functions. In large projects, it can be tedious to define the addresses for each EEPROM stored variable. The EEMEM attribute is used to auto allocate addresses for the non-volatile variables. Consider the following code example. Even though these...




Leave Comment

characters left:

New Circuits

.

 


Popular Circuits

DC servo motor driver with MC33030
High q notch filter
Hall-effect-compass
Simple RS 232 Level Converter
Basic Circuit Modification of Kodak Disposable Camera
The ICL7135 Integrating A/D Converter Functional Diagram and Datasheet
Latest British Police Car Siren circuit
Wien Bridge Oscillator Circuit
fet current source
Ring Counter Circuit Working Principle with Animation and Video
A Keypad Circuit That Will Convert From Decimal To BCD Decimal



Top