嵌入的IAP汇编代码如下: $MOD_MX51
NAME IAP
?PR?_EraseBootLoader?IAP SEGMENT ECODE INSEG ?DT?_EraseBootLoader?IAP SEGMENT DATA OVERLAYABLE ?PR?_WriteBootLoader?IAP SEGMENT ECODE INSEG ?DT?_WriteBootLoader?IAP SEGMENT DATA OVERLAYABLE ?PR?_ReadBootLoader?IAP SEGMENT ECODE INSEG ?DT?_ReadBootLoader?IAP SEGMENT DATA OVERLAYABLE ?PR?_DelFlashByte?IAP SEGMENT ECODE INSEG ?DT?_DelFlashByte?IAP SEGMENT DATA OVERLAYABLE ?PR?_WriteFlashByte?IAP SEGMENT ECODE INSEG ?DT?_WriteFlashByte?IAP SEGMENT DATA OVERLAYABLE ?PR?_ReadFlashByte?IAP SEGMENT ECODE INSEG ?DT?_ReadFlashByte?IAP SEGMENT DATA OVERLAYABLE
PUBLIC _ReadFlashByte PUBLIC _WriteFlashByte PUBLIC _DelFlashByte PUBLIC _ReadBootLoader PUBLIC _WriteBootLoader PUBLIC _EraseBootLoader
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DPH DATA 083H DPL DATA 082H AUXR1 DATA 0A2H EA BIT 0AFH CMOD DATA 0D9H ACC DATA 0E0H IE DATA 0A8H ESFR EPL = 01FCH; ESFR EPM = 01FDH; ESFR EPH = 01FEH; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; XTAL_MHZ EQU 11 ; Chip runs at 11.0592MHz,no use ? PGM_MTP EQU 00FFF0H ; PGM-MTP routine enrty WriteDatByte EQU 02H ; program data byte ,function code ReadDatByte EQU 03H ; read device data of pointed address,function code EraseBlock EQU 0CH ; erase one of 11 blocks,function code EraseBL EQU 04H ; erase status or boot vector,function code ProgramBL EQU 06H ; program status byte or boot vector,function code FetchBL EQU 07H ; read status or boot vector,function code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; #define uINT8 unsigned char ; #define uINT16 unsigned int ; /*************************************************** ; **** unsigned char EraseBootLoader(uINT8 nDatAll); ; **** unsigned char DelFlashByte(uINT8 BlockHi, uINT8 FlashBlock); ; **** unsigned char WriteFlashByte(uINT8 FlashData, uINT16 FlashAddress); ; **** unsigned char ReadFlashByte(uINT16 FlashAddress); ; **** unsigned char WriteBootLoader(uINT8 nBL,uINT8 nDat); //nBL={0---StatusByte,1-----BootVectorMiddle,2----BootVectorHigh} ; **** //R7----uBL;R5------nDat ; **** unsigned char ReadBootLoader(uINT8 nBL); //nBL={0---SecERETByte,1-----StatusByte,2-----BootVector} ; **** //nBL=0/1/2/3/4/5 ; *****************************************************************/ ; void WaiteHere(uINT16 Delayus); ; ; /**************************************************************** ; *FUNCTION DESCRIBATION: ; * uINT8 nDatAll: dump variable ; * ; * ; * ; * ; ****************************************************************/ ; uINT8 EraseBootLoader(uINT8 nDatAll)
RSEG ?PR?_EraseBootLoader?IAP _EraseBootLoader: USING 0 PUSH IE CLR EA; //disable interrupt MOV A,CMOD MOV R2,A ; store copy of CMOD JNB ACC.6,?IAPTAG0 ; if watchdog enabled then disable ANL CMOD,#0BFH ?IAPTAG0: ORL AUXR1,#020H ; enable bootrom MOV R0,XTAL_MHZ ; osc frequency 11.0592MHz MOV R1,EraseBL ; function code ECALL PGM_MTP ;ECALL L?0014 ; WaiteHere(20); MOV R7,ACC ; ANL AUXR1,#0DFH ;disable boot-rom function MOV CMOD,R2; ;recover COMD register SETB EA; ; enable interrupt POP IE; ERET ; END OF _EraseBootLoader
; /**************************************************************** ; *FUNCTION DESCRIBATION: WriteBootLoader ; * uINT8 nBL : ; * uINT8 nDat: ; * ; * ; * ; ****************************************************************/ ; uINT8 WriteBootLoader(uINT8 nBL,uINT8 nDat)
RSEG ?PR?_WriteBootLoader?IAP _WriteBootLoader: USING 0 PUSH IE CLR EA; //disable interrupt MOV A,CMOD MOV R2,A ; store copy of CMOD JNB ACC.6,?IAPTAG1 ; if watchdog enabled then disable ANL CMOD,#0BFH ?IAPTAG1: ORL AUXR1,#020H ; enable bootrom MOV R0,XTAL_MHZ ; osc frequency 11.0592MHz MOV R1,ProgramBL ; function code MOV EPL, R7; which cell to be written MOV ACC, R5; data to be written ECALL PGM_MTP; ;ECALL L?0014 ; waite here for ready MOV R7,ACC; copy Flag of operation ANL AUXR1,#0DFH ;disable boot-rom function MOV CMOD,R2 ; recover COMD SETB EA; ; enable interrupt POP IE ERET ; END OF _WriteBootLoader
; /**************************************************************** ; *FUNCTION DESCRIBATION: ReadBootLoader ; * uINT8 nBL: ; * ; * ; * ; * ; ****************************************************************/ ; uINT8 ReadBootLoader(uINT8 nBL)
RSEG ?PR?_ReadBootLoader?IAP _ReadBootLoader: USING 0 PUSH IE CLR EA; //disable interrupt 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 R0,XTAL_MHZ ; osc frequency 11.0592MHz MOV R1,FetchBL ; function code MOV EPL, R7 ; ECALL PGM_MTP ; ;ECALL L?0014 ; waite for end of operation MOV R7,ACC; ANL AUXR1,#0DFH ;disable boot-rom function MOV CMOD,R2 ; recover COMD SETB EA; ; enable interrupt POP IE ERET ; END OF _ReadBootLoader
; /**************************************************************** ; *FUNCTION DESCRIBATION: DelFlashByte ; * uINT16 FlashBlock: ; * ; * ; * ; * ; ****************************************************************/ ; uINT8 DelFlashByte(uINT8 BlockHi, uINT8 FlashBlock)
RSEG ?PR?_DelFlashByte?IAP _DelFlashByte: USING 0 PUSH IE CLR EA; //disable interrupt MOV A,CMOD MOV R2,A ; store copy of CMOD JNB ACC.6,?IAPTAG3 ; if watchdog enabled then disable ANL CMOD,#0BFH ?IAPTAG3: ORL AUXR1,#020H ; enable bootrom MOV R0,XTAL_MHZ ; osc frequency 11.0592MHz MOV R1,EraseBlock ; function code MOV EPH, R7; MOV EPM, R5; ECALL PGM_MTP ; ;;;;;;;;;;;;;;;;;;Delay here for about 1 second ; ;;;;;;;;;End of waiting here ;;;;;;;;;;;;;;;;;; MOV R7,ACC; ANL AUXR1,#0DFH ;disable boot-rom function MOV CMOD,R2 ; recover COMD SETB EA; ; enable interrupt POP IE ERET ; END OF _DelFlashByte
; /**************************************************************** ; *FUNCTION DESCRIBATION: DelFlashByte ; * uINT16 FlashBlock: ; * ; * ; * ; * ; ****************************************************************/ ; uINT8 WriteFlashByte(uINT8 FlashData, uINT16 FlashAddress)
RSEG ?PR?_WriteFlashByte?IAP _WriteFlashByte: USING 0 PUSH IE CLR EA; //disable interrupt 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 R0,XTAL_MHZ ; osc frequency 11.0592MHz MOV R1,WriteDatByte ; function code MOV ACC, R7 ;data to be written MOV EPH,#00 ; MOV EPM,R4 ; MOV EPL,R5 ;which cell to be written ECALL PGM_MTP ; ;ECALL L?0014 ; waite for ready MOV R7,ACC ; ANL AUXR1,#0DFH ;disable boot-rom function MOV CMOD,R2 ; recover COMD SETB EA; ; enable interrupt POP IE ERET ; END OF _WriteFlashByte
; /**************************************************************** ; *FUNCTION DESCRIBATION: ReadFlashByte ; * uINT16 FlashAddress: ; * ; * ; * ; * ; ****************************************************************/ ; uINT8 ReadFlashByte(uINT16 FlashAddress)
RSEG ?PR?_ReadFlashByte?IAP _ReadFlashByte: USING 0 PUSH IE CLR EA; //disable interrupt MOV A,CMOD MOV R2,A ; store copy of CMOD JNB ACC.6,?IAPTAG5 ; if watchdog enabled then disable ANL CMOD,#0BFH ?IAPTAG5: ORL AUXR1,#020H ; enable bootrom MOV R0,XTAL_MHZ ; osc frequency 11.0592MHz MOV R1,ReadDatByte ; function code MOV EPH,#00 MOV EPM,R6; MOV EPL,R7; ECALL PGM_MTP ; ;ECALL L?0014 ; waite for ready MOV R7,ACC; ANL AUXR1,#0DFH ;disable boot-rom function MOV CMOD,R2 ; recover COMD SETB EA; ; enable interrupt POP IE; ERET ; END OF _ReadFlashByte
; /**************************************************************** ; *FUNCTION DESCRIBATION: WaiteHere ; * uINT16 Delayus: ; * ; * ; * ; * ; ****************************************************************/ ; void WaiteHere(uINT16 Delayus)
END |
|