AVR的EEPROM簡(jiǎn)單實(shí)驗(yàn)
#include "1602.h"
void port_init() //端口初始化
{
PORTA=0xff;
DDRA=0xff;
PORTB=0xff;
DDRB=0xff;
PORTC=0xff;
DDRC=0xff;
PORTD=0xff;
DDRD=0x0f;
}
{
PORTA=0xff;
DDRA=0xff;
PORTB=0xff;
DDRB=0xff;
PORTC=0xff;
DDRC=0xff;
PORTD=0xff;
DDRD=0x0f;
}
void write_EEPROM(uchar address,uchar data) //寫(xiě)入EEPROM函數(shù)
{
while(EECR&(1< EEAR=address;
EEDR=data;
EECR|=(1< EECR|=(1< }
{
while(EECR&(1<
EEDR=data;
EECR|=(1<
uchar receive_EEPROM(uchar address) //讀取EEPROM操作
{
while(EECR&(1< EEAR=address;
EECR|=(1< return EEDR;
}
{
while(EECR&(1<
EECR|=(1<
}
void key3()
{
static uchar i,j;
if(k3==0)
{
if(i==0)
{
j++;
if(j>3)
{
if(k3==0)
{
i=1;j=0;
write_EEPROM(address,data);
}
}
}
}
else
{
i=0;j=0;
}
}
void key4()
{
static uchar i,j;
if(k4==0)
{
if(i==0)
{
j++;
if(j>3)
{
if(k4==0)
{
i=1;j=0;
val=receive_EEPROM(address);
}
}
}
}
else
{
i=0;j=0;
}
}
{
static uchar i,j;
if(k4==0)
{
if(i==0)
{
j++;
if(j>3)
{
if(k4==0)
{
i=1;j=0;
val=receive_EEPROM(address);
}
}
}
}
else
{
i=0;j=0;
}
}
void main()
{
port_init();
{
port_init();
write_EEPROM(address,data);
val=receive_EEPROM(address);
while(1)
{
show_val(val); //顯示數(shù)據(jù)值
show_address(address); //顯示數(shù)據(jù)地址
show_data(data); //顯示需要寫(xiě)入的數(shù)據(jù)地址
key1(); //改變數(shù)據(jù)地址
key2(); //改變準(zhǔn)備寫(xiě)入的數(shù)據(jù)值
key3();//把數(shù)據(jù)寫(xiě)入地址中
key4();//讀出地址值
}
}
val=receive_EEPROM(address);
while(1)
{
show_val(val); //顯示數(shù)據(jù)值
show_address(address); //顯示數(shù)據(jù)地址
show_data(data); //顯示需要寫(xiě)入的數(shù)據(jù)地址
key1(); //改變數(shù)據(jù)地址
key2(); //改變準(zhǔn)備寫(xiě)入的數(shù)據(jù)值
key3();//把數(shù)據(jù)寫(xiě)入地址中
key4();//讀出地址值
}
}
評(píng)論