Created
July 20, 2016 00:12
-
-
Save Jacajack/a0267a935489fccd8a280dd441015a27 to your computer and use it in GitHub Desktop.
EEPROM snippet for AVR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include "../include/eeprom.h" | |
void eepromWrite( unsigned int address, unsigned char data ) | |
{ | |
//Wait for EEPROM to be ready | |
while ( EECR & ( 1 << EEPE ) ); | |
EEAR = address; | |
EEDR = data; | |
//Start operation | |
EECR |= ( 1 << EEMPE ); | |
EECR |= ( 1 << EEPE ); | |
} | |
unsigned char eepromRead( unsigned int address ) | |
{ | |
//Wait for EEPROM to be ready | |
while ( EECR & ( 1 << EEPE ) ); | |
EEAR = address; | |
//Start operation | |
EECR |= (1<<EERE); | |
return EEDR; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef EEPROM_H | |
#define EEPROM_H | |
extern void eepromWrite( unsigned int address, unsigned char data ); | |
extern unsigned char eepromRead( unsigned int address ); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment