📄 slli_nr.asm
字号:
BNZ $FlashGetInfo10 ;NO
;Calculate Block number from block number and bank.
MOV X,A
MOV A,[HL+2] ;Read data from flash information acquisition structure(=Block number)
MOV B,A
MOV A,[HL+1] ;Read data from flash information acquisition structure(=Bank)
;A...Bank, B...Block number
CALL !ExchangeBlockNum ;Block number is calculated from block number and bank.
;(Return A=Block number after it calculates)
BZ $FlashGetInfo20 ;It is error if the bank number is outside the range.
XCH A,X ;A...Option number, X...Block number
;Get info processing(When Option number = 5)
PUSH PSW ;Save register bank in STACK.
PUSH DE
PUSH AX
SEL RB3 ;Sets to register bank 3.
POP AX
XCH A,X
MOV [HL+0],A ;Sets entry RAM+0 to Block number
MOV A,X ;A...Option number
BR FlashGetInfo40
;Check of Option number error
FlashGetInfo10:
CMP A,#03H ;Option number = 3 ?
BZ $FlashGetInfo30 ;YES
CMP A,#04H ;Option number = 4 ?
BZ $FlashGetInfo30 ;YES
FlashGetInfo20:
MOV A,#FLASHFIRM_PARAMETER_ERROR ;The parameter error is returned, except when option NO is 3, 4, and 5.
BR FlashGetInfo50
;Get info processing(When Option number = 3,4)
FlashGetInfo30:
PUSH PSW ;Save register bank in STACK.
PUSH DE
PUSH AX
SEL RB3 ;Sets to register bank 3.
POP AX
FlashGetInfo40:
MOV [HL+3],A ;Sets entry RAM+3 to Option number
POP AX
MOV [HL+5],A ;Sets entry RAM+5 to Storage buffer higher address
MOV A,X
MOV [HL+4],A ;Sets entry RAM+4 to Storage buffer lower address
MOV C,#FLASH_GET_INF ;Sets function number to C register
CALL !8100H ;Calls flash firmware
POP PSW ;Restores register bank from STACK.
;Calculate Address from Storage buffer and bank.Nothing to do when Option number = 3or4 or Bank = 0
;or Block number(Previous) < 32 or Block number(Previous) >= 48.
;A=Option number, B=Bank, C...Block number(Previous), DE=Storage buffer first address of get data
CMP A,#05H ;Option number = 5 ?
BNZ $ReturnAddress_end ;NO
MOV A,B
CMP A,#0 ;Bank = 0 ?
BZ $ReturnAddress_end ;YES
XCH A,C
CMP A,#32 ;Block number(Previous) < 32 ?
BC $ReturnAddress_end ;YES
CMP A,#48 ;Block number(Previous) >= 48 ?
BNC $ReturnAddress_end ;YES
MOV A,C
;Calculation of address(40H*Bank is pulled from address in two high rank bytes.Lower address is the state as it is.)
XCHW AX,DE
MOVW HL,AX
MOV A,[HL+1]
MOV X,A
MOV A,[HL+2] ;A...Most higher address, X...Higher address
XCHW AX,DE ;A...Bank, D...Most higher address, E...Higher address
MOV [HL+2],A ;Sets Storage buffer+2 to Bank.
MOV X,#0
ROL A,1
ROL A,1
ROL A,1
ROL A,1
ROL A,1
ROLC A,1
XCH A,X
ROLC A,1 ;AX=40H*Bank
XCHW AX,DE
XCH A,X
SUB A,E
XCH A,X
SUBC A,D
MOV A,X
MOV [HL+1],A ;Sets Storage buffer+1 to Calculated address(higher).
ReturnAddress_end:
;Get flash firmware error information
MOV A,0FEE3H ;Sets flash firmware error information to return value
;(0FEE3H = B register of Bank 3)
FlashGetInfo50:
MOV C,A
MOV B,#00H
POP HL
RET
;-------------------------------------------------------------------
; Function name : _FlashSetInfo
; Input : AX=Flash information data
; Output : BC=Status
; Destroyed register : A,BC
; Summary : Setting of flash information.
;-------------------------------------------------------------------
_FlashSetInfo:
;Set infomation processing
MOV A,X
PUSH AX ;Save Flash information data in STACK.
PUSH PSW ;Save register bank in STACK.
SEL RB3 ;Sets to register bank 3.
MOVW AX,SP
ADDW AX,#2
MOV [HL+5],A ;Sets entry RAM+5 to higher address of flash information data secured for stack
MOV A,X
MOV [HL+4],A ;Sets entry RAM+4 to lower address of flash information data secured for stack
MOV C,#FLASH_SET_INF ;Sets function number to C register
CALL !8100H ;Calls flash firmware
POP PSW ;Restores register bank from STACK.
POP AX
;Get flash firmware error information
MOV A,0FEE3H ;Sets flash firmware error information to return value
;(0FEE3H = B register of Bank 3)
MOV C,A
MOV B,#00H
RET
;-------------------------------------------------------------------
; Function name : _CheckFLMD
; Input : None
; Output : BC=Status
; Destroyed register : A,BC
; Summary : Checks voltage level of FLMD pin.
;-------------------------------------------------------------------
_CheckFLMD:
;Set infomation processing
PUSH PSW ;Save register bank in STACK.
SEL RB3 ;Sets to register bank 3.
MOV C,#FLASH_CHECK_FLMD ;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)
MOV C,A
MOV B,#00H
RET
;-------------------------------------------------------------------
; Function name : _EEPROMWrite
; 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.
;-------------------------------------------------------------------
_EEPROMWrite:
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 $EW_PErr ;It is error if the bank number is outside the range.
;EEPROM 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_EEPROM_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 EEPROMWrite00
;Parameter error
EW_PErr:
MOV A,#FLASHFIRM_PARAMETER_ERROR ;Sets parameter error to return value
EEPROMWrite00:
MOV C,A
MOV B,#00H
POP HL
RET
;-------------------------------------------------------------------
; Function name : ExchangeBlockNum
; Input : A=Bank
; B=Block number
; Output : A=Block number(New)
; B=Bank
; C=Block number(Previous)
; Summary : Block number is converted into the real address
; from bank information.
;-------------------------------------------------------------------
ExchangeBlockNum:
;It calculates from 32 to 47 block number.
XCH A,B
CMP A,#32
BC $EBN_end
CMP A,#48
BNC $EBN_end
;Calculation of block number(Bank*16 is added to block number.)
XCH A,B
MOV C,A ;C...Bank
CMP A,#6
BNC $EBN_error_end
ROL A,1
ROL A,1
ROL A,1
ROL A,1 ;A=16*Bank
ADD A,B
XCH A,C
XCH A,B
XCH A,C ;A=Block number after it calculates, B=Bank,
;C=Block number before it calculates
BR EBN_end
;Bank error
EBN_error_end:
MOV A,#BANK_BLC_ERROR ;Return error number
EBN_end:
CMP A,#BANK_BLC_ERROR ;Bank error ?
RET
;-------------------------------------------------------------------
; Function name : ExchangeAddress
; Input : AX=Address of writing beginning address structure
; (Member of structure...Writing starting address
; Bank of writing starting address)
; Output : AX=Writing starting address(Address in two high rank bytes)
; C=Writing starting address(Lower address)
; Summary : Writing starting address of structure is converted
; into the real address from bank information.
;-------------------------------------------------------------------
ExchangeAddress:
PUSH HL
;It calculates from 8000H to BFFFH address.
MOVW HL,AX
MOV A,[HL+0] ;Read data from writing beginning address structure(=Write address)
MOV X,A
MOV A,[HL+1]
CMPW AX,#8000H
BC $EA_end
CMPW AX,#0C000H
BNC $EA_end
;Calculation of address(Bank*40H is added to address in two high rank bytes.Lower address is the state as it is.)
MOV D,A
XCH A,X
MOV C,A
MOV X,#0
MOV A,[HL+2] ;Read data from writing beginning address structure
;(=Bank of writing starting address)
CMP A,#6
BNC $EA_error_end
ROL A,1
ROL A,1
ROL A,1
ROL A,1
ROL A,1
ROLC A,1
XCH A,X
ROLC A,1 ;AX=40H*Bank
XCH A,X
ADD A,D ;Addition of Higher address
XCH A,X
ADDC A,#0 ;Addition of Most higher address
;A....Most higher address after it calculates
;X....higher address after it calculates, C...Lower address
BR EA_normal_end
;Bank error
EA_error_end:
MOVW AX,#BANK_ADDR_ERROR
BR EA_normal_end
EA_end:
XCH A,X
MOV C,A
MOV A,#0 ;A....Most higher address after it calculates
;X....higher address after it calculates, C...Lower address
EA_normal_end:
POP HL
CMPW AX,#BANK_ADDR_ERROR ;Bank error ?
RET
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -