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

📄 slli_nr.asm

📁 如何使用flash来模拟EEPROM
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;  System       : Self programming library(Normal model)
;  File name    : SelfLibrary_normal.asm
;  Version      : 2.00
;  Target CPU   : 78K0/Kx2
;  Last updated : 2005/07/08
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

PUBLIC	_FlashStart
PUBLIC	_FlashEnd
PUBLIC	_FlashEnv
PUBLIC	_FlashBlockErase
PUBLIC	_FlashWordWrite
PUBLIC	_FlashBlockVerify
PUBLIC	_FlashBlockBlankCheck
PUBLIC	_FlashGetInfo
PUBLIC	_FlashSetInfo
PUBLIC	_CheckFLMD
PUBLIC	_EEPROMWrite

;---------------------------------------------------------------------
;	EQU settings
;---------------------------------------------------------------------
FLASH_ENV				EQU	00H	;Initialization
FLASH_BLOCK_ERASE		EQU	03H	;Block erace
FLASH_WORD_WRITE		EQU	04H	;Word write
FLASH_BLOCK_VERIFY		EQU	06H	;Block verify
FLASH_BLOCK_BLANKCHECK	EQU	08H	;Block blank check
FLASH_GET_INF			EQU	09H	;Flash memory information read
FLASH_SET_INF			EQU	0AH	;Flash memory information setting
FLASH_CHECK_FLMD		EQU	0EH	;Mode check
FLASH_EEPROM_WRITE		EQU	17H	;EEPROM write

FLASHFIRM_PARAMETER_ERROR	EQU	05H	;Parameter error

BANK_BLC_ERROR			EQU	0FFH	;Bank number error(BLOCK)
BANK_ADDR_ERROR			EQU	0FFFFH	;Bank number error(ADDRESS)


SELF_PRG	CSEG	AT	7000H

;-------------------------------------------------------------------
; Function name 	: _FlashStart
; Input			: None
; Output		: None
; Destroyed register	: None
; Summary		: Self programming start processing.
;-------------------------------------------------------------------
_FlashStart:
	MOV	PFCMD,#0A5H		;PFCMD register control
	MOV	FLPMC,#001H		;FLPMC register control (set value)
	MOV	FLPMC,#0FEH		;FLPMC register control (inverted set value)
	MOV	FLPMC,#001H		;FLPMC register control (set value)
	RET

;-------------------------------------------------------------------
; Function name 	: _FlashEnd
; Input			: None
; Output		: None
; Destroyed register	: None
; Summary		: Self programming end processing.
;-------------------------------------------------------------------
_FlashEnd:
	MOV	PFCMD,#0A5H		;PFCMD register control
	MOV	FLPMC,#000H		;FLPMC register control (set value)
	MOV	FLPMC,#0FFH		;FLPMC register control (inverted set value)
	MOV	FLPMC,#000H		;FLPMC register control (set value)
	RET

;-------------------------------------------------------------------
; Function name 	: _FlashEnv
; Input			: AX=Entry RAM address
; Output		: None
; Destroyed register	: None
; Summary		: Initialization processing of self programming.
;-------------------------------------------------------------------
_FlashEnv:
;Initialization processing
	PUSH	PSW			;Save register bank in STACK.
	PUSH	AX
	SEL	RB3			;Sets to register bank 3.
	POP	HL			;Sets Entry RAM address to HL register
	MOV	C,#FLASH_ENV		;Sets function number to C register
	CALL	!8100H			;Calls flash firmware

	MOV	A, #09H
	MOV	[HL+13H], A		;Set Block Erase Retry Number
	MOV	[HL+14H], A		;Set Chip Erase Retry Number

	POP	PSW			;Restores register bank from STACK.
	RET

;-------------------------------------------------------------------
; Function name 	: _FlashBlockErase
; Input			: AX=Erase bank
;			  STACK=Erase block number
; Output		: BC=Status
; Destroyed register	: AX,BC
; Summary		: Erases of specified block (1K byte).
;-------------------------------------------------------------------
_FlashBlockErase:
	PUSH	HL

;Calculate Erase block number from block number and bank.
	MOVW	BC,AX
	MOVW	AX,SP
	MOVW	HL,AX
	MOV	A,[HL+4]		;Read STACK data(=Erase block number)
	MOV	B,A
	MOV	A,C			;A...Erase bank, B...Erase block number
	CALL	!ExchangeBlockNum	;Block number is calculated from block number and bank.
					;(Return A=Erase block number after it calculates)
	BZ	$FBE_PErr		;It is error if the bank number is outside the range.

;Block erase processing
	PUSH	PSW			;Save register bank in STACK.
	PUSH	AX
	SEL	RB3			;Sets to register bank 3.
	POP	AX
	MOV	[HL+3],A		;Sets entry RAM+3 to Erase block number after it calculates
	MOV	C,#FLASH_BLOCK_ERASE	;Sets function number to C register
	CALL	!8100H			;Calls flash firmware
	POP	PSW			;Restores register bank from STACK.

;Get flash firmware error information
	MOV	A,0FEE3H		;Sets flash firmware error information to return value
					;(0FEE3H = B register of Bank 3)
	BR	FlashBlockErase00

;Parameter error
FBE_PErr:
	MOV	A,#FLASHFIRM_PARAMETER_ERROR	;Sets parameter error to return value

FlashBlockErase00:
	MOV	C,A
	MOV	B,#00H
	POP	HL
	RET

;-------------------------------------------------------------------
; Function name 	: _FlashWordWrite
; Input			: AX=Address of writing beginning address structure
;			  (Member of structure...Writing starting address
;						 Bank of writing starting address)
;			  STACK1=Number of writing data
;			  STACK2=Address in writing data buffer
; Output		: BC=Status
; Destroyed register	: AX,BC,DE
; Summary		: Data on RAM is written in the flash memory.
;			  256 bytes or less (Every 4 bytes) are written at a time.
;-------------------------------------------------------------------
_FlashWordWrite:
	PUSH	HL

;Calculate Writing address from writing address and bank.
	MOVW	DE,AX
	MOVW	AX,SP
	MOVW	HL,AX
	MOV	A,[HL+4]		;Read STACK data(=Number of writing data)
	MOV	B,A
	MOV	A,[HL+6]		;Read STACK data(=Address in writing data buffer)
	XCH	A,X
	MOV	A,[HL+7]
	MOVW	HL,AX
	MOVW	AX,DE			;AX...Address of writing beginning address structure address,
					;B...Number of writing data,HL...Address in writing data buffer
	CALL	!ExchangeAddress	;Writing address is calculated from structure member's writing address and bank
					;(Return AX=Writing address)
	BZ	$FWW_PErr		;It is error if the bank number is outside the range.

;Word write processing
	PUSH	PSW			;Save register bank in STACK.
	PUSH	AX
	PUSH	BC
	PUSH	HL
	SEL	RB3			;Sets to register bank 3.
	POP	AX
	MOV	[HL+5],A		;Sets entry RAM+5 to higher address in writing data buffer
	MOV	A,X
	MOV	[HL+4],A		;Sets entry RAM+4 to lower address in writing data buffer
	POP	AX
	MOV	[HL+3],A		;Sets entry RAM+3 to Number of writing data
	MOV	A,X
	MOV	[HL+0],A		;Sets entry RAM+0 to Writing address lower bytes
	POP	AX
	MOV	[HL+2],A		;Sets entry RAM+2 to Writing address most higher bytes
	MOV	A,X
	MOV	[HL+1],A		;Sets entry RAM+1 to Writing address higher bytes
	MOV	C,#FLASH_WORD_WRITE	;Sets function number to C register
	CALL	!8100H			;Calls flash firmware
	POP	PSW			;Restores register bank from STACK.

;Get flash firmware error information
	MOV	A,0FEE3H		;Sets flash firmware error information to return value
					;(0FEE3H = B register of Bank 3)
	BR	FlashWordWrite00

;Parameter error
FWW_PErr:
	MOV	A,#FLASHFIRM_PARAMETER_ERROR	;Sets parameter error to return value

FlashWordWrite00:
	MOV	C,A
	MOV	B,#00H
	POP	HL
	RET

;-------------------------------------------------------------------
; Function name 	: _FlashBlockVerify
; Input			: AX=Verify bank
;			  STACK=Verify block number
; Output		: BC=Status
; Destroyed register	: AX,BC
; Summary		: Internal verify of specified block (1K byte).
;-------------------------------------------------------------------
_FlashBlockVerify:
	PUSH	HL

;Calculate Verify block number from block number and bank.
	MOVW	BC,AX
	MOVW	AX,SP
	MOVW	HL,AX
	MOV	A,[HL+4]		;Read STACK data(=Verify block number)
	MOV	B,A
	MOV	A,C			;A...Verify bank, B...Verify block number
	CALL	!ExchangeBlockNum	;Block number is calculated from block number and bank.
					;(Return A=Verify block number after it calculates)
	BZ	$FBV_PErr		;It is error if the bank number is outside the range.

;Block verify processing
	PUSH	PSW			;Save register bank in STACK.
	PUSH	AX
	SEL	RB3			;Sets to register bank 3.
	POP	AX
	MOV	[HL+3],A		;Sets entry RAM+3 to Verify block number after it calculates
	MOV	C,#FLASH_BLOCK_VERIFY	;Sets function number to C register
	CALL	!8100H			;Calls flash firmware
	POP	PSW			;Restores register bank from STACK.

;Get flash firmware error information
	MOV	A,0FEE3H		;Sets flash firmware error information to return value
					;(0FEE3H = B register of Bank 3)
	BR	FlashBlockVerify00

;Parameter error
FBV_PErr:
	MOV	A,#FLASHFIRM_PARAMETER_ERROR	;Sets parameter error to return value

FlashBlockVerify00:
	MOV	C,A
	MOV	B,#00H
	POP	HL
	RET

;-------------------------------------------------------------------
; Function name 	: _FlashBlockBlankCheck
; Input			: AX=Blank check bank
;			  STACK=Blank check block number
; Output		: BC=Status
; Destroyed register	: AX,BC
; Summary		: Blank check of specified block (1K byte).
;-------------------------------------------------------------------
_FlashBlockBlankCheck:
	PUSH	HL

;Calculate Blank check block number from block number and bank.
	MOVW	BC,AX
	MOVW	AX,SP
	MOVW	HL,AX
	MOV	A,[HL+4]			;Read STACK data(=Blank check block number)
	MOV	B,A
	MOV	A,C				;A...Blank check bank, B...Blank check block number
	CALL	!ExchangeBlockNum		;Block number is calculated from block number and bank.
						;(Return A=Blank check block number after it calculates)
	BZ	$FBBC_PErr			;It is error if the bank number is outside the range.

;Block blank check processing
	PUSH	PSW				;Save register bank in STACK.
	PUSH	AX
	SEL	RB3				;Sets to register bank 3.
	POP	AX
	MOV	[HL+3],A			;Sets entry RAM+3 to Blank check block number after it calculates
	MOV	C,#FLASH_BLOCK_BLANKCHECK	;Sets function number to C register
	CALL	!8100H				;Calls flash firmware
	POP	PSW				;Restores register bank from STACK.

;Get flash firmware error information
	MOV	A,0FEE3H			;Sets flash firmware error information to return value
						;(0FEE3H = B register of Bank 3)
	BR	FlashBlockBlankCheck00

;Parameter error
FBBC_PErr:
	MOV	A,#FLASHFIRM_PARAMETER_ERROR	;Sets parameter error to return value

FlashBlockBlankCheck00:
	MOV	C,A
	MOV	B,#00H
	POP	HL
	RET

;-------------------------------------------------------------------
; Function name		: _FlashGetInfo
; Input			: AX=Address of flash information acquisition structure
;			  (Member of structure...Option number
;						 Bank
;						 Block number)
;			  STACK=The first address in buffer where get data is stored
; Output		: BC=Status
; Destroyed register	: AX,BC,DE
; Summary		: The set up information of the flash memory is read.
;-------------------------------------------------------------------
_FlashGetInfo:
	PUSH	HL

;Check of Option number
	MOVW	BC,AX
	MOVW	AX,SP
	MOVW	HL,AX
	MOV	A,[HL+4]		;Read STACK data(=The first address in buffer where get data is stored)
	XCH	A,X
	MOV	A,[HL+5]
	XCHW	AX,BC			;AX...Address of flash information acquisition structure
					;BC...The first address in buffer where get data is stored
	MOVW	HL,AX
	MOVW	AX,BC
	MOVW	DE,AX
	MOV	A,[HL+0]		;Read data from flash information acquisition structure(=Option number)
	CMP	A,#05H			;Option number = 5 ?

⌨️ 快捷键说明

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