PIC內部EEPROM讀寫操作

2022-08-19 08:42:07 字數 1973 閱讀 1538

#include //

config

#pragma config fosc = hs //

oscillator selection bits (hs oscillator)

#pragma config wdte = off //

watchdog timer enable bit (wdt disabled)

#pragma config pwrte = off //

power-up timer enable bit (pwrt disabled)

#pragma config boren = off //

brown-out reset enable bit (bor enabled)

#pragma config lvp = off //

low-voltage (single-supply) in-circuit serial programming enable bit (rb3/pgm pin has pgm function; low-voltage programming enabled)

#pragma config cpd = off //

data eeprom memory code protection bit (data eeprom code protection off)

#pragma config wrt = off //

flash program memory write enable bits (write protection off; all program memory may be written to by eecon control)

#pragma config cp = off //

flash program memory code protection bit (code protection off)

typedef unsigned

char

uchar;

void

writeee(uchar addr, uchar data);

uchar readee(uchar addr);

uchar led_data;

__eeprom_data(

0xfe,0xff,0xef,0,0,0,0,0

);void main(void) }

void

writeee(uchar addr, uchar data)

while(wr == 1); //

等待完成

eeadr = addr; //

寫入位址資訊

eedata = data; //

寫入資料資訊

eepgd = 0; //

操作eeprom,訪問資料儲存器

wren = 1; //

寫入eeprom允許

eecon2 = 0x55

; eecon2 = 0xaa; //

特定時序

wr = 1; //

執行寫操作

do{}

while(wr == 1); //

等待寫入完成

wren = 0; //

禁止寫入eeprom

}uchar readee(uchar addr)

while(rd == 1); //

等待讀完成

eeadr = addr; //

位址 eepgd = 0; //

訪問資料儲存器

rd = 1; //

執行讀操作

do{}

while(rd == 1

); _data =eedata;

return

_data;

}

STM8S 操作內部EEPROM

對於stm8s103f3這款晶元來講,存在640個位元組的eeprom,當然如果有外部eeprom,自然是不會使用到內部的eeprom的。但小東西也有大用途,例如做無線應用時,減少成本的情況下,還能儲存一些特定設定,如 休眠時間,工作頻率,輸出功率,密碼等。下圖所示,stm8s系列eeprom大小一...

STM32HAL內部EEPROM讀寫L151

資料eeprom程式設計功能 擦除或程式設計的任何操作都應遵循以下步驟 呼叫 ref hal flashex dataeeprom unlock 函式啟用資料eeprom訪問 和flash程式擦除控制暫存器訪問。呼叫所需的功能來擦除或程式設計資料。呼叫 ref hal flashex dataeep...

PIC16F877A微控制器的EEPROM讀寫

編寫乙個例程來說明比較好理解,本例程的功能是將乙個0x66的字元放在0x15的eeprom中,然後在讀取,如果讀取成功就點亮led燈 include 呼叫標頭檔案,16f877a微控制器 config 0xff32 晶元配置字,看門狗關,上電延時開,掉電檢測關,低壓程式設計關,加密,4m晶體hs振盪...