
; CC5X Version 3.8, Copyright (c) B Knudsen Data
; C compiler for the PICmicro family
; ************   1. Sep 2022  19:43  *************

        processor  OB36A01A1
        radix  DEC

PCL         EQU   0x02
STATUS      EQU   0x03
PORTA       EQU   0x05
PORTB       EQU   0x06
PCLATH      EQU   0x0A
Carry       EQU   0
Zero_       EQU   2
RP0         EQU   5
RP1         EQU   6
ANSELA      EQU   0x07
ANSELB      EQU   0x08
PAM0        EQU   0x0F
PAM1        EQU   0x10
PBIM        EQU   0x11
TAKEY       EQU   0x1F
SCON0       EQU   0x8E
SCON1       EQU   0x8F
SRELL       EQU   0x90
SRELH       EQU   0x91
SBUF        EQU   0x92
IAPC        EQU   0x93
IAPAL       EQU   0x94
IAPAH       EQU   0x95
IAPDL       EQU   0x96
IAPDH       EQU   0x97
PA_0        EQU   0
PB_0        EQU   0
TXIF        EQU   1
g_Data      EQU   0x27
g_StartAddr EQU   0x29
svrWREG     EQU   0x20
svrSTATUS   EQU   0x21
Data        EQU   0x26
i           EQU   0x22
j           EQU   0x23
tmpData     EQU   0x24
NoteByte    EQU   0x25
i_2         EQU   0x7F
j_2         EQU   0x7F
tmpData_2   EQU   0x7F
i_3         EQU   0x7F
tmpData_3   EQU   0x7F
i_4         EQU   0x7F
Temp        EQU   0x7F
i_5         EQU   0x7F
ci          EQU   0x26

        GOTO main

  ; FILE .\IAP.c
                        ;#include "int16CXX.h"
                        ;
                        ;#pragma interruptSaveCheck  n
                        ;
                        ;
                        ;////////////////////////////////////////////////////////////////////////////////
                        ;// Interrupt ISR
                        ;////////////////////////////////////////////////////////////////////////////////
                        ;uns16 g_Data,g_StartAddr;
                        ;
                        ;void Sub_ALLINT(void);
                        ;void Check_SFR();
                        ;
                        ;#pragma unlockISR   // If the ISR address!=0x04, you will do this.
                        ;#pragma origin 4    // Define the following code at flash address 0x04
        ORG 0x0004
                        ;interrupt INTR_ISR( void)
                        ;{
INTR_ISR
                        ;    Sub_ALLINT();    
        CALL  Sub_ALLINT
                        ;}
        RETFIE
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Sub_ALLINT()
                        ;{
_const1
        BCF   0x03,RP0
        MOVWF ci
        MOVLW 28
        SUBWF ci,W
        BTFSC 0x03,Carry
        RETLW 0
        BCF   0x03,RP0
        CLRF  PCLATH
        MOVF  ci,W
        ADDWF PCL,1
        RETLW 153
        RETLW 0
        RETLW 152
        RETLW 1
        RETLW 151
        RETLW 2
        RETLW 150
        RETLW 3
        RETLW 149
        RETLW 4
        RETLW 18
        RETLW 0
        RETLW 52
        RETLW 0
        RETLW 86
        RETLW 0
        RETLW 120
        RETLW 0
        RETLW 1
        RETLW 2
        RETLW 3
        RETLW 4
        RETLW 5
        RETLW 6
        RETLW 7
        RETLW 8
        RETLW 9
        RETLW 10
Sub_ALLINT
                        ;    int_save_registers    // W, STATUS (and PCLATH)
        MOVWF svrWREG
        SWAPF STATUS,W
        BCF   0x03,RP0
        BCF   0x03,RP1
        MOVWF svrSTATUS
                        ;
                        ;   
                        ;    int_restore_registers // W, STATUS (and PCLATH)
        SWAPF svrSTATUS,W
        MOVWF STATUS
        SWAPF svrWREG,1
        SWAPF svrWREG,W
                        ;}
        RETURN
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Initiate_UART()
                        ;{	
Initiate_UART
                        ;	SCON0=0x80;
        MOVLW 128
        BSF   0x03,RP0
        MOVWF SCON0
                        ;	SCON1=0x00;
        CLRF  SCON1
                        ;
                        ;	//9600
                        ;	SRELH=0x03;
        MOVLW 3
        MOVWF SRELH
                        ;	SRELL=0xF3;				
        MOVLW 243
        MOVWF SRELL
                        ;}
        RETURN
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Send_Data(uns8 Data)
                        ;{
Send_Data
        BCF   0x03,RP0
        MOVWF Data
                        ;	SBUF=Data;
        MOVF  Data,W
        BSF   0x03,RP0
        MOVWF SBUF
                        ;	
                        ;	while(TXIF==0);		
m001    BSF   0x03,RP0
        BTFSS 0x8E,TXIF
        GOTO  m001
                        ;			
                        ;	TXIF=0;		
        BSF   0x03,RP0
        BCF   0x8E,TXIF
                        ;}
        RETURN
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Test_IAP_Function_Enable()
                        ;{
Test_IAP_Function_Enable
                        ;	TAKEY=0x55;
        MOVLW 85
        BCF   0x03,RP0
        MOVWF TAKEY
                        ;	TAKEY=0xAA;
        MOVLW 170
        MOVWF TAKEY
                        ;	TAKEY=0x5A;
        MOVLW 90
        MOVWF TAKEY
                        ;	
                        ;	IAPC |=0x80;
        BSF   0x03,RP0
        BSF   IAPC,7
                        ;	
                        ;	TAKEY=0x00;
        BCF   0x03,RP0
        CLRF  TAKEY
                        ;	
                        ;	Send_Data(IAPC);
        BSF   0x03,RP0
        MOVF  IAPC,W
        CALL  Send_Data
                        ;
                        ;	//------------------------------
                        ;	//bit 7 should not be written to 0
                        ;	//IAPC &=0x7f;
                        ;	IAPC=0x00;
        BSF   0x03,RP0
        CLRF  IAPC
                        ;	
                        ;	Send_Data(IAPC);
        MOVF  IAPC,W
        CALL  Send_Data
                        ;
                        ;	//------------------------------
                        ;	TAKEY=0x55;
        MOVLW 85
        BCF   0x03,RP0
        MOVWF TAKEY
                        ;	TAKEY=0xAA;
        MOVLW 170
        MOVWF TAKEY
                        ;	TAKEY=0x5A;
        MOVLW 90
        MOVWF TAKEY
                        ;	
                        ;	IAPC &=0x7f;
        BSF   0x03,RP0
        BCF   IAPC,7
                        ;	//IAPC=0x00;
                        ;	
                        ;	TAKEY=0x00;
        BCF   0x03,RP0
        CLRF  TAKEY
                        ;
                        ;	Send_Data(IAPC);
        BSF   0x03,RP0
        MOVF  IAPC,W
        GOTO  Send_Data
                        ;	
                        ;}
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Test_Code_Read_Write()
                        ;{
Test_Code_Read_Write
                        ;	uns8 i,j,tmpData,NoteByte;
                        ;	uns8 static const Data[10]={0x99,0x00,0x98,0x01,0x97,0x02,0x96,0x03,0x95,0x04};
                        ;
                        ;	
                        ;	TAKEY=0x55;
        MOVLW 85
        BCF   0x03,RP0
        MOVWF TAKEY
                        ;	TAKEY=0xAA;
        MOVLW 170
        MOVWF TAKEY
                        ;	TAKEY=0x5A;
        MOVLW 90
        MOVWF TAKEY
                        ;	
                        ;	IAPC=0x80;
        MOVLW 128
        BSF   0x03,RP0
        MOVWF IAPC
                        ;	
                        ;	TAKEY=0x00;
        BCF   0x03,RP0
        CLRF  TAKEY
                        ;
                        ;	for(j=0;j<2;j++)
        CLRF  j
m002    MOVLW 2
        BCF   0x03,RP0
        SUBWF j,W
        BTFSC 0x03,Carry
        GOTO  m015
                        ;	{
                        ;		if(j==1)
        DECFSZ j,W
        GOTO  m004
                        ;		{
                        ;			IAPAH= 0x00;
        BSF   0x03,RP0
        CLRF  IAPAH
                        ;			IAPAL= 0x00;	
        CLRF  IAPAL
                        ;
                        ;			NoteByte=0x6A;
        MOVLW 106
        BCF   0x03,RP0
        MOVWF NoteByte
                        ;			
                        ;			for(i=0;i<5;i++)
        CLRF  i
m003    MOVLW 5
        BCF   0x03,RP0
        SUBWF i,W
        BTFSC 0x03,Carry
        GOTO  m004
                        ;			{		
                        ;				IAPC=0x80;	//Read Code
        MOVLW 128
        BSF   0x03,RP0
        MOVWF IAPC
                        ;				
                        ;				Send_Data(IAPC);
        MOVF  IAPC,W
        CALL  Send_Data
                        ;				Send_Data(NoteByte);
        BCF   0x03,RP0
        MOVF  NoteByte,W
        CALL  Send_Data
                        ;				Send_Data(IAPAH);
        BSF   0x03,RP0
        MOVF  IAPAH,W
        CALL  Send_Data
                        ;				Send_Data(IAPAL);
        BSF   0x03,RP0
        MOVF  IAPAL,W
        CALL  Send_Data
                        ;				Send_Data(NoteByte);
        BCF   0x03,RP0
        MOVF  NoteByte,W
        CALL  Send_Data
                        ;				Send_Data(IAPDH);
        BSF   0x03,RP0
        MOVF  IAPDH,W
        CALL  Send_Data
                        ;				Send_Data(IAPDL);
        BSF   0x03,RP0
        MOVF  IAPDL,W
        CALL  Send_Data
                        ;				Send_Data(NoteByte);	
        BCF   0x03,RP0
        MOVF  NoteByte,W
        CALL  Send_Data
                        ;				
                        ;				IAPAL+=1;		
        BSF   0x03,RP0
        INCF  IAPAL,1
                        ;			}			
        BCF   0x03,RP0
        INCF  i,1
        GOTO  m003
                        ;		}
                        ;	
                        ;		//--------------------------------------
                        ;		//Write code
                        ;		if(j==0)
m004    BCF   0x03,RP0
        MOVF  j,1
        BTFSS 0x03,Zero_
        GOTO  m005
                        ;		{
                        ;			
                        ;			IAPAH= g_StartAddr>>8;	//address read from OP09
        MOVF  g_StartAddr+1,W
        BSF   0x03,RP0
        MOVWF IAPAH
                        ;			IAPAL= g_StartAddr;
        BCF   0x03,RP0
        MOVF  g_StartAddr,W
        BSF   0x03,RP0
        MOVWF IAPAL
                        ;			
                        ;			NoteByte=0xFF;
        MOVLW 255
        BCF   0x03,RP0
        MOVWF NoteByte
                        ;		}
                        ;		else
        GOTO  m006
                        ;		{
                        ;			IAPAH= 0x02;
m005    MOVLW 2
        BSF   0x03,RP0
        MOVWF IAPAH
                        ;			IAPAL= 0x00;	
        CLRF  IAPAL
                        ;
                        ;			NoteByte=0x4A;
        MOVLW 74
        BCF   0x03,RP0
        MOVWF NoteByte
                        ;		}
                        ;		
                        ;		for(i=0;i<5;i++)
m006    BCF   0x03,RP0
        CLRF  i
m007    MOVLW 5
        BCF   0x03,RP0
        SUBWF i,W
        BTFSC 0x03,Carry
        GOTO  m008
                        ;		{
                        ;			
                        ;			IAPDL= Data[i*2+1];
        BCF   0x03,Carry
        RLF   i,W
        ADDLW 1
        CALL  _const1
        BSF   0x03,RP0
        MOVWF IAPDL
                        ;			IAPDH= Data[i*2];
        BCF   0x03,Carry
        BCF   0x03,RP0
        RLF   i,W
        CALL  _const1
        BSF   0x03,RP0
        MOVWF IAPDH
                        ;			
                        ;			IAPC=0x81;	//Write Code
        MOVLW 129
        MOVWF IAPC
                        ;			
                        ;			Send_Data(IAPC);
        MOVF  IAPC,W
        CALL  Send_Data
                        ;			Send_Data(NoteByte);
        BCF   0x03,RP0
        MOVF  NoteByte,W
        CALL  Send_Data
                        ;			Send_Data(IAPAH);
        BSF   0x03,RP0
        MOVF  IAPAH,W
        CALL  Send_Data
                        ;			Send_Data(IAPAL);
        BSF   0x03,RP0
        MOVF  IAPAL,W
        CALL  Send_Data
                        ;			Send_Data(NoteByte);
        BCF   0x03,RP0
        MOVF  NoteByte,W
        CALL  Send_Data
                        ;			Send_Data(IAPDH);
        BSF   0x03,RP0
        MOVF  IAPDH,W
        CALL  Send_Data
                        ;			Send_Data(IAPDL);
        BSF   0x03,RP0
        MOVF  IAPDL,W
        CALL  Send_Data
                        ;			Send_Data(NoteByte);
        BCF   0x03,RP0
        MOVF  NoteByte,W
        CALL  Send_Data
                        ;
                        ;			IAPAL+=1;		
        BSF   0x03,RP0
        INCF  IAPAL,1
                        ;		}
        BCF   0x03,RP0
        INCF  i,1
        GOTO  m007
                        ;		
                        ;		//--------------------------------------
                        ;		//Read code
                        ;		if(j==0)
m008    BCF   0x03,RP0
        MOVF  j,1
        BTFSS 0x03,Zero_
        GOTO  m009
                        ;		{
                        ;			IAPAH= g_StartAddr>>8;
        MOVF  g_StartAddr+1,W
        BSF   0x03,RP0
        MOVWF IAPAH
                        ;			IAPAL= g_StartAddr;
        BCF   0x03,RP0
        MOVF  g_StartAddr,W
        BSF   0x03,RP0
        MOVWF IAPAL
                        ;			
                        ;			NoteByte=0xFF;
        MOVLW 255
        BCF   0x03,RP0
        MOVWF NoteByte
                        ;		}
                        ;		else
        GOTO  m010
                        ;		{
                        ;			IAPAH= 0x02;
m009    MOVLW 2
        BSF   0x03,RP0
        MOVWF IAPAH
                        ;			IAPAL= 0x00;	
        CLRF  IAPAL
                        ;
                        ;			NoteByte=0x4A;
        MOVLW 74
        BCF   0x03,RP0
        MOVWF NoteByte
                        ;		}
                        ;
                        ;		//it should fail to read data when j=1 (read outside address of IAP range)
                        ;		for(i=0;i<5;i++)
m010    BCF   0x03,RP0
        CLRF  i
m011    MOVLW 5
        BCF   0x03,RP0
        SUBWF i,W
        BTFSC 0x03,Carry
        GOTO  m014
                        ;		{		
                        ;			IAPC=0x80;	//Read Code
        MOVLW 128
        BSF   0x03,RP0
        MOVWF IAPC
                        ;			
                        ;			Send_Data(IAPC);
        MOVF  IAPC,W
        CALL  Send_Data
                        ;			Send_Data(NoteByte);
        BCF   0x03,RP0
        MOVF  NoteByte,W
        CALL  Send_Data
                        ;			Send_Data(IAPAH);
        BSF   0x03,RP0
        MOVF  IAPAH,W
        CALL  Send_Data
                        ;			Send_Data(IAPAL);
        BSF   0x03,RP0
        MOVF  IAPAL,W
        CALL  Send_Data
                        ;			Send_Data(NoteByte);
        BCF   0x03,RP0
        MOVF  NoteByte,W
        CALL  Send_Data
                        ;			Send_Data(IAPDH);
        BSF   0x03,RP0
        MOVF  IAPDH,W
        CALL  Send_Data
                        ;			Send_Data(IAPDL);
        BSF   0x03,RP0
        MOVF  IAPDL,W
        CALL  Send_Data
                        ;			Send_Data(NoteByte);	
        BCF   0x03,RP0
        MOVF  NoteByte,W
        CALL  Send_Data
                        ;			
                        ;			tmpData=Data[i*2];
        BCF   0x03,Carry
        BCF   0x03,RP0
        RLF   i,W
        CALL  _const1
        BCF   0x03,RP0
        MOVWF tmpData
                        ;			
                        ;			if(IAPDH!=tmpData)
        BSF   0x03,RP0
        MOVF  IAPDH,W
        BCF   0x03,RP0
        XORWF tmpData,W
        BTFSC 0x03,Zero_
        GOTO  m013
                        ;			{
                        ;				tmpData=Data[i*2+1];
        BCF   0x03,Carry
        RLF   i,W
        ADDLW 1
        CALL  _const1
        BCF   0x03,RP0
        MOVWF tmpData
                        ;				
                        ;				if(IAPDL!=tmpData)
        BSF   0x03,RP0
        MOVF  IAPDL,W
        BCF   0x03,RP0
        XORWF tmpData,W
        BTFSC 0x03,Zero_
        GOTO  m013
                        ;				{
                        ;					while(1)
                        ;						PB_0=!PB_0;												
m012    MOVLW 1
        BCF   0x03,RP0
        XORWF PORTB,1
        GOTO  m012
                        ;				}
                        ;			}
                        ;			
                        ;			IAPAL+=1;		
m013    BSF   0x03,RP0
        INCF  IAPAL,1
                        ;			
                        ;		}
        BCF   0x03,RP0
        INCF  i,1
        GOTO  m011
                        ;	}
m014    BCF   0x03,RP0
        INCF  j,1
        GOTO  m002
                        ;}
m015    RETURN
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Test_Option_Read_Write()
                        ;{
Test_Option_Read_Write
                        ;	uns8 i,j,tmpData;
                        ;	uns16 static const Data[4]={0x12,0x34,0x56,0x78};
                        ;	
                        ;	TAKEY=0x55;
        MOVLW 85
        BCF   0x03,RP0
        MOVWF TAKEY
                        ;	TAKEY=0xAA;
        MOVLW 170
        MOVWF TAKEY
                        ;	TAKEY=0x5A;
        MOVLW 90
        MOVWF TAKEY
                        ;	
                        ;	IAPC=0x80;
        MOVLW 128
        BSF   0x03,RP0
        MOVWF IAPC
                        ;	
                        ;	TAKEY=0x00;
        BCF   0x03,RP0
        CLRF  TAKEY
                        ;	
                        ;	//--------------------------------------
                        ;	//Write option
                        ;	IAPAH=0x00;
        BSF   0x03,RP0
        CLRF  IAPAH
                        ;	IAPAL=0x0E;
        MOVLW 14
        MOVWF IAPAL
                        ;	
                        ;	for(i=0;i<2;i++)
        BCF   0x03,RP0
        CLRF  i_2
m016    MOVLW 2
        BCF   0x03,RP0
        SUBWF i_2,W
        BTFSC 0x03,Carry
        GOTO  m017
                        ;	{
                        ;		tmpData=i*2;
        BCF   0x03,Carry
        RLF   i_2,W
        MOVWF tmpData_2
                        ;		
                        ;		IAPDH= Data[tmpData+1];
        BCF   0x03,Carry
        RLF   tmpData_2,W
        ADDLW 10
        ADDLW 2
        CALL  _const1
        BSF   0x03,RP0
        MOVWF IAPDH
                        ;		IAPDL= Data[tmpData];
        BCF   0x03,Carry
        BCF   0x03,RP0
        RLF   tmpData_2,W
        ADDLW 10
        CALL  _const1
        BSF   0x03,RP0
        MOVWF IAPDL
                        ;		
                        ;		IAPC=0x85;	//Write option
        MOVLW 133
        MOVWF IAPC
                        ;		
                        ;		Send_Data(IAPC);
        MOVF  IAPC,W
        CALL  Send_Data
                        ;		Send_Data(0xFF);
        MOVLW 255
        CALL  Send_Data
                        ;		Send_Data(IAPAH);
        BSF   0x03,RP0
        MOVF  IAPAH,W
        CALL  Send_Data
                        ;		Send_Data(IAPAL);
        BSF   0x03,RP0
        MOVF  IAPAL,W
        CALL  Send_Data
                        ;		Send_Data(0xFF);
        MOVLW 255
        CALL  Send_Data
                        ;		Send_Data(IAPDH);
        BSF   0x03,RP0
        MOVF  IAPDH,W
        CALL  Send_Data
                        ;		Send_Data(IAPDL);
        BSF   0x03,RP0
        MOVF  IAPDL,W
        CALL  Send_Data
                        ;		Send_Data(0xFF);
        MOVLW 255
        CALL  Send_Data
                        ;		
                        ;		IAPAL+=1;
        BSF   0x03,RP0
        INCF  IAPAL,1
                        ;	}
        BCF   0x03,RP0
        INCF  i_2,1
        GOTO  m016
                        ;	
                        ;	//--------------------------------------
                        ;	//Read option
                        ;	 IAPAH=0x00;
m017    BSF   0x03,RP0
        CLRF  IAPAH
                        ;	 IAPAL=0x0E;
        MOVLW 14
        MOVWF IAPAL
                        ;
                        ;	for(i=0;i<2;i++)
        BCF   0x03,RP0
        CLRF  i_2
m018    MOVLW 2
        BCF   0x03,RP0
        SUBWF i_2,W
        BTFSC 0x03,Carry
        GOTO  m021
                        ;	{		
                        ;		IAPC=0x84;	//Read option
        MOVLW 132
        BSF   0x03,RP0
        MOVWF IAPC
                        ;		
                        ;		Send_Data(IAPC);
        MOVF  IAPC,W
        CALL  Send_Data
                        ;		Send_Data(0x55);
        MOVLW 85
        CALL  Send_Data
                        ;		Send_Data(IAPAH);
        BSF   0x03,RP0
        MOVF  IAPAH,W
        CALL  Send_Data
                        ;		Send_Data(IAPAL);
        BSF   0x03,RP0
        MOVF  IAPAL,W
        CALL  Send_Data
                        ;		Send_Data(0x55);
        MOVLW 85
        CALL  Send_Data
                        ;		Send_Data(IAPDH);
        BSF   0x03,RP0
        MOVF  IAPDH,W
        CALL  Send_Data
                        ;		Send_Data(IAPDL);
        BSF   0x03,RP0
        MOVF  IAPDL,W
        CALL  Send_Data
                        ;		Send_Data(0x55);		
        MOVLW 85
        CALL  Send_Data
                        ;
                        ;		j=i*2;
        BCF   0x03,Carry
        BCF   0x03,RP0
        RLF   i_2,W
        MOVWF j_2
                        ;		
                        ;		tmpData=Data[j+1];
        BCF   0x03,Carry
        RLF   j_2,W
        ADDLW 10
        ADDLW 2
        CALL  _const1
        BCF   0x03,RP0
        MOVWF tmpData_2
                        ;		
                        ;		if(IAPDH!=tmpData)
        BSF   0x03,RP0
        MOVF  IAPDH,W
        BCF   0x03,RP0
        XORWF tmpData_2,W
        BTFSC 0x03,Zero_
        GOTO  m020
                        ;		{
                        ;			tmpData=Data[j];
        BCF   0x03,Carry
        RLF   j_2,W
        ADDLW 10
        CALL  _const1
        BCF   0x03,RP0
        MOVWF tmpData_2
                        ;			
                        ;			if(IAPDL!=tmpData)
        BSF   0x03,RP0
        MOVF  IAPDL,W
        BCF   0x03,RP0
        XORWF tmpData_2,W
        BTFSC 0x03,Zero_
        GOTO  m020
                        ;			{
                        ;				while(1)
                        ;					PB_0=!PB_0;												
m019    MOVLW 1
        BCF   0x03,RP0
        XORWF PORTB,1
        GOTO  m019
                        ;			}
                        ;		}
                        ;		
                        ;		IAPAL+=1;		
m020    BSF   0x03,RP0
        INCF  IAPAL,1
                        ;		
                        ;	}
        BCF   0x03,RP0
        INCF  i_2,1
        GOTO  m018
                        ;}
m021    RETURN
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Test_EEPROM_Read_Write()
                        ;{
Test_EEPROM_Read_Write
                        ;	uns8 i,tmpData;
                        ;	uns8 static const Data[10]={0x01,0x02,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0xa};
                        ;	
                        ;	TAKEY=0x55;
        MOVLW 85
        BCF   0x03,RP0
        MOVWF TAKEY
                        ;	TAKEY=0xAA;
        MOVLW 170
        MOVWF TAKEY
                        ;	TAKEY=0x5A;
        MOVLW 90
        MOVWF TAKEY
                        ;	
                        ;	IAPC=0x80;
        MOVLW 128
        BSF   0x03,RP0
        MOVWF IAPC
                        ;	
                        ;	TAKEY=0x00;
        BCF   0x03,RP0
        CLRF  TAKEY
                        ;	
                        ;	//--------------------------------------
                        ;	//Write EEPROM
                        ;	IAPAH=0x00;
        BSF   0x03,RP0
        CLRF  IAPAH
                        ;	IAPAL=0x00;
        CLRF  IAPAL
                        ;	
                        ;	IAPDH=0x00;	
        CLRF  IAPDH
                        ;	
                        ;	
                        ;	for(i=0;i<10;i++)
        BCF   0x03,RP0
        CLRF  i_3
m022    MOVLW 10
        BCF   0x03,RP0
        SUBWF i_3,W
        BTFSC 0x03,Carry
        GOTO  m023
                        ;	{		
                        ;		IAPDL=Data[i];
        MOVLW 18
        ADDWF i_3,W
        CALL  _const1
        BSF   0x03,RP0
        MOVWF IAPDL
                        ;		
                        ;		IAPC=0x83;	//Write EEPROM
        MOVLW 131
        MOVWF IAPC
                        ;		
                        ;		Send_Data(IAPC);
        MOVF  IAPC,W
        CALL  Send_Data
                        ;		Send_Data(0xFF);
        MOVLW 255
        CALL  Send_Data
                        ;		Send_Data(IAPAH);
        BSF   0x03,RP0
        MOVF  IAPAH,W
        CALL  Send_Data
                        ;		Send_Data(IAPAL);
        BSF   0x03,RP0
        MOVF  IAPAL,W
        CALL  Send_Data
                        ;		Send_Data(0xFF);
        MOVLW 255
        CALL  Send_Data
                        ;		Send_Data(IAPDH);
        BSF   0x03,RP0
        MOVF  IAPDH,W
        CALL  Send_Data
                        ;		Send_Data(IAPDL);
        BSF   0x03,RP0
        MOVF  IAPDL,W
        CALL  Send_Data
                        ;		Send_Data(0xFF);		
        MOVLW 255
        CALL  Send_Data
                        ;								
                        ;		IAPAL+=1;
        BSF   0x03,RP0
        INCF  IAPAL,1
                        ;	}
        BCF   0x03,RP0
        INCF  i_3,1
        GOTO  m022
                        ;	
                        ;	//--------------------------------------
                        ;	//Read EEPROM
                        ;	 IAPAH=0x00;
m023    BSF   0x03,RP0
        CLRF  IAPAH
                        ;	 IAPAL=0x00;
        CLRF  IAPAL
                        ;	 IAPDH=0x00;
        CLRF  IAPDH
                        ;
                        ;	for(i=0;i<10;i++)
        BCF   0x03,RP0
        CLRF  i_3
m024    MOVLW 10
        BCF   0x03,RP0
        SUBWF i_3,W
        BTFSC 0x03,Carry
        GOTO  m027
                        ;	{		
                        ;		IAPC=0x82;	//Read EEPROM
        MOVLW 130
        BSF   0x03,RP0
        MOVWF IAPC
                        ;
                        ;		Send_Data(IAPC);
        MOVF  IAPC,W
        CALL  Send_Data
                        ;		Send_Data(0x55);
        MOVLW 85
        CALL  Send_Data
                        ;		Send_Data(IAPAH);
        BSF   0x03,RP0
        MOVF  IAPAH,W
        CALL  Send_Data
                        ;		Send_Data(IAPAL);
        BSF   0x03,RP0
        MOVF  IAPAL,W
        CALL  Send_Data
                        ;		Send_Data(0x55);
        MOVLW 85
        CALL  Send_Data
                        ;		Send_Data(IAPDH);
        BSF   0x03,RP0
        MOVF  IAPDH,W
        CALL  Send_Data
                        ;		Send_Data(IAPDL);
        BSF   0x03,RP0
        MOVF  IAPDL,W
        CALL  Send_Data
                        ;		Send_Data(0x55);		
        MOVLW 85
        CALL  Send_Data
                        ;			
                        ;		tmpData=Data[i];
        MOVLW 18
        BCF   0x03,RP0
        ADDWF i_3,W
        CALL  _const1
        BCF   0x03,RP0
        MOVWF tmpData_3
                        ;			
                        ;		if(IAPDL!=tmpData)
        BSF   0x03,RP0
        MOVF  IAPDL,W
        BCF   0x03,RP0
        XORWF tmpData_3,W
        BTFSC 0x03,Zero_
        GOTO  m026
                        ;		{
                        ;			while(1)
                        ;				PB_0=!PB_0;												
m025    MOVLW 1
        BCF   0x03,RP0
        XORWF PORTB,1
        GOTO  m025
                        ;		}
                        ;		
                        ;		IAPAL+=1;		
m026    BSF   0x03,RP0
        INCF  IAPAL,1
                        ;		
                        ;	}
        BCF   0x03,RP0
        INCF  i_3,1
        GOTO  m024
                        ;}
m027    RETURN
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Test_Undefined_Selection()
                        ;{
Test_Undefined_Selection
                        ;	uns8 i;
                        ;	
                        ;	TAKEY=0x55;
        MOVLW 85
        BCF   0x03,RP0
        MOVWF TAKEY
                        ;	TAKEY=0xAA;
        MOVLW 170
        MOVWF TAKEY
                        ;	TAKEY=0x5A;
        MOVLW 90
        MOVWF TAKEY
                        ;	
                        ;	IAPC=0x80;
        MOVLW 128
        BSF   0x03,RP0
        MOVWF IAPC
                        ;	
                        ;	TAKEY=0x00;
        BCF   0x03,RP0
        CLRF  TAKEY
                        ;	
                        ;	IAPAH= 0x00;
        BSF   0x03,RP0
        CLRF  IAPAH
                        ;	IAPAL= 0x00;	
        CLRF  IAPAL
                        ;
                        ;	
                        ;	for(i=0;i<10;i++)
        BCF   0x03,RP0
        CLRF  i_4
m028    MOVLW 10
        BCF   0x03,RP0
        SUBWF i_4,W
        BTFSC 0x03,Carry
        GOTO  m029
                        ;	{		
                        ;		IAPC=0x8F;	//Defaut: Read Code?
        MOVLW 143
        BSF   0x03,RP0
        MOVWF IAPC
                        ;		
                        ;		Send_Data(IAPC);
        MOVF  IAPC,W
        CALL  Send_Data
                        ;		Send_Data(0x55);
        MOVLW 85
        CALL  Send_Data
                        ;		Send_Data(IAPAH);
        BSF   0x03,RP0
        MOVF  IAPAH,W
        CALL  Send_Data
                        ;		Send_Data(IAPAL);
        BSF   0x03,RP0
        MOVF  IAPAL,W
        CALL  Send_Data
                        ;		Send_Data(0x55);
        MOVLW 85
        CALL  Send_Data
                        ;		Send_Data(IAPDH);
        BSF   0x03,RP0
        MOVF  IAPDH,W
        CALL  Send_Data
                        ;		Send_Data(IAPDL);
        BSF   0x03,RP0
        MOVF  IAPDL,W
        CALL  Send_Data
                        ;		Send_Data(0x55);	
        MOVLW 85
        CALL  Send_Data
                        ;		
                        ;		IAPAL+=1;		
        BSF   0x03,RP0
        INCF  IAPAL,1
                        ;	}				
        BCF   0x03,RP0
        INCF  i_4,1
        GOTO  m028
                        ;
                        ;}
m029    RETURN
                        ;
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Get_IAP_Address_OP09()
                        ;{
Get_IAP_Address_OP09
                        ;	TAKEY=0x55;
        MOVLW 85
        BCF   0x03,RP0
        MOVWF TAKEY
                        ;	TAKEY=0xAA;
        MOVLW 170
        MOVWF TAKEY
                        ;	TAKEY=0x5A;
        MOVLW 90
        MOVWF TAKEY
                        ;	
                        ;	IAPC=0x80;
        MOVLW 128
        BSF   0x03,RP0
        MOVWF IAPC
                        ;	
                        ;	TAKEY=0x00;
        BCF   0x03,RP0
        CLRF  TAKEY
                        ;	
                        ;	//information block - OP09H (IAP start address)
                        ;	IAPAH=0x00;
        BSF   0x03,RP0
        CLRF  IAPAH
                        ;	IAPAL=0x09;
        MOVLW 9
        MOVWF IAPAL
                        ;
                        ;	IAPC=0x84;	//Read option
        MOVLW 132
        MOVWF IAPC
                        ;	
                        ;	g_Data=IAPDH&0x08;
        BCF   0x03,RP0
        CLRF  g_Data+1
        MOVLW 8
        BSF   0x03,RP0
        ANDWF IAPDH,W
        BCF   0x03,RP0
        MOVWF g_Data
                        ;	
                        ;	if(g_Data==0)
        MOVF  g_Data,W
        IORWF g_Data+1,W
        BTFSC 0x03,Zero_
                        ;		PA_0=0;
        BCF   0x05,PA_0
                        ;	
                        ;	Send_Data(IAPDH);
        BSF   0x03,RP0
        MOVF  IAPDH,W
        CALL  Send_Data
                        ;	Send_Data(IAPDL);
        BSF   0x03,RP0
        MOVF  IAPDL,W
        CALL  Send_Data
                        ;	
                        ;	g_StartAddr=IAPDH&0x03;
        BCF   0x03,RP0
        CLRF  g_StartAddr+1
        MOVLW 3
        BSF   0x03,RP0
        ANDWF IAPDH,W
        BCF   0x03,RP0
        MOVWF g_StartAddr
                        ;	
                        ;	//Send_Data(g_StartAddr);
                        ;	
                        ;	g_StartAddr <<= 8;
        MOVF  g_StartAddr,W
        MOVWF g_StartAddr+1
        CLRF  g_StartAddr
                        ;
                        ;	g_StartAddr |=IAPDL;
        BSF   0x03,RP0
        MOVF  IAPDL,W
        BCF   0x03,RP0
        IORWF g_StartAddr,1
                        ;	
                        ;	Send_Data(0x00);
        MOVLW 0
        CALL  Send_Data
                        ;	
                        ;	//-------------------------------
                        ;	//get protection bit - OP05
                        ;	IAPAH=0x00;
        BSF   0x03,RP0
        CLRF  IAPAH
                        ;	IAPAL=0x06;
        MOVLW 6
        MOVWF IAPAL
                        ;
                        ;	IAPC=0x84;	//Read option
        MOVLW 132
        MOVWF IAPC
                        ;
                        ;	Send_Data(IAPDH);
        MOVF  IAPDH,W
        CALL  Send_Data
                        ;	Send_Data(IAPDL);
        BSF   0x03,RP0
        MOVF  IAPDL,W
        CALL  Send_Data
                        ;
                        ;	Send_Data(0x00);
        MOVLW 0
        GOTO  Send_Data
                        ;}
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Check_SFR()
                        ;{
Check_SFR
                        ;	uns8 Temp,i;
                        ;	
                        ;	PORTA=0xFF;
        MOVLW 255
        BCF   0x03,RP0
        MOVWF PORTA
                        ;	
                        ;	for(i=0;i<2;i++)
        CLRF  i_5
m030    MOVLW 2
        BCF   0x03,RP0
        SUBWF i_5,W
        BTFSC 0x03,Carry
        GOTO  m035
                        ;	{
                        ;		if(i==0)
        MOVF  i_5,W
        BTFSS 0x03,Zero_
        GOTO  m031
                        ;			IAPC=0x05;
        MOVLW 5
        BSF   0x03,RP0
        MOVWF IAPC
                        ;		else
        GOTO  m032
                        ;			IAPC=0x02;
m031    MOVLW 2
        BSF   0x03,RP0
        MOVWF IAPC
                        ;		
                        ;		Send_Data(IAPC);
m032    BSF   0x03,RP0
        MOVF  IAPC,W
        CALL  Send_Data
                        ;		
                        ;		Temp=IAPC;
        BSF   0x03,RP0
        MOVF  IAPC,W
        BCF   0x03,RP0
        MOVWF Temp
                        ;		
                        ;		if(Temp!=IAPC)
        MOVF  Temp,W
        BSF   0x03,RP0
        XORWF IAPC,W
        BTFSC 0x03,Zero_
        GOTO  m034
                        ;		{
                        ;			if(i==0)
        BCF   0x03,RP0
        MOVF  i_5,W
        BTFSS 0x03,Zero_
        GOTO  m033
                        ;				PORTA=1;
        MOVLW 1
        MOVWF PORTA
                        ;			else
        GOTO  m060
                        ;				PORTA=2;
m033    MOVLW 2
        BCF   0x03,RP0
        MOVWF PORTA
                        ;			
                        ;			goto ERROR;
        GOTO  m060
                        ;		}
                        ;	}
m034    BCF   0x03,RP0
        INCF  i_5,1
        GOTO  m030
                        ;
                        ;	TAKEY=0x55;
m035    MOVLW 85
        BCF   0x03,RP0
        MOVWF TAKEY
                        ;	TAKEY=0xAA;
        MOVLW 170
        MOVWF TAKEY
                        ;	TAKEY=0x5A;
        MOVLW 90
        MOVWF TAKEY
                        ;	
                        ;	IAPC=0x80;
        MOVLW 128
        BSF   0x03,RP0
        MOVWF IAPC
                        ;	
                        ;	TAKEY=0x00;
        BCF   0x03,RP0
        CLRF  TAKEY
                        ;	
                        ;	//-------------------------------
                        ;	for(i=0;i<2;i++)
        CLRF  i_5
m036    MOVLW 2
        BCF   0x03,RP0
        SUBWF i_5,W
        BTFSC 0x03,Carry
        GOTO  m041
                        ;	{
                        ;		if(i==0)
        MOVF  i_5,W
        BTFSS 0x03,Zero_
        GOTO  m037
                        ;			IAPAL=0x55;
        MOVLW 85
        BSF   0x03,RP0
        MOVWF IAPAL
                        ;		else
        GOTO  m038
                        ;			IAPAL=0xAA;
m037    MOVLW 170
        BSF   0x03,RP0
        MOVWF IAPAL
                        ;		
                        ;		Send_Data(IAPAL);
m038    BSF   0x03,RP0
        MOVF  IAPAL,W
        CALL  Send_Data
                        ;		
                        ;		Temp=IAPAL;
        BSF   0x03,RP0
        MOVF  IAPAL,W
        BCF   0x03,RP0
        MOVWF Temp
                        ;		
                        ;		if(Temp!=IAPAL)
        MOVF  Temp,W
        BSF   0x03,RP0
        XORWF IAPAL,W
        BTFSC 0x03,Zero_
        GOTO  m040
                        ;		{
                        ;			if(i==0)
        BCF   0x03,RP0
        MOVF  i_5,W
        BTFSS 0x03,Zero_
        GOTO  m039
                        ;				PORTA=3;
        MOVLW 3
        MOVWF PORTA
                        ;			else
        GOTO  m060
                        ;				PORTA=4;
m039    MOVLW 4
        BCF   0x03,RP0
        MOVWF PORTA
                        ;			
                        ;			goto ERROR;
        GOTO  m060
                        ;		}
                        ;	}		
m040    BCF   0x03,RP0
        INCF  i_5,1
        GOTO  m036
                        ;	
                        ;	//-------------------------------
                        ;	for(i=0;i<2;i++)
m041    BCF   0x03,RP0
        CLRF  i_5
m042    MOVLW 2
        BCF   0x03,RP0
        SUBWF i_5,W
        BTFSC 0x03,Carry
        GOTO  m047
                        ;	{
                        ;		if(i==0)
        MOVF  i_5,W
        BTFSS 0x03,Zero_
        GOTO  m043
                        ;			IAPAH=0x55;
        MOVLW 85
        BSF   0x03,RP0
        MOVWF IAPAH
                        ;		else
        GOTO  m044
                        ;			IAPAH=0xAA;
m043    MOVLW 170
        BSF   0x03,RP0
        MOVWF IAPAH
                        ;		
                        ;		Send_Data(IAPAH);
m044    BSF   0x03,RP0
        MOVF  IAPAH,W
        CALL  Send_Data
                        ;		
                        ;		Temp=IAPAH;
        BSF   0x03,RP0
        MOVF  IAPAH,W
        BCF   0x03,RP0
        MOVWF Temp
                        ;		
                        ;		if(Temp!=IAPAH)
        MOVF  Temp,W
        BSF   0x03,RP0
        XORWF IAPAH,W
        BTFSC 0x03,Zero_
        GOTO  m046
                        ;		{
                        ;			if(i==0)
        BCF   0x03,RP0
        MOVF  i_5,W
        BTFSS 0x03,Zero_
        GOTO  m045
                        ;				PORTA=5;
        MOVLW 5
        MOVWF PORTA
                        ;			else
        GOTO  m060
                        ;				PORTA=6;
m045    MOVLW 6
        BCF   0x03,RP0
        MOVWF PORTA
                        ;			
                        ;			goto ERROR;
        GOTO  m060
                        ;		}
                        ;	}			
m046    BCF   0x03,RP0
        INCF  i_5,1
        GOTO  m042
                        ;	
                        ;	//-------------------------------
                        ;	for(i=0;i<2;i++)
m047    BCF   0x03,RP0
        CLRF  i_5
m048    MOVLW 2
        BCF   0x03,RP0
        SUBWF i_5,W
        BTFSC 0x03,Carry
        GOTO  m053
                        ;	{
                        ;		if(i==0)
        MOVF  i_5,W
        BTFSS 0x03,Zero_
        GOTO  m049
                        ;			IAPDL=0x55;
        MOVLW 85
        BSF   0x03,RP0
        MOVWF IAPDL
                        ;		else
        GOTO  m050
                        ;			IAPDL=0xAA;
m049    MOVLW 170
        BSF   0x03,RP0
        MOVWF IAPDL
                        ;		
                        ;		Send_Data(IAPDL);
m050    BSF   0x03,RP0
        MOVF  IAPDL,W
        CALL  Send_Data
                        ;		
                        ;		Temp=IAPDL;
        BSF   0x03,RP0
        MOVF  IAPDL,W
        BCF   0x03,RP0
        MOVWF Temp
                        ;		
                        ;		if(Temp!=IAPDL)
        MOVF  Temp,W
        BSF   0x03,RP0
        XORWF IAPDL,W
        BTFSC 0x03,Zero_
        GOTO  m052
                        ;		{
                        ;			if(i==0)
        BCF   0x03,RP0
        MOVF  i_5,W
        BTFSS 0x03,Zero_
        GOTO  m051
                        ;				PORTA=7;
        MOVLW 7
        MOVWF PORTA
                        ;			else
        GOTO  m060
                        ;				PORTA=8;
m051    MOVLW 8
        BCF   0x03,RP0
        MOVWF PORTA
                        ;			
                        ;			goto ERROR;
        GOTO  m060
                        ;		}
                        ;	}			
m052    BCF   0x03,RP0
        INCF  i_5,1
        GOTO  m048
                        ;
                        ;	//-------------------------------
                        ;	for(i=0;i<2;i++)
m053    BCF   0x03,RP0
        CLRF  i_5
m054    MOVLW 2
        BCF   0x03,RP0
        SUBWF i_5,W
        BTFSC 0x03,Carry
        GOTO  m059
                        ;	{
                        ;		if(i==0)
        MOVF  i_5,W
        BTFSS 0x03,Zero_
        GOTO  m055
                        ;			IAPDH=0x55;
        MOVLW 85
        BSF   0x03,RP0
        MOVWF IAPDH
                        ;		else
        GOTO  m056
                        ;			IAPDH=0xAA;
m055    MOVLW 170
        BSF   0x03,RP0
        MOVWF IAPDH
                        ;		
                        ;		Send_Data(IAPDH);
m056    BSF   0x03,RP0
        MOVF  IAPDH,W
        CALL  Send_Data
                        ;		
                        ;		Temp=IAPDH;
        BSF   0x03,RP0
        MOVF  IAPDH,W
        BCF   0x03,RP0
        MOVWF Temp
                        ;		
                        ;		if(Temp!=IAPDH)
        MOVF  Temp,W
        BSF   0x03,RP0
        XORWF IAPDH,W
        BTFSC 0x03,Zero_
        GOTO  m058
                        ;		{
                        ;			if(i==0)
        BCF   0x03,RP0
        MOVF  i_5,W
        BTFSS 0x03,Zero_
        GOTO  m057
                        ;				PORTA=9;
        MOVLW 9
        MOVWF PORTA
                        ;			else
        GOTO  m060
                        ;				PORTA=10;
m057    MOVLW 10
        BCF   0x03,RP0
        MOVWF PORTA
                        ;			
                        ;			goto ERROR;
        GOTO  m060
                        ;		}
                        ;	}
m058    BCF   0x03,RP0
        INCF  i_5,1
        GOTO  m054
                        ;
                        ;	PB_0=0;
m059    BCF   0x03,RP0
        BCF   0x06,PB_0
                        ;	return;
        RETURN
                        ;	
                        ;ERROR:
                        ;	PB_0=1;		
m060    BCF   0x03,RP0
        BSF   0x06,PB_0
                        ;	
                        ;}
        RETURN
                        ;/*******************************************************************************/
                        ;// Main
                        ;/*******************************************************************************/
                        ;void main() 
                        ;{   
main
                        ; 
                        ;    //0: digital, 1:analog
                        ;	ANSELA=0x00 ;//& 0xf9;
        BCF   0x03,RP0
        CLRF  ANSELA
                        ;	ANSELB=0x0;	
        CLRF  ANSELB
                        ;
                        ;	PAM0=0xff;
        MOVLW 255
        MOVWF PAM0
                        ;	PAM1=0xff;
        MOVLW 255
        MOVWF PAM1
                        ;	PBIM=0x03;
        MOVLW 3
        MOVWF PBIM
                        ;	
                        ;	PORTA=0xff;
        MOVLW 255
        MOVWF PORTA
                        ;	PB_0=1;
        BSF   0x06,PB_0
                        ;	
                        ;	Initiate_UART();
        CALL  Initiate_UART
                        ;		
                        ;	//Check_SFR();
                        ;	
                        ;	//---------------------------------------------
                        ;	//Test_IAP_Function_Enable();
                        ;	
                        ;	Get_IAP_Address_OP09();		
        CALL  Get_IAP_Address_OP09
                        ;	
                        ;	Test_Code_Read_Write();
        CALL  Test_Code_Read_Write
                        ;	
                        ;	//Test_Option_Read_Write();
                        ;	
                        ;	//Test_EEPROM_Read_Write();
                        ;	
                        ;	//Test_Undefined_Selection();
                        ;	
                        ;		
                        ;	while(1)
                        ;	{
                        ;		PA_7=!PA_7;
m061    MOVLW 128
        BCF   0x03,RP0
        XORWF PORTA,1
                        ;	}
        GOTO  m061

        END


; *** KEY INFO ***

; 0x002C   10 word(s)  0 % : Sub_ALLINT
; 0x02BA  234 word(s) 22 % : Check_SFR
; 0x0004    2 word(s)  0 % : INTR_ISR
; 0x0036    9 word(s)  0 % : Initiate_UART
; 0x003F   11 word(s)  1 % : Send_Data
; 0x004A   32 word(s)  3 % : Test_IAP_Function_Enable
; 0x006A  226 word(s) 22 % : Test_Code_Read_Write
; 0x0006   38 word(s)  3 % : _const1
; 0x014C  140 word(s) 13 % : Test_Option_Read_Write
; 0x01D8  111 word(s) 10 % : Test_EEPROM_Read_Write
; 0x0247   51 word(s)  4 % : Test_Undefined_Selection
; 0x027A   64 word(s)  6 % : Get_IAP_Address_OP09
; 0x03A4   19 word(s)  1 % : main

; RAM usage: 11 bytes (7 local), 53 bytes free
; Maximum call level: 2 (+2 for interrupt)
; Total of 948 code words (92 %)
