ML51Dec. 05, 2018 Page 344 of 401 Rev 1.00ML51 SERIES TECHNICAL REFERENCE MANUAL27.2 IAP User GuideIAP facilitates the updating Flash contents in a convenient way; however, user should follow somerestricted laws in order that the IAP operates correctly. Without noticing warnings will possible causeundetermined results even serious damages of devices. Furthermore, this paragraph will also supportuseful suggestions during IAP procedures.(1) If no more IAP operation is needed, user should clear IAPEN (CHPCON.0). It will make the systemvoid to trigger IAP unaware. Furthermore, IAP requires the HIRC running. If the external clock sourceis selected, disabling IAP will stop the HIRC for saving power consumption. Note that a write to IAPENis TA protected.(2) When the LOCK bit (CONFIG0.1) is activated, IAP reading, writing, or erasing can still be valid.During IAP progress, interrupts (if enabled) should be disabled temporally by clearing EA bitfor implement limitation.Do not attempt to erase or program to a page that the code is currently executing. This willcause unpredictable program behavior and may corrupt program data.27.3 Using Flash Memory as Data StorageIn general application, there is a need of data storage, which is non-volatile so that it remains itscontent even after the power is off. Therefore, in general application user can read back or update thedata, which rules as parameters or constants for system control. The Flash Memory array of the ML51supports IAP function and any byte in the Flash Memory array may be read using the MOVCinstruction and thus is suitable for use as non-volatile data storage. IAP provides erase and programfunction that makes it easy for one or more bytes within a page to be erased and programmed in aroutine. IAP performs in the application under the control of the microcontroller’s firmware. Be awareof Flash Memory writing endurance of 100,000 cycles. A demo is illustrated as follows.Assembly 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.;**************************************************************************PAGE_ERASE_AP EQU 00100010bBYTE_PROGRAM_AP EQU 00100001bORG 0000hMOV TA,#0Aah ;CHPCON is TA protectedMOV TA,#55hORL CHPCON,#00000001b ;IAPEN = 1, enable IAP mode