
MS51
Dec. 17, 2019
Page
186
of 316
Rev 1.01
M
S51
SE
RIES
TE
CHNICA
L REF
ERE
N
CE MA
NU
A
L
volatile unsigned char code Data_Flash[128] _at_ 0x0200;
Main (void)
{
TA = 0Xaa;
//CHPCON is TA protected
TA = 0x55;
CHPCON |= 0x01;
//IAPEN = 1, enable IAP mode
TA = 0Xaa;
//IAPUEN is TA protected
TA = 0x55;
IAPUEN |= 0x01;
//APUEN = 1, enable APROM update
IAPCN = PAGE_ERASE_AP;
//Erase page 200h~27Fh
IAPAH = 0x02;
IAPAL = 0x00;
IAPFD = 0Xff;
TA = 0Xaa;
//IAPTRG is TA protected
TA = 0x55;
IAPTRG |= 0x01;
//write ‘1’ to IAPGO to trigger IAP process
IAPCN = BYTE_PROGRAM_AP;
// Program 201h with 55h
IAPAH = 0x02;
IAPAL = 0x01;
IAPFD = 0x55;
TA = 0Xaa;
TA = 0x55;
IAPTRG |= 0x01;
//write ‘1’ to IAPGO to trigger IAP process
TA = 0Xaa;
//IAPUEN is TA protected
TA = 0x55;
IAPUEN &= ~0x01;
//APUEN = 0, disable APROM update
TA = 0Xaa;
//CHPCON is TA protected
TA = 0x55;
CHPCON &= ~0x01;
//IAPEN = 0, disable IAP mode
P0 = Data_Flash[1];
//Read content of address 200h+1
while(1);
}
In-System-Programming (ISP)
6.3.1.5
The Flash Memory supports both hardware programming and In-Application-Programming (IAP). If the
product is just under development or the end product needs firmware updating in the hand of an end
user, the hardware programming mode will make repeated programming difficult and inconvenient. In-
System-Programming (ISP) makes it easy and possible. ISP performs Flash Memory updating without
removing the microcontroller from the system. It allows a device to be re-programmed under software
control. Furthermore, the capability to update the application firmware makes wide range of
applications possible.
User can develop a custom Boot Code that resides in LDROM. The maximum size of LDROM is 4K
Byte. User developed Boot Code can be re-programmed by parallel writer or In-Circuit-Programming
(ICP) tool.
General speaking, an ISP is carried out by a communication between PC and MCU. PC transfers the
new User Code to MCU through serial port. Then Boot Code receives it and re-programs into User
Code through IAP commands. Nuvoton provides ISP firmware and PC application for MS51. It makes