avr: added routines to read/write EEPROM.
This commit is contained in:
@@ -93,4 +93,54 @@ Utils_IncrementCounter32:
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; Utils_ReadEeprom
|
||||
;
|
||||
; Read a byte from EEPROM (see example in ATtiny24/44/84 manual p.19).
|
||||
;
|
||||
; IN:
|
||||
; - X: EEPROM Address to read from
|
||||
; OUT:
|
||||
; - R16: byte read
|
||||
; MODIFIED REGISTERS: R16
|
||||
|
||||
Utils_ReadEeprom:
|
||||
sbic EECR, EEPE ; wait for previous write to complete (if any)
|
||||
rjmp Utils_ReadEeprom
|
||||
out EEARH, xh ; set EEPROM address
|
||||
out EEARL, xl
|
||||
sbi EECR, EERE ; start EEPROM read by writing EERE
|
||||
in r16, EEDR ; read data from data register
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; Utils_WriteEeprom
|
||||
;
|
||||
; Write a byte to EEPROM (see example in ATtiny24/44/84 manual p.18).
|
||||
;
|
||||
; IN:
|
||||
; - R16: byte to write
|
||||
; - X: EEPROM Address to read from
|
||||
; OUT:
|
||||
; - nothing
|
||||
; MODIFIED REGISTERS: R17
|
||||
|
||||
Utils_WriteEeprom:
|
||||
sbic EECR, EEPE ; wait for previous write to complete (if any)
|
||||
rjmp Utils_WriteEeprom
|
||||
ldi r17, (0<<EEPM1) | (0<<EEPM0) ; set programming mode
|
||||
out EECR, r17
|
||||
out EEARH, xh ; set EEPROM address
|
||||
out EEARL, xl
|
||||
out EEDR, r16 ; write data to data register
|
||||
sbi EECR, EEMPE ; write logical one to EEMPE
|
||||
sbi EECR, EEPE ; start EEPROM write by setting EEPE
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user