📄 669iaplib.a51
字号:
$MOD_MX51
; module name
NAME P669IAPLIB
; SFRs and sbits required
AUXR1 DATA 0A2H
EA BIT 0AFH
CMOD DATA 0D9H
ACC DATA 0E0H
IE DATA 0A8H
ESFR EPH = 01FEH
ESFR EPM = 01FDH
ESFR EPL = 01FCH
; segments in this library
?PR?iap_read_security_bits?P669IAPLIB SEGMENT ECODE INSEG
?PR?_iap_program_data_byte?P669IAPLIB SEGMENT ECODE INSEG
?PR?_iap_read_data_byte?P669IAPLIB SEGMENT ECODE INSEG
?PR?_iap_erase_block?P669IAPLIB SEGMENT ECODE INSEG
; function names and global variables
PUBLIC iap_read_security_bits
PUBLIC _iap_program_data_byte
PUBLIC _iap_read_data_byte
PUBLIC _iap_erase_block
; **********************************************************************
; function: iap_read_security_bits
; prototype: unsigned char iap_read_security_bits(void);
; description: reads the security bits. The bits are returned in bit
; positions 1 to 3 (bit 1 = security bit 1).
; **********************************************************************
RSEG ?PR?iap_read_security_bits?P669IAPLIB
iap_read_security_bits:
PUSH IE ; disable interrupts
CLR EA
MOV A,CMOD
MOV R2,A ; store copy of CMOD
JNB ACC.6,?IAPTAG6 ; if watchdog enabled then disable
ANL CMOD,#0BFH
?IAPTAG6:
ORL AUXR1,#020H ; enable bootrom
MOV R1,#07H
MOV EPL,#05H
LCALL 00FFF0H ; call iap routine
MOV R7,A ; id in accumulator
ANL AUXR1,#0DFH ; disable bootrom
MOV CMOD,R2 ; restore CMOD (restore watchdog state)
POP IE ; restore interrupts to initial state
RET
; end of iap_read_security_bits
; **********************************************************************
; function: iap_program_data_byte
; prototype: unsigned char iap_program_data_byte
; (unsigned char val, unsigned int addr, unsigned char seg);
; description: programs a byte in the flash. passed is the byte, the
; 16-bit address and 64k segment number. zero is returned for success,
; non zero is returned for failure.
; **********************************************************************
RSEG ?PR?_iap_program_data_byte?P669IAPLIB
_iap_program_data_byte:
PUSH IE ; disable interrupts
CLR EA
MOV A,CMOD
MOV R2,A ; store copy of CMOD
JNB ACC.6,?IAPTAG11 ; if watchdog enabled then disable
ANL CMOD,#0BFH
?IAPTAG11:
ORL AUXR1,#020H ; enable bootrom
MOV R1,#02H
MOV EPH,R3 ; address to program
MOV EPM,R4
MOV EPL,R5
MOV A,R7 ; data to write
LCALL 00FFF0H ; call iap routine
MOV R7,A ; result in accumulator
ANL AUXR1,#0DFH ; disable bootrom
MOV CMOD,R2 ; restore CMOD (restore watchdog state)
POP IE ; restore interrupts to initial state
RET
; end of iap_program_data_byte
; **********************************************************************
; function: iap_read_data_byte
; prototype: unsigned char iap_read_data_byte
; (unsigned int addr, unsigned char seg);
; description: reads a byte from the flash. passed is the 16-bit
; address and 64k segment
; **********************************************************************
RSEG ?PR?_iap_read_data_byte?P669IAPLIB
_iap_read_data_byte:
PUSH IE ; disable interrupts
CLR EA
MOV A,CMOD
MOV R2,A ; store copy of CMOD
JNB ACC.6,?IAPTAG12 ; if watchdog enabled then disable
ANL CMOD,#0BFH
?IAPTAG12:
ORL AUXR1,#020H ; enable bootrom
MOV R1,#03H
MOV EPH,R5 ; address to program
MOV EPM,R6
MOV EPL,R7
LCALL 00FFF0H ; call iap routine
MOV R7,A ; result in accumulator
ANL AUXR1,#0DFH ; disable bootrom
MOV CMOD,R2 ; restore CMOD (restore watchdog state)
POP IE ; restore interrupts to initial state
RET
; end of iap_read_data_byte
; **********************************************************************
; function: iap_erase_block
; prototype: unsigned char iap_erase_block(unsigned int block);
; description: erases a block of flash. passed is a number indicating
; the block to erase. returns zero for success, non-zero for failure
; **********************************************************************
RSEG ?PR?_iap_erase_block?P669IAPLIB
_iap_erase_block:
PUSH IE ; disable interrupts
CLR EA
MOV A,CMOD
MOV R2,A ; store copy of CMOD
JNB ACC.6,?IAPTAG13 ; if watchdog enabled then disable
ANL CMOD,#0BFH
?IAPTAG13:
ORL AUXR1,#020H ; enable bootrom
MOV R1,#0CH
MOV EPH,R6 ; address to program
MOV EPM,R7
LCALL 00FFF0H ; call iap routine
MOV R7,A ; result in accumulator
ANL AUXR1,#0DFH ; disable bootrom
MOV CMOD,R2 ; restore CMOD (restore watchdog state)
POP IE ; restore interrupts to initial state
RET
; end of iap_erase_block
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -