⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eeprom.asm

📁 Eversmith_-_AVRSMS for pdu mode
💻 ASM
字号:
;==========================================================
; This is a part of: Eversmith - AVRSMS
; Copyright (2003) Martin Thomas, Kaiserslautern,  Germany. 
; This  Software is  distributed  under  the Aladdin  Free 
; Public License (AFPL) Read the file license.txt included 
; in the distibution-package. See main-file for more infor-
; mation and license.
;==========================================================
;
;----------------------------------------------------------
; EEPROM handling subroutines
; ** caller has to disable interrupts  for the EEPROM **
; ** write routines - its not done by this routines!  **
; e.g. cli					; disable all interrupts
;      rcall EEWriteXXX		; call EEPROM write
;      sei					; enable all interrups
;----------------------------------------------------------

.CSEG
;----------------------------------------------------------
; Subroutine EEWriteByte
; Writes one byte to EEPROM-Adress (based on Atmel App-Note)
;----------------------------------------------------------
; ! caller has to disable interrupts (see uC-manual) !
;
; Inputs:
; r16 = Data Byte to EEPROM
; r24 = address in EEPROM Low
; r25 = address in EEPROM High
;
; Outputs:
; none
;
; Side-Effects: EE* Registers changed
EEWriteByte:
EEWriteByte_Wait:
	; it halts the CPU for two clock cycles
	sbic EECR,EEWE			; if EEWE not clear
	rjmp EEWriteByte_Wait	; wait more
	out	EEARL,r24	; output addresss low 
	out EEARH,r25	; output addresss high
	out	EEDR,r16	; output data
	sbi EECR,EEMWE	; set master write enable
	sbi	EECR,EEWE	; set EEPROM write strobe
				; This instruction takes 4 clock cycles since
				; it halts the CPU for two clock cycles
	ret

;----------------------------------------------------------
; Subroutine EEWriteSeqFromFlash
; Write a Null-terminated sequence from FLASH to EEPROM
;----------------------------------------------------------
; !! caller has to disable interrupts  !!
;
; Inputs:
; Z-Registers(ZL/ZH) = Pointer to Data in fash
;	Null-terminated
; r24 = start address in EEPROM Low
; r25 = start address in EEPROM High
;
; Outputs:
; none
;
; Side-effects:
; implicit from EEWriteByte (EE*-Registers changed)
; ZH, ZL changed to last address read from FLASH
; r25:r24 changed to last adress written to EEPROM

EEWriteSeqFromFlash:
	push r0
	push r16
	
EEWriteSeqPM_L1:
	;;lpm r16,Z+ 		; this instruction is not supported on AVR 90S8515
	; alternate methode:
	lpm				; defaults to lpm r0
	mov r16,r0		; copy r0 to r16
	adiw ZH:ZL,$01 	; increment Z
    rcall EEWriteByte
	adiw r25:r24,0x01
    tst r16			; test for Null
	brne EEWriteSeqPM_L1

	pop r16
	pop r0
	
	ret

;----------------------------------------------------------
; Subroutine EEWriteSeqFromRam
; Write a Null-terminated sequence from SRAM to EEPROM
;----------------------------------------------------------
; !! caller has to disable interrupts  !!
;
; Inputs:
; Y-Registers(YL/YH) = Pointer to begin of data in SRAM
;	Null-terminated
; r24 = start address in EEPROM Low (Data null terminated)
; r25 = start address in EEPROM High
;
; Outputs:
;  none
;
; Side-effects:
;  implicit from EEWriteByte
;  YH, YL changed to last address read from SRAM+1
;  r25:r24 changed to last adress written to EEPROM+1

EEWriteSeqFromRam:
	push r16
	push r17

EEWriteSeqRam_L1:
	ld r16, Y+
	mov r17,r16
	rcall EEWriteByte
	adiw r25:r24,0x01
	tst r16			; test for Null
	brne EEWriteSeqRam_L1

	pop r17
	pop r16
	ret

;----------------------------------------------------------
; Subroutine EEReadByte
; Read one Byte from EEPROM
;----------------------------------------------------------
; (based on Atmel App-Note)
;
; Inputs:
;  r24 = address in EEPROM low
;  r25 = address in EEPROM high
;
; Outputs:
;  r16 = Data byte from EEPROM Adress r25:r24
;
; Side-Effects: EE*-Registers changed

EEReadByte:
	
EERead_WaitClear:
	sbic EECR,EEWE		; if EEWE not clear
	rjmp EERead_WaitClear		; wait more

	out	EEARL,r24	; output address low 
	out EEARH,r25	; output address high
	sbi	EECR,EERE	; set EEPROM Read strobe
			; This instruction takes 4 clock cycles since
			; it halts the CPU for two clock cycles
	in	r16,EEDR	;get data

	ret

;----------------------------------------------------------
; Subroutine EEReadPlus
; Read one Byte from EEPROM with increment
;----------------------------------------------------------
;
; Inputs:
;  r24 = Address in EEPROM low
;  r25 = Address in EEPROM high
;
; Outputs:
;  r16 = Data byte from EEPROM Adress r25:r24
;  r25:r24 = Input address +1
; 

EEReadPlus:
	rcall EEReadByte
	adiw r25:r24, 0x01
	ret

;----------------------------------------------------------
; Subroutine EEReadSeqToRam
; Read a Null-terminated sequence from EEPROM to SRAM
;----------------------------------------------------------
;
; Inputs:
;  r24 = Address in EEPROM low (Data null terminated)
;  r25 = Address in EEPROM high
;  Y-Register = Address in SRAM (Destination)
;
; Outputs:
;  Copied data in RAM including Null

EEReadSeqToRam:
	push r16
	push r24
	push r25
	push YL
	push YH

EEReadSeqToRam_L1:
	rcall EEReadPlus
	cpi r16,$FF		; inital empty protection
	brne EEReadSeqToRam_L2
	ldi r16,$00
EEReadSeqToRam_L2:
	st Y+, r16
	tst r16
	brne EEReadSeqToRam_L1

	pop YH
	pop YL
	pop r25
	pop r24
	pop r16
	ret

;----------------------------------------------------------
; Subroutine EESeqLen
; Get Length of Null-terminated sequence in EEPROM 
;----------------------------------------------------------
;
; Inputs:
;  r24 = Address in EEPROM low (Data null terminated)
;  r25 = Address in EEPROM high
;
; Outputs:
;  r17 = Length of Sequence
;

EESeqLen:
	push r16
	push r24
	push r25

	ldi r17,$00
EESeqLen_L1:
	rcall EEReadPlus
	cpi r16,$FF		; inital empty protection
	brne EESeqLen_L2
	ldi r16,$00
EESeqLen_L2:
	inc r17
	tst r16
	brne EESeqLen_L1
	dec r17

	pop r25
	pop r24
	pop r16
	ret

;----------------------------------------------------------
; Subroutine EEFlashSeqToRAM
; Write null-terminated sequence from Program-Memory to
; RAM - does not fit here but no-where better
;----------------------------------------------------------
; Inputs:
; Z-Registers(ZL/ZH) = Pointer to Data in program-fash
;	Null-terminated
; Y = Pointer to Ram-Area
;
EEFlashSeqToRAM:
	push r0
	push r16
	push YL
	push YH
	push ZL
	push ZH

	
EEF2R_L1:
	;;lpm r16,Z+ 	; is not supported on AVR 90S8515
	lpm				; defaults to lpm r0,Z
	mov r16,r0		; copy r0 to r16
	adiw ZH:ZL,$01 	; increment Z
    st Y+,r16		; store in ram-area
    tst r16			; test for Null
	brne EEF2R_L1

	pop ZH
	pop ZL
	pop YH
	pop YL
	pop r16
	pop r0
ret

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -