📄 669iaplib.a51
字号:
; 669IAPLIB
; In-Application-Programming Library for the Philips P89C669 device
; This library was developed for the Keil Compiler for interfacing
; to C programs
; Use ROM size HUGE or adapt for other ROM models
; Version 1.00 (18-Sep-2003)
; - first version
; by A. Ayre
; (C) Embedded Systems Academy 2003
$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_manufacturer_id?P669IAPLIB SEGMENT ECODE INSEG
?PR?_iap_read_device_id?P669IAPLIB SEGMENT ECODE INSEG
?PR?iap_read_security_bits?P669IAPLIB SEGMENT ECODE INSEG
?PR?_iap_program_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
?PR?iap_read_boot_vector?P669IAPLIB SEGMENT ECODE INSEG
?PR?iap_read_status_byte?P669IAPLIB SEGMENT ECODE INSEG
?PR?iap_erase_bv_sb?P669IAPLIB SEGMENT ECODE INSEG
?PR?_iap_program_status_byte?P669IAPLIB SEGMENT ECODE INSEG
?PR?_iap_program_boot_vector?P669IAPLIB SEGMENT ECODE INSEG
; function names and global variables
PUBLIC iap_read_manufacturer_id
PUBLIC _iap_read_device_id
PUBLIC iap_read_security_bits
PUBLIC _iap_program_security_bits
PUBLIC _iap_program_data_byte
PUBLIC _iap_read_data_byte
PUBLIC _iap_erase_block
PUBLIC iap_read_boot_vector
PUBLIC iap_read_status_byte
PUBLIC iap_erase_bv_sb
PUBLIC _iap_program_status_byte
PUBLIC _iap_program_boot_vector
; **********************************************************************
; function: iap_read_manufacturer_id
; prototype: unsigned char iap_read_manufacturer_id(void);
; description: returns manufacturer id (15H = Philips)
; **********************************************************************
RSEG ?PR?iap_read_manufacturer_id?P669IAPLIB
iap_read_manufacturer_id:
USING 0
PUSH IE ; disable interrupts
CLR EA
MOV A,CMOD
MOV R2,A ; store copy of CMOD
JNB ACC.6,?IAPTAG2 ; if watchdog enabled then disable
ANL CMOD,#0BFH
?IAPTAG2:
ORL AUXR1,#020H ; enable bootrom
MOV R1,#00H
MOV EPL,#00H
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
ERET
; end of iap_read_manufacturer_id
; **********************************************************************
; function: iap_read_device_id
; prototype: unsigned char iap_read_device_id(unsigned char id_number);
; description: reads the device id number. id_number may be 1 or 2.
; **********************************************************************
RSEG ?PR?_iap_read_device_id?P669IAPLIB
_iap_read_device_id:
PUSH IE ; disable interrupts
CLR EA
MOV A,CMOD
MOV R2,A ; store copy of CMOD
JNB ACC.6,?IAPTAG4 ; if watchdog enabled then disable
ANL CMOD,#0BFH
?IAPTAG4:
ORL AUXR1,#020H ; enable bootrom
MOV R1,#00H
MOV EPL,R7 ; id number to read
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
ERET
; end of iap_read_device_id
; **********************************************************************
; 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
ERET
; end of iap_read_security_bits
; **********************************************************************
; function: iap_program_security_bits
; prototype: void iap_program_security_bits(unsigned char bits);
; description: programs the security bits. The bits are stored in bit
; positions 1 to 3 (bit 1 = security bit 1).
; **********************************************************************
RSEG ?PR?_iap_program_security_bits?P669IAPLIB
_iap_program_security_bits:
; prologue
PUSH IE ; disable interrupts
CLR EA
MOV A,CMOD
MOV R2,A ; store copy of CMOD
JNB ACC.6,?IAPTAG10 ; if watchdog enabled then disable
ANL CMOD,#0BFH
?IAPTAG10:
ORL AUXR1,#020H ; enable bootrom
MOV R6,#00H ; bit counter
MOV A,R7 ; copy param into acc
; end of prologue
?IAPTAG7:
JNB ACC.1,?IAPTAG8 ; test if lsb of acc is set
MOV R1,#05H
MOV EPL,R6 ; set EPL to bit to program (0-index)
LCALL 00FFF0H
?IAPTAG8:
CLR C ; shift acc right one bit
RRC A
INC R6 ; increment bit counter
CJNE R6,#003H,?IAPTAG9 ; have we gone through 3 bits?
?IAPTAG9:
JC ?IAPTAG7 ; jump back to program next bit
; epologue
ANL AUXR1,#0DFH ; disable bootrom
MOV CMOD,R2 ; restore CMOD (restore watchdog state)
POP IE ; restore interrupts to initial state
ERET
; end of epilogue
; end of iap_program_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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -