Skip to content

Instantly share code, notes, and snippets.

@Jacajack
Created July 20, 2016 00:12
Show Gist options
  • Save Jacajack/a0267a935489fccd8a280dd441015a27 to your computer and use it in GitHub Desktop.
Save Jacajack/a0267a935489fccd8a280dd441015a27 to your computer and use it in GitHub Desktop.
EEPROM snippet for AVR
#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;
}
#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