- //******************************************************************************
- // 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
- 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);
- }
|