📄 eeprom.h
字号:
#ifndef _EEPROM_H
#define _EEPROM_H
#define EERE 0
#define EEWE 1
#define EEMWE 2
#define EERIE 3
void EEPROM_Write(unsigned int uiAddress, unsigned char ucData)
{
while(EECR & (1<<EEWE)) ;
EEAR = uiAddress;
EEDR = ucData;
EECR |= (1<<EEMWE);
EECR = (1<<EEWE);
}
unsigned char EEPROM_Read(unsigned int uiAddress)
{
while(EECR & (1<<EEWE)) ;
EEAR = uiAddress;
EECR |= (1<<EERE);
return EEDR;
}
#pragma asm_function+
void EEPROM_Write_W(unsigned int uiAddress, unsigned int ucData)
{
#asm
ld r22,y+
ld r23,y+
ld r24,y+
ld r25,y+
ser r31
in r0,0x3f
__wait:
sbic 0x1c,1
rjmp __wait
out 0x1f,r25
out 0x1e,r24
out 0x1d,r22
cli
sbi 0x1c,2
sbi 0x1c,1
out 0x3f,r0
sbrs r31,0
ret
subi r24,0xff
sbci r25,0xff
mov r22,r23
clr r31
rjmp __wait
#endasm
}
#pragma asm_function-
#pragma asm_function+
unsigned int EEPROM_Read_W(unsigned int uiAddress)
{
#asm
ld r30,y+
ld r31,y+
__wait:
sbic 0x01,1
rjmp __wait
out 0x1f,r31
out 0x1e,r30
sbi 0x1c,0
adiw r30,0x01
in r0,0x1d
out 0x1f,r31
out 0x1e,r30
sbi 0x1c,0
mov r30,r0
in r31,0x1d
ret
#endasm
}
#pragma asm_function-
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -