When I'm using Proteus to simulate following program, The EEPROM will not change, and Also the EEPE will not set when I add EECR to watch, The whole program is here:
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
void writeEEPROM(unsigned char address,char data){
while(EECR & (1<<EEPE)); //wait for previus writing;
EECR = ((0<<EEPM1)|(0<<EEPM0));
//EECR=0;
EEAR = address; //set address to eeprom address register
EEDR = data;
cli();
EECR |= (1<<EEMPE);
EECR |= (1<<EEPE);
while(EECR & (1<<EEPE)); //wait for previus writing;
EECR |= (1<<EEMPE);
EECR |= (1<<EEPE);
sei();
}
char readEEPROM(unsigned char address){
while(EECR & (1<<EEPE)); //wait for previous write operation
EEAR=0;
EEAR |= address;
EECR=0;
EECR |= 1; //set bit0
return EEDR;
}
int main()
{
// Write your code here
char ret=0;
writeEEPROM(1,9);
_delay_ms(100);
ret=readEEPROM(1);
if(ret==9){
DDRB=0xff;
PORTB=0xff;
}
while (1)
;
return 0;
}
On calling writeEEPROM data will not store to the eeprom.