AVR EEPROM问题在proteus

时间:2017-07-26 13:41:40

标签: avr eeprom

当我使用Proteus模拟以下程序时,EEPROM不会改变,并且当我添加EECR观看时EEPE也不会设置,整个程序在这里:

#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;
}

在调用writeEEPROM时,数据不会存储到eeprom。

1 个答案:

答案 0 :(得分:0)

这是从源代码随播文件集到AVR103 AVR EEPROM Application Note,来自设备制造商的权威出版物。

var selectedItemBindingExpression = GetBindingExpression(SelectedItemProperty);