20.2.3 How to Implement In-System Programming
Before using the ISP function, the user should use a Universal Programmer, the “Megawin 8051 Writer” or the
“Megawin 8051 ICP Programmer” (see Section 20.4.1) to do the following configuration:
(1) Properly configure an ISP-memory according to size of the ‘loader program’.
(2) Program the ‘loader program’ (hereafter called ‘ISP code’) into this configured ISP-memory.
As we have known, the purpose of the ISP code is to program both AP-memory and IAP-memory. Therefore, the
MCU must boot from the ISP-memory in order to execute the ISP code. There are two methods to implement
In-System Programming according to how the MCU boots from the ISP-memory.
Method 1: MCU Directly Boots from ISP-memory at Power-up
To make the MCU directly boot from the ISP-memory when it is just powered on, the MCU’s hardware option
HWBS or HWBS2 must be enabled. Once HWBS or HWBS2 is enabled, the MCU will always boot from the ISP-
memory to execute the ISP code when it is just powered on. The first thing the ISP code should do is to check if
there is an ISP request. If there is no ISP requested, the ISP code should trigger a software reset to make the
MCU re-boot from the AP-memory to run the user’s application program. See the following flow chart.
Figure 20-5. Directly boot from ISP-memory (HWBS or HWBS2 is enabled)
Power on, or
Reset from RST-pin
"Reset from RST-pin" is
only for enabled HWBS2.
MCU boots from ISP-memory,
and starts to run the "ISP code".
NO
Check if ISP is requested?
YES
See Figure 20-2
for the flow chart
ISPCR=ISPCR&0xBF;
Do Flash Page Erase
Do Flash Program
//SWBS=0,
//select software-boot from AP-memory
ISPCR=ISPCR|0x20;
//SWRST=1,
//trigger software reset to reboot from AP-memory
See Figure 20-3
for the flow chart
See Figure 20-4
for the flow chart
Do Flash Read to verify
the programmed data
MCU will re-boot from AP-memory,
and run the normal "Application code"
End
MEGAWIN
MPC82G516A Data Sheet
102