中科因仑“3+1”工程特种兵精英论坛

标题: 求大神指教!!! [打印本页]

作者: jerryzhai    时间: 2014-8-12 08:57
标题: 求大神指教!!!
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);
        }
}



作者: 墨奚    时间: 2014-8-12 08:57
领钱               
作者: jerryzhai    时间: 2014-8-12 11:54
延时函数在这里影响不大,大家不要在意这些细节!




欢迎光临 中科因仑“3+1”工程特种兵精英论坛 (http://bbs.enlern.com/) Powered by Discuz! X3.4