⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eeprom读写.c

📁 ICC mega8例子
💻 C
字号:
//ICC-AVR application builder : 2009-3-12 17:39:42
// Target : M8
// Crystal: 8.0000Mhz

#include <iom8v.h>
#include <macros.h>

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<<EEWE))
 {;}
 EEAR=address;
 EEDR=data;
 EECR|=(1<<EEMWE);
 EECR|=(1<<EEWE);
}
//eeprom读操作
unsigned char eeprom_read(unsigned int address)
{
 while(EECR&(1<<EEWE))
 {;}
 EEAR=address;
 EECR|=(1<<EERE);
 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)
 {
  ;
 }
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -