-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheeprom.S
71 lines (51 loc) · 1.68 KB
/
eeprom.S
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
62
63
64
65
66
67
68
69
70
71
; ****************************************************************************
;
; EEPROM
;
; ****************************************************************************
#include "include.inc"
.text
; ----------------------------------------------------------------------------
; Read EEPROM byte
; ----------------------------------------------------------------------------
; INPUT: R27:R26 = source address
; OUTPUT: R24 = data
; DESTROYS: -
; ----------------------------------------------------------------------------
; ----- set up address
.global EERead
EERead: out _SFR_IO_ADDR(EEARH),r27
out _SFR_IO_ADDR(EEARL),r26
; ----- start read operation
sbi _SFR_IO_ADDR(EECR),EERE
; ----- read data
in r24,_SFR_IO_ADDR(EEDR)
ret
; ----------------------------------------------------------------------------
; Write EEPROM byte
; ----------------------------------------------------------------------------
; INPUT: R27:R26 = destination address
; R25 = data
; OUTPUT: R24 = old byte
; ----------------------------------------------------------------------------
; ----- check old content
.global EEWrite
EEWrite:
; INPUT: R27:R26 = source address
; OUTPUT: R24 = data
; DESTROYS: -
rcall EERead ; read old byte -> R24
cp r24,r25 ; check byte
breq EEWrite4 ; data already set
; ----- set up address and data
out _SFR_IO_ADDR(EEARH),r27
out _SFR_IO_ADDR(EEARL),r26
out _SFR_IO_ADDR(EEDR),r25
; ----- start write operation
sbi _SFR_IO_ADDR(EECR),EEMPE ; from now, 4 clock cycles to write EEPE
sbi _SFR_IO_ADDR(EECR),EEPE
; ----- wait operation
2: sbic _SFR_IO_ADDR(EECR),EEPE
rjmp 2b
EEWrite4:
ret