MS51
Dec. 17, 2019
Page
187
of 316
Rev 1.01
M
S51
SE
RIES
TE
CHNICA
L REF
ERE
N
CE MA
NU
A
L
user quite easy perform ISP through UART port. Please visit Nuvoton 8-bit Microcontroller website:
Nuvoton 80C51 Microcontroller Technical Support
. A simple ISP demo code is given below.
Assembly demo code:
;**************************************************************************
;
This code illustrates how to do APROM and CONFIG IAP from LDROM.
;
APROM are re-programmed by the code to output P1 as 55h and P2 as aah.
;
The CONFIG2 is also updated to disable BOD reset.
;
User needs to configure CONFIG0 = 0x7F, CONFIG1 = 0Xfe, CONFIG2 = 0Xff.
;**************************************************************************
PAGE_ERASE_AP
EQU
00100010b
BYTE_PROGRAM_AP
EQU
00100001b
BYTE_READ_AP
EQU
00000000b
ALL_ERASE_CONFIG
EQU
11100010b
BYTE_PROGRAM_CONFIG
EQU
11100001b
BYTE_READ_CONFIG
EQU
11000000b
ORG 0000h
CLR EA
;disable all interrupts
CALL Enable_IAP
CALL Enable_AP_Update
CALL Erase_AP
;erase AP data
CALL Program_AP
;programming AP data
CALL Disable_AP_Update
CALL Program_AP_Verify
;verify Programmed AP data
CALL Read_CONFIG
;read back CONFIG2
CALL Enable_CONFIG_Update
CALL Erase_CONFIG
;erase CONFIG bytes
CALL Program_CONFIG
;programming CONFIG2 with new data
CALL Disable_CONFIG_Update
CALL Program_CONFIG_Verify
;verify Programmed CONFIG2
CALL Disable_IAP
MOV TA,#0Aah
;TA protection
MOV TA,#55h
;
ANL CHPCON,#11111101b
;BS = 0, reset to APROM
MOV TA,#0Aah
MOV TA,#55h
ORL CHPCON,#80h
;software reset and reboot from APROM
SJMP $
;********************************************************************
;
IAP Subroutine
;********************************************************************
Enable_IAP:
MOV TA,#0Aah
;CHPCON is TA protected
MOV TA,#55h
ORL CHPCON,#00000001b
;IAPEN = 1, enable IAP mode
RET
Disable_IAP:
MOV TA,#0Aah
MOV TA,#55h
ANL CHPCON,#11111110b
;IAPEN = 0, disable IAP mode