저는 Atemega32의 EEPROM에 데이터를 저장해야하는 대학 프로젝트를 진행하고 있습니다. 메모리의 특정 위치에서 데이터를 쓰고 읽을 수 있습니다. 하지만 데이터를 순차적으로 쓰기 위해 주소 0 ~ 1023을 쓰면 잘못된 값이 나옵니다.EEPROM에 순차적으로 데이터 쓰기 및 읽기
다음은 내가 작성한 기능입니다.
기능 정의 읽기 및 쓰기 할 데이터
#include "eeprom.h"
uint8_t EEPROMRead(uint16_t uiAddress)
{
/* Wait for completion of previous write */
while(EECR & (1<<EEWE));
/* Set up address register */
EEAR = uiAddress;
/* Start eeprom read by writing EERE */
EECR |= (1<<EERE);
/* Return data from data register */
return EEDR;
}
void EEPROMWrite(uint16_t uiAddress, uint8_t ucData)
{
/* Wait for completion of previous write */
while(EECR & (1<<EEWE));
/* Set up address and data registers */
EEAR = uiAddress;
EEDR = ucData;
/* Write logical one to EEMWE */
EECR |= (1<<EEMWE);
/* Start eeprom write by setting EEWE */
EECR |= (1<<EEWE);
}
여기
static int epadr=0;
epread=EEPROMRead(epadr); //reading from address stored in epadr
printf("%d",epread); //printing values
if(epadr<=1023)
{
EEPROMWrite(epadr,high); //writing at address stored in epadr
epadr++; //increment address
}
}
if(epadr>1023)
printf("Memory Full\n");
가이 코드에 어떤 문제가 있는지 알려주십시오 1023 위치 0에서 데이터를 저장할 주요 기능을합니다.
'EEAR','EECR' 및'EEDR' 등 변수의 정의는 무엇입니까? – Dai
'epadr'은 어디에서 초기화합니까? 정적 저장소 지속 시간 변수를 초기화하지 않으시겠습니까? 그렇게하는 것은 특히 임베디드 시스템에서 제로 초기화를 건너 뛰는 비표준 시작 코드가있는 경우 특히 그렇습니다. – Lundin
@Dai 'EEAR, EECR, EEDR'은 AVR의 acsess EEPROM에 등록되어 등록되어 있습니다. –