atmega8 系列的EEPROM读写

//ICC-AVR application builder : 2009-3-12 17:39:42
// Target : M8
// Crystal: 8.0000Mhz

#include
#include

void port_init(void)
{
PORTB = 0x00;
DDRB = 0x00;
PORTC = 0x00; //m103 output only
DDRC = 0x00;
PORTD = 0x00;
DDRD = 0x00;
}

//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();

MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}

/*****************************************************************************
用 途:EEPROM读写程序
Taget :mega8
crystal :8M
介 绍:
*****************************************************************************/
//eeprom写操作
void eeprom_write(unsigned int address,unsigned char data)
{
while(EECR&(1<{;}
EEAR=address;
EEDR=data;
EECR|=(1<EECR|=(1<}
//eeprom读操作
unsigned char eeprom_read(unsigned int address)
{
while(EECR&(1<{;}
EEAR=address;
EECR|=(1<return EEDR;
}
//****************************************************************************
void main()
{
unsigned char i;
port_init();
init_devices();

eeprom_write(1,0x55);
eeprom_write(2,0xAA);
i=eeprom_read(1);
PORTB=i;
i=eeprom_read(2);
PORTD=i;
while(1)
{
;
}
}

相关文档
最新文档