Professional Documents
Culture Documents
EEPROM
EEPROM
CodeVisionAVR EEPROM.PRJ
C:\cvavr\EXAMPLES\EEPROM CodeVisionAVR
Atmel 162 WinAVR
ptr_to_flash=f;
ptr_to_eeprom=e;
char r[16];
char *ptr_to_ram;
ptr_to_ram=r;
1Byte 1Byte
0x06 char temp;
//save 1 byte to EEPROM designate address
ptr_to_eeprom=0x06;
// eeprom 0x06
*ptr_to_eeprom=0x52;
// 0x06=0x52
//read 1 byte form EEPROM designate address
ptr_to_eeprom=0x06;
// eeprom 0x06
temp=*ptr_to_eeprom;
// 0x06=0x52
//
#include <mega162.h>
//-------------------------------------------//
//-------------------------------------------void initial(void); //
//-------------------------------------------// Declare your global variables here
//-------------------------------------------//
flash char f[16]="This is a test";
#pragma warneeprom char e[16];
#pragma warn+
char r[16];
char temp;
//********************************************************************************
//
//********************************************************************************
void main(void)
{
initial();
//CodeVisionAVR set
while (1)
{
char flash *ptr_to_flash;
char eeprom *ptr_to_eeprom;
char *ptr_to_ram;
// copy the string f from FLASH to
// the string e in EEPROM
ptr_to_flash=f;
ptr_to_eeprom=e;
while (*ptr_to_flash)
{
*ptr_to_eeprom++=*ptr_to_flash++;
}
*ptr_to_eeprom++=0x00; // 0, 0 ,
// copy the string e from EEPROM to
// the string r in RAM
ptr_to_eeprom=e;
ptr_to_ram=r;
while (*ptr_to_eeprom)
{
*ptr_to_ram++=*ptr_to_eeprom++;
}
//save 1 byte to EEPROM designate address
ptr_to_eeprom=0x06;
// eeprom 0x06
*ptr_to_eeprom=0x52;
// 0x06=0x52
//read 1 byte form EEPROM designate address
ptr_to_eeprom=0x06;
// eeprom 0x06
temp=*ptr_to_eeprom;
// 0x06=0x52
while (1);
}
}
//stop here
Name
Bloghttp://blog.xuite.net/likelive
2007/08/04