📄 eeprom.s
字号:
.module eeprom.c
.area text(rom, con, rel)
.dbfile E:\avrwork3_pt100\eeprom.c
.dbfunc e EEPROMread _EEPROMread fc
; location -> R16,R17
.even
_EEPROMread::
.dbline -1
.dbline 6
; #include <iom16v.h>
; #include <macros.h>
;
;
; unsigned char EEPROMread( int location)
; {
L2:
.dbline 7
L3:
.dbline 7
; while (EECR & 0x02); // Wait until any earlier write is done.
sbic 0x1c,1
rjmp L2
.dbline 15
; // This is just a safety incase a write
; // was done and is not completed when
; // the read was called. If this test is
; // not done, the current write operation
; // will fail due to that the address or
; // data is changed.
;
; EEAR = location;
out 0x1f,R17
out 0x1e,R16
.dbline 17
;
; EECR |= 0x01; // Set READ strobe
sbi 0x1c,0
.dbline 19
;
; return (EEDR); // Return byte
in R16,0x1d
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbsym r location 16 I
.dbend
.dbfunc e EEPROMReadBytes _EEPROMReadBytes fV
; dst -> R10,R11
; size -> R12,R13
; ptr -> y+6
; addr -> R14,R15
.even
_EEPROMReadBytes::
st -y,r19
st -y,r18
xcall push_gset5x
movw R14,R16
ldd R12,y+8
ldd R13,y+9
.dbline -1
.dbline 24
; }
;
;
; void EEPROMReadBytes(int addr, void *ptr, int size)
; {
.dbline 25
; char *dst = ptr;
ldd R10,y+6
ldd R11,y+7
xjmp L7
L6:
.dbline 28
.dbline 29
movw R16,R14
xcall _EEPROMread
movw R30,R10
std z+0,R16
.dbline 30
movw R24,R14
adiw R24,1
movw R14,R24
.dbline 31
movw R24,R30
adiw R24,1
movw R10,R24
.dbline 32
L7:
.dbline 27
;
; while (size--)
movw R2,R12
movw R24,R2
sbiw R24,1
movw R12,R24
tst R2
brne L6
tst R3
brne L6
X0:
.dbline -2
L5:
xcall pop_gset5x
adiw R28,2
.dbline 0 ; func end
ret
.dbsym r dst 10 pc
.dbsym r size 12 I
.dbsym l ptr 6 pV
.dbsym r addr 14 I
.dbend
.dbfunc e EEPROMwrite _EEPROMwrite fI
; oldSREG -> R10
; byte -> R18
; location -> R16,R17
.even
_EEPROMwrite::
xcall push_gset3x
.dbline -1
.dbline 37
; {
; *dst = EEPROMread(addr);
; addr++;
; dst++;
; }
; }
;
;
; int EEPROMwrite( int location, unsigned char byte)
; {
L10:
.dbline 40
L11:
.dbline 40
; unsigned char oldSREG;
;
; while (EECR & 0x02); // Wait until any earlier write is done
sbic 0x1c,1
rjmp L10
.dbline 42
;
; EEAR = location;
out 0x1f,R17
out 0x1e,R16
.dbline 44
;
; EEDR = byte;
out 0x1d,R18
.dbline 46
;
; oldSREG = SREG;
in R10,0x3f
.dbline 47
; SREG &= ~0x80; // disable interrupt
bclr 7
.dbline 49
;
; EECR |= 0x04; // Set MASTER WRITE enable
sbi 0x1c,2
.dbline 50
; EECR |= 0x02; // Set WRITE strobe
sbi 0x1c,1
.dbline 52
;
; SREG = oldSREG;
out 0x3f,R10
.dbline 53
; return 0; // return Success.
clr R16
clr R17
.dbline -2
L9:
xcall pop_gset3x
.dbline 0 ; func end
ret
.dbsym r oldSREG 10 c
.dbsym r byte 18 c
.dbsym r location 16 I
.dbend
.dbfunc e EEPROMWriteBytes _EEPROMWriteBytes fV
; src -> R10,R11
; size -> R12,R13
; ptr -> y+6
; addr -> R14,R15
.even
_EEPROMWriteBytes::
st -y,r19
st -y,r18
xcall push_gset5x
movw R14,R16
ldd R12,y+8
ldd R13,y+9
.dbline -1
.dbline 62
; // Could be expanded so that
; // the routine checks that the address
; // is within the range of the chip.
; }
;
;
;
; void EEPROMWriteBytes(int addr, void *ptr, int size)
; {
.dbline 63
; char *src = ptr;
ldd R10,y+6
ldd R11,y+7
xjmp L15
L14:
.dbline 66
.dbline 67
movw R30,R10
ldd R18,z+0
movw R16,R14
xcall _EEPROMwrite
.dbline 68
movw R24,R14
adiw R24,1
movw R14,R24
.dbline 69
movw R24,R10
adiw R24,1
movw R10,R24
.dbline 70
L15:
.dbline 65
;
; while (size--)
movw R2,R12
movw R24,R2
sbiw R24,1
movw R12,R24
tst R2
brne L14
tst R3
brne L14
X1:
.dbline -2
L13:
xcall pop_gset5x
adiw R28,2
.dbline 0 ; func end
ret
.dbsym r src 10 pc
.dbsym r size 12 I
.dbsym l ptr 6 pV
.dbsym r addr 14 I
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -