📄 eprom.c
字号:
#include <avr/io.h>
#include <avr/eeprom.h>
#define RS PA7
#define RW PA5
#define EN PA6
#define DIN PB2
#define UP_KEY PA0
#define DOWN_KEY PA1
#define OK_KEY PA2
#define RW_CLR PORTA &=~(1<<RW)
#define RW_SET PORTA |=(1<<RW)
#define RS_CLR PORTA &=~(1<<RS)
#define RS_SET PORTA |=(1<<RS)
#define EN_CLR PORTA &=~(1<<EN)
#define EN_SET PORTA |=(1<<EN)
unsigned char xianshi[16]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44,0x45,0x46};
void delay(unsigned int j)
{
unsigned int i;
for(i=0;i<j;i++){}
}
void lcd_data(unsigned char data)
{
RS_SET;
EN_SET;
delay(200);
PORTC=data;
delay(200);
EN_CLR;
}
////////////////////////////////write lcd address
//** name : lcd_com()
//** function : write commands to the LCD
//** input parameter :add
//** output parameter :NULL
//** debugging explanation :
/////////////////////////////////////////////////
void lcd_com(unsigned char add)
{
RS_CLR;
EN_SET;
delay(200);
PORTC=add;
delay(200);
EN_CLR;
}
void lcd_Init()
{
lcd_com(0x30);//normal function
lcd_com(0x01);//clear all
lcd_com(0x0f);//on lcd
}
int main(void)
{
// unsigned char num;
unsigned char val;
unsigned char data[4];
unsigned char first_on,ok_set;
DDRB=0X07|DDRB;
DDRC=0xff|DDRC;
DDRA=0xE0|DDRA;
RW_CLR;
lcd_Init();
while(1)
{
first_on=ok_set=0x00;
lcd_com(0x80);
if(!(PINA & 0x01))/////////////////first check
{
first_on=0x01;
}
if(first_on)
{
delay(100);
if(!(PINA&0x01))////////////////second check
{
ok_set=0x01;
}
}
if(ok_set==0x01)
{
eeprom_busy_wait();
eeprom_write_byte(0x01,0x01);
eeprom_busy_wait();
eeprom_write_byte(0x02,0x02);
eeprom_busy_wait();
eeprom_write_byte(0x03,0x03);
eeprom_busy_wait();
eeprom_write_byte(0x04,0x04);
}
eeprom_busy_wait();
data[0]=eeprom_read_byte(0x01);
lcd_data(xianshi[data[0]]);
eeprom_busy_wait();
data[1]=eeprom_read_byte(0x02);
lcd_data(xianshi[data[1]]);
eeprom_busy_wait();
data[2]=eeprom_read_byte(0x03);
lcd_data(xianshi[data[2]]);
eeprom_busy_wait();
data[3]=eeprom_read_byte(0x04);
lcd_data(xianshi[data[3]]);
}
}
/*
#include<avr/io.h>
#include<avr/iom169.h>
#include <avr/eeprom.h>
unsigned char low10print[640]={};
void delay(int j)
{
int i;
for(i=0;i<j;i++){}
}
void Eeprom_write(unsigned int add,unsigned char data)
{
while(EECR&(1<<EEWE));
EEDR=data;
EEAR=add;
EECR|(1<<EEWE);
EECR|=(1<<EEMWE);
while (EECR & 0x02);
EEAR=0;
}
unsigned char Eeprom_read(unsigned int add)
{
while(EECR&(1<<EEWE));
EEAR=add;
EECR|=(1<<EERE);
EEAR=0;
return EEDR;
}
void main(void)
{
unsigned int i,eeprom_add;
unsigned char chari;
// delay(60000);
// Eeprom_write(1,0x76);
chari=Eeprom_read(0x01);
chari=Eeprom_read(0x02);
chari=Eeprom_read(0x03);
chari=Eeprom_read(0x04);
}
*/
/*
#include<avr/io.h>
#include<avr/iom169.h>
#include <avr/eeprom.h>
unsigned char high11print[704]={};
void main(void)
{
int i;
for(i=0;i<704;i++)
{
eeprom_busy_wait();
eeprom_write_byte(eeprom_add,high11print[i]);
}
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -