標題: 單片機內部eeprom程序 Gapvalue是不是寫錯了? [打印本頁]

作者: 2979181478    時間: 2023-5-10 13:21
標題: 單片機內部eeprom程序 Gapvalue是不是寫錯了?
//該值可以為小數#define GapValue 349

volatile bit ClearWeighFlag = 0; //傳感器調零標志位,清除0漂                                


/******************把數據保存到單片機內部eeprom中******************/
void write_eeprom()
{
        SectorErase(0x1000);
        GapValue1=GapValue&0x00ff;
        byte_write(0x2000, GapValue1);
        GapValue1=(GapValue&0xff00)>>8;
        byte_write(0x2001, GapValue1);
        byte_write(0x2060, a_a);        
}

/******************把數據從單片機內部eeprom中讀出來*****************/
void read_eeprom()
{
        GapValue   = byte_read(0x2001);
        GapValue   = (GapValue<<8)|byte_read(0x2000);
        a_a      = byte_read(0x2060);
}

/**************開機自檢eeprom初始化*****************/
void init_eeprom()
{
        read_eeprom();                //先讀
        if(a_a != 1)                //新的單片機初始單片機內問eeprom
        {
                GapValue  = 349+140*5+2*4;//為什么不是直接寫349
                a_a = 1;
                write_eeprom();           //保存數據
        }        
}


作者: Hephaestus    時間: 2023-5-10 15:42
這問題跟你的傳感器有關,看c代碼毫無意義。




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1