MS51
Nov. 28, 2019
Page
260
of 491
Rev 1.00
MS51
32K
SE
RIES
TE
CHNICAL RE
F
EREN
CE MA
N
UAL
CLR
A
MOVC A,@A+DPTR
;Read content of address 201h
MOV
P0,A
SJMP $
C language demo code:
//*************************************************************************
*****
//
This code illustrates how to use IAP to make APROM 201h as a
byte of
//
Data Flash when user code is executed in APROM.
//*************************************************************************
*****
#define PAGE_ERASE_AP
0x22
#define BYTE_PROGRAM_AP
0x21
/*Data Flash, as part of APROM, is read by MOVC. Data Flash can be defined
as
128-element array in “code” area from absolute address 0x0200
*/
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