-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEEPROM.inc
61 lines (55 loc) · 1.76 KB
/
EEPROM.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;**************************************************************
;*
;* EEPROM Access Module
;*
;**************************************************************
;* Notes
;*
;*
;**************************************************************
;* Subroutine Modified Stacked Preserved
;* EEPROM_WRITE - Temp_1,Temp_2 XL
;* EEPROM_READ - Temp_1,Temp_2 XL
;**************************************************************
.DSEG ; Definitions segment
.CSEG
rjmp IO_SETUP
EEPROM_WRITE:
sbis PINB,LOW_BATT
rjmp LOW_BATT_RESET
push XL ; Save XL
push XH ; Save XH
ldi Temp_1,9 ; Set first write address in EEPROM
ldi XL,$09 ; Set first read address in SRAM
WRITE_LOOP:
sbic EECR,EEWE ; if EEWE not clear
rjmp WRITE_LOOP ; wait
out EEAR,Temp_1 ; Set write address in EEPROM
ld Temp_2,X+ ; Load SRAM data (post incrament read address)
out EEDR,Temp_2 ; Put data register into IO register
sbi EECR,EEMWE ; Set master write enable
sbi EECR,EEWE ; Set EEPROM Write strobe
inc Temp_1 ; Incrament write address in EEPROM
cpi XL,$13 ; test exit loop condition
brne WRITE_LOOP ; loop if not equal
pop XH ; Restore XH
pop XL ; Restore XL
ret
EEPROM_READ:
sbis PINB,LOW_BATT
rjmp LOW_BATT_RESET
push XL ; Save XL
push XH ; Save XH
ldi Temp_1,9 ; Set first read address in EEPROM
ldi XL,$09 ; Set first write address in SRAM
READ_LOOP:
out EEAR,Temp_1 ; Set read address in EEPROM
sbi EECR,EERE ; Set EEPROM read strobe
in Temp_2,EEDR ; Get data register from IO register
st X+,Temp_2 ; Store data to SRAM (post incrament write address)
inc Temp_1 ; Incrament read address in EEPROM
cpi XL,$13 ; If NOT All data is Stored
brne READ_LOOP ; Loop
pop XH ; Restore XH
pop XL ; Restore XL
ret