📄 eeprom.c
字号:
//#pragma SRC
#include "mytype.h"
//#include <atmel\reg51xd2.h>
//#pragma disable
//sfr16 DPTR = 0x82;
void weeprom(uint addr,uchar dat);
uchar REeprom(uint addr);
void weeprom(uint addr,uchar dat)
{
/*
Check EEBUSY flag
If the user application interrupts routines use XRAM memory space: Save and
disable interrupts.
Load DPTR with the address to write
Store A register with the data to be written
Set bit EEE of EECON register
Execute a MOVX @DPTR, A
Clear bit EEE of EECON register
Restore interrupts.
EEBUSY flag in EECON is then set by hardware to indicate that programming is in
progress and that the EEPROM segment is not available for reading or writing.
The end of programming is indicated by a hardware clear of the EEBUSY flag.
*/
uchar stIE;
uchar xdata *p = (uchar xdata *)addr;
stIE = IE;
while(EECON&1)
;
EA = 0;
EECON|=2;
*p = dat;
EECON&=~2;
IE = stIE;
}
uchar REeprom(uint addr)
{
/*
Check EEBUSY flag
If the user application interrupts routines use XRAM memory space: Save and
disable interrupts.
Load DPTR with the address to read
Set bit EEE of EECON register
Execute a MOVX A, @DPTR
Clear bit EEE of EECON register
Restore interrupts.
*/
uchar stIE,dat;
uchar xdata *p = (uchar xdata *)addr;
stIE = IE;
while(EECON&1)
;
EA = 0;
EECON|=2;
dat = *p;
EECON&=~2;
IE = stIE;
return dat;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -