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

📄 eeprom.inc

📁 AMTEL公司阿avr mega系列单片机烧写eeprom的程序
💻 INC
字号:
;********************************************************************************************************;
;
; Name:		ee.inc
; Founction:	interface for internal eeprom
; MCU:		AVR
; Date:		2007-9-17 18:39
;
;********************************************************************************************************;

			RSEG	EEPROM_I

;********************************************************************************************************;

eei_user_code:		dw	4			 	; 客户代码: 泰达燃气





;********************************************************************************************************;

			RSEG	RCODE

;********************************************************************************************************;
; input:	x  -	address
;		AL -	data will be written

eei_byte_write:	push	AH
		mov	ah,	al
		rcall	eei_byte_read		; ->al
		cp	al,	ah
		breq	eei_byte_write_end

		in	AL,	SREG
		cli
		out	EEDR,	AH		;output data
		sbi 	EECR,	EEMPE		;set master write enable, remove if 1200 is used
		sbi	EECR,	EEPE		;set EEPROM Write strobe
						;This instruction takes 4 clock cycles since
						;it halts the CPU for two clock cycles
		out	SREG,	AL
eei_byte_write_end:
		pop	AH
		ret
;=======================================================================================================;
; input:	x  	-	address
;		AL.AH	-	data will be written
; output	x=x+2

eei_word_write:	rcall	eei_byte_write
		adiw	xl,	1
		mov	AL,	AH
		rcall	eei_byte_write
		adiw	xl,	1
		ret
;=======================================================================================================;
; input:	x  -	address
; output:	AL -	data

eei_byte_read:	sbic	EECR,	EEPE		;if EEPE not clear
		rjmp	eei_byte_read		;    wait more
		out 	EEARH,	xh		;output address high for mega88
		out	EEARL,	xl		;output address low for mega88
		sbi	EECR,	EERE		;set EEPROM Read strobe
						;This instruction takes 4 clock cycles since
						;it halts the CPU for two clock cycles
		in	AL,	EEDR		;get data
		ret
;=======================================================================================================;
; input:	x  	-	address
; output:	AL.AH	-	data
;		x=x+2

eei_word_read:	rcall	eei_byte_read
		push	AL
		adiw	xl,	1
		rcall	eei_byte_read
		mov	AH,	AL
		adiw	xl,	1
		pop	AL
		ret
;*******************************************************************************************************;
; founction:	(y+)	-> (x+)
; input:	x	- target address
;		y	- source address
;		z	- length

eei_seq_write:	push	AL
eei_seq_write_next:
		WDR
		ld	AL,	y+
		rcall	eei_byte_write
eei_seq_write_1:
		adiw	xl,	1
		sbiw	zl,	1
		brne	eei_seq_write_next
		pop	AL
		ret
;=======================================================================================================;
; founction:	(x+)	-> (y+)
; input:	x	- source address
;		y	- target address
;		z	- length

eei_seq_read:	push	AL
eei_seq_read_next:
		WDR
		rcall	eei_byte_read
		st	y+,	AL
		adiw	xl,	1
		sbiw	zl,	1
		brne	eei_seq_read_next
		pop	AL
		ret
;=======================================================================================================;
; founction:	(x-)	-> (y+)
; input:	x	- source address
;		y	- target address
;		dh	- length

eei_seq_to_string:
		rcall	eei_byte_read				; (x) -> al
		adiw	xl,	1
		rcall	get_ascii_word				; < subprg.inc > al-ah.al
		st	y+,	ah
		st	y+,	al
		dec	dh
		brne	eei_seq_to_string
		ret
;********************************************************************************************************;




⌨️ 快捷键说明

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