|
50因仑币
AVR片内EEPROM写进去的数据擦除不掉了,用烧录软件也不行,马老师上的书里面讲这方面的方恨少,就一笔带过了,求大神支招!!!
下面是程序:
#include <iom16v.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
uchar SEG_CODE[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; //ED数码管从0到9来回显示
void delay_1ms(int k)
{
int i,j;
for(i=0;i<k;i++)
{
for(j=0;j<1000;j++)
;
}
}
void EEPROM_write(uint addr,uint adata)
{
SREG &= ~BIT(7);
while(EECR &BIT(EEWE));
EEAR = addr;
EEDR = adata;
EECR |= BIT(EEMWE);
EECR |= BIT(EEWE);
SREG |= BIT(7);
}
uchar EEPROM_read(uint addr)
{
uchar edata;
SREG &= ~BIT(7);
while(EECR &BIT(EEWE));
EEAR = addr;
EECR |= BIT(EERE);
edata = EEDR;
return edata;
}
void main(void)
{
uchar i;
DDRB = 0xff; //初始化PB口为输出
PORTB = 0x00; //PB口一开始输出为0
i = EEPROM_read(2);
i ++;
EEPROM_write(2,i);
while(1)
{
PORTB = SEG_CODE[i];
delay_1ms(10000);
}
}
|
|