
; CC5X Version 3.8, Copyright (c) B Knudsen Data
; C compiler for the PICmicro family
; ************   8. Dec 2021  14:04  *************

        processor  OB36A01A1
        radix  DEC

INDF        EQU   0x00
STATUS      EQU   0x03
FSR         EQU   0x04
PORTB       EQU   0x06
INTCON      EQU   0x0B
Carry       EQU   0
Zero_       EQU   2
RP0         EQU   5
RP1         EQU   6
T0IF        EQU   2
ANSELA      EQU   0x07
ANSELB      EQU   0x08
INTFS       EQU   0x0C
LVC         EQU   0x0D
WDTC        EQU   0x0E
TAKEY       EQU   0x1F
SCON0       EQU   0x8E
SCON1       EQU   0x8F
SRELL       EQU   0x90
SRELH       EQU   0x91
SBUF        EQU   0x92
T1IF        EQU   4
WDTIF       EQU   5
ADCIF       EQU   6
LVIF        EQU   7
RXIF        EQU   0
TXIF        EQU   1
PriorityNum EQU   0x27
PriorityIndex EQU   0x3B
svrWREG     EQU   0x20
svrSTATUS   EQU   0x21
svrWREG_2   EQU   0x22
svrSTATUS_2 EQU   0x23
svrWREG_3   EQU   0x22
svrSTATUS_3 EQU   0x23
svrWREG_4   EQU   0x22
svrSTATUS_4 EQU   0x23
svrWREG_5   EQU   0x22
svrSTATUS_5 EQU   0x23
svrWREG_6   EQU   0x22
svrSTATUS_6 EQU   0x23
svrWREG_7   EQU   0x22
svrSTATUS_7 EQU   0x23
svrWREG_8   EQU   0x22
svrSTATUS_8 EQU   0x23
Data        EQU   0x26
tmp         EQU   0x24

        GOTO main

  ; FILE .\Interrupt.c
                        ;#include "int16CXX.h"
                        ;
                        ;#pragma interruptSaveCheck  n
                        ;
                        ;#define WATCHDOG_INDEX 0
                        ;#define TIMER0_INDEX 1
                        ;#define TIMER1_INDEX 2
                        ;#define IOC_INDEX 3
                        ;#define LVI_INDEX 4
                        ;#define ADC_INDEX 5
                        ;#define TI_INDEX 6
                        ;#define RI_INDEX 7
                        ;
                        ;
                        ;////////////////////////////////////////////////////////////////////////////////
                        ;// Interrupt ISR
                        ;////////////////////////////////////////////////////////////////////////////////
                        ;uns16 PriorityNum[10];
                        ;uns8 PriorityIndex;
                        ;
                        ;void Sub_ALLINT(void);
                        ;void Sub_WATCHDOG();
                        ;void Sub_IOC();
                        ;void Sub_TMR0();
                        ;void Sub_TMR1();
                        ;void Sub_LVI();
                        ;void Sub_UART();
                        ;void Sub_ADC();
                        ;
                        ;#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()
                        ;{
Sub_ALLINT
                        ;    int_save_registers    // W, STATUS (and PCLATH)
        MOVWF svrWREG
        SWAPF STATUS,W
        BCF   0x03,RP0
        BCF   0x03,RP1
        MOVWF svrSTATUS
                        ;
                        ;	if(WDTIF==1)
        BTFSC 0x0C,WDTIF
                        ;		Sub_WATCHDOG();
        CALL  Sub_WATCHDOG
                        ;	
                        ;    if((INTFS&0x0F)!=0)
        MOVLW 15
        BCF   0x03,RP0
        ANDWF INTFS,W
        BTFSS 0x03,Zero_
                        ;		Sub_IOC();
        CALL  Sub_IOC
                        ;	
                        ;	if(T0IF==1)
        BTFSC 0x0B,T0IF
                        ;		Sub_TMR0();
        CALL  Sub_TMR0
                        ;	
                        ;	if(T1IF==1)
        BCF   0x03,RP0
        BTFSC 0x0C,T1IF
                        ;		Sub_TMR1();
        CALL  Sub_TMR1
                        ;
                        ;	if(LVIF==1)
        BCF   0x03,RP0
        BTFSC 0x0C,LVIF
                        ;		Sub_LVI();
        CALL  Sub_LVI
                        ;    	
                        ;	if((TXIF==1)||(RXIF==1))
        BSF   0x03,RP0
        BTFSC 0x8E,TXIF
        GOTO  m001
        BTFSC 0x8E,RXIF
                        ;		Sub_UART(); 
m001    CALL  Sub_UART
                        ;
                        ;	if(ADCIF==1)
        BCF   0x03,RP0
        BTFSC 0x0C,ADCIF
                        ;		Sub_ADC();
        CALL  Sub_ADC
                        ;		
                        ;    int_restore_registers // W, STATUS (and PCLATH)
        BCF   0x03,RP0
        SWAPF svrSTATUS,W
        MOVWF STATUS
        SWAPF svrWREG,1
        SWAPF svrWREG,W
                        ;}
        RETURN
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Sub_WATCHDOG()
                        ;{
Sub_WATCHDOG
                        ;    int_save_registers    // W, STATUS (and PCLATH)
        MOVWF svrWREG_2
        SWAPF STATUS,W
        BCF   0x03,RP0
        BCF   0x03,RP1
        MOVWF svrSTATUS_2
                        ;    		
                        ;	WDTIF=0;
        BCF   0x0C,WDTIF
                        ;
                        ;	PriorityNum[PriorityIndex]=WATCHDOG_INDEX;
        BCF   0x03,Carry
        RLF   PriorityIndex,W
        ADDLW 39
        MOVWF FSR
        CLRF  INDF
        INCF  FSR,1
        CLRF  INDF
                        ;	PriorityIndex++;
        INCF  PriorityIndex,1
                        ;	
                        ;    int_restore_registers // W, STATUS (and PCLATH)
        SWAPF svrSTATUS_2,W
        MOVWF STATUS
        SWAPF svrWREG_2,1
        SWAPF svrWREG_2,W
                        ;}
        RETURN
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Sub_IOC()
                        ;{
Sub_IOC
                        ;    int_save_registers    // W, STATUS (and PCLATH)
        MOVWF svrWREG_3
        SWAPF STATUS,W
        BCF   0x03,RP0
        BCF   0x03,RP1
        MOVWF svrSTATUS_3
                        ;    
                        ;	//Clear flag		
                        ;	INTFS = INTFS &0xF0;		
        MOVLW 240
        ANDWF INTFS,1
                        ;
                        ;	PriorityNum[PriorityIndex]=IOC_INDEX;
        BCF   0x03,Carry
        RLF   PriorityIndex,W
        ADDLW 39
        MOVWF FSR
        MOVLW 3
        MOVWF INDF
        INCF  FSR,1
        CLRF  INDF
                        ;	PriorityIndex++;
        INCF  PriorityIndex,1
                        ;
                        ;		
                        ;    int_restore_registers // W, STATUS (and PCLATH)
        SWAPF svrSTATUS_3,W
        MOVWF STATUS
        SWAPF svrWREG_3,1
        SWAPF svrWREG_3,W
                        ;}
        RETURN
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Sub_TMR0()
                        ;{
Sub_TMR0
                        ;    int_save_registers    // W, STATUS (and PCLATH)
        MOVWF svrWREG_4
        SWAPF STATUS,W
        BCF   0x03,RP0
        BCF   0x03,RP1
        MOVWF svrSTATUS_4
                        ;    
                        ;	PriorityNum[PriorityIndex]=TIMER0_INDEX;
        BCF   0x03,Carry
        RLF   PriorityIndex,W
        ADDLW 39
        MOVWF FSR
        MOVLW 1
        MOVWF INDF
        INCF  FSR,1
        CLRF  INDF
                        ;	PriorityIndex++;
        INCF  PriorityIndex,1
                        ;	
                        ;	
                        ;	T0IF=0;	
        BCF   0x0B,T0IF
                        ;			
                        ;    int_restore_registers // W, STATUS (and PCLATH)
        SWAPF svrSTATUS_4,W
        MOVWF STATUS
        SWAPF svrWREG_4,1
        SWAPF svrWREG_4,W
                        ;}
        RETURN
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Sub_TMR1()
                        ;{
Sub_TMR1
                        ;    int_save_registers    // W, STATUS (and PCLATH)
        MOVWF svrWREG_5
        SWAPF STATUS,W
        BCF   0x03,RP0
        BCF   0x03,RP1
        MOVWF svrSTATUS_5
                        ;   
                        ;	PriorityNum[PriorityIndex]=TIMER1_INDEX;
        BCF   0x03,Carry
        RLF   PriorityIndex,W
        ADDLW 39
        MOVWF FSR
        MOVLW 2
        MOVWF INDF
        INCF  FSR,1
        CLRF  INDF
                        ;	PriorityIndex++;
        INCF  PriorityIndex,1
                        ;	
                        ;
                        ;	T1IF=0;	
        BCF   0x0C,T1IF
                        ;   
                        ;    int_restore_registers // W, STATUS (and PCLATH)
        SWAPF svrSTATUS_5,W
        MOVWF STATUS
        SWAPF svrWREG_5,1
        SWAPF svrWREG_5,W
                        ;}
        RETURN
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Sub_LVI()
                        ;{
Sub_LVI
                        ;    int_save_registers    // W, STATUS (and PCLATH)
        MOVWF svrWREG_6
        SWAPF STATUS,W
        BCF   0x03,RP0
        BCF   0x03,RP1
        MOVWF svrSTATUS_6
                        ;    		
                        ;	LVIF=0;
        BCF   0x0C,LVIF
                        ;	
                        ;	PriorityNum[PriorityIndex]=LVI_INDEX;
        BCF   0x03,Carry
        RLF   PriorityIndex,W
        ADDLW 39
        MOVWF FSR
        MOVLW 4
        MOVWF INDF
        INCF  FSR,1
        CLRF  INDF
                        ;	PriorityIndex++;
        INCF  PriorityIndex,1
                        ;	
                        ;		
                        ;    int_restore_registers // W, STATUS (and PCLATH)
        SWAPF svrSTATUS_6,W
        MOVWF STATUS
        SWAPF svrWREG_6,1
        SWAPF svrWREG_6,W
                        ;}
        RETURN
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Sub_UART()
                        ;{
Sub_UART
                        ;    int_save_registers    // W, STATUS (and PCLATH)
        MOVWF svrWREG_7
        SWAPF STATUS,W
        BCF   0x03,RP0
        BCF   0x03,RP1
        MOVWF svrSTATUS_7
                        ;	
                        ;	if(RXIF)
        BSF   0x03,RP0
        BTFSS 0x8E,RXIF
        GOTO  m002
                        ;	{
                        ;		RXIF=0;
        BCF   0x8E,RXIF
                        ;
                        ;		PriorityNum[PriorityIndex]=RI_INDEX;
        BCF   0x03,Carry
        BCF   0x03,RP0
        RLF   PriorityIndex,W
        ADDLW 39
        MOVWF FSR
        MOVLW 7
        MOVWF INDF
        INCF  FSR,1
        CLRF  INDF
                        ;		PriorityIndex++;
        INCF  PriorityIndex,1
                        ;	}
                        ;	
                        ;	if(TXIF)
m002    BSF   0x03,RP0
        BTFSS 0x8E,TXIF
        GOTO  m003
                        ;	{
                        ;		TXIF=0;
        BCF   0x8E,TXIF
                        ;		PriorityNum[PriorityIndex]=TI_INDEX;
        BCF   0x03,Carry
        BCF   0x03,RP0
        RLF   PriorityIndex,W
        ADDLW 39
        MOVWF FSR
        MOVLW 6
        MOVWF INDF
        INCF  FSR,1
        CLRF  INDF
                        ;		PriorityIndex++;
        INCF  PriorityIndex,1
                        ;	} 
                        ;	
                        ;    int_restore_registers // W, STATUS (and PCLATH)
m003    BCF   0x03,RP0
        SWAPF svrSTATUS_7,W
        MOVWF STATUS
        SWAPF svrWREG_7,1
        SWAPF svrWREG_7,W
                        ;}
        RETURN
                        ;
                        ;/*******************************************************************************/
                        ;/*******************************************************************************/
                        ;void Sub_ADC()
                        ;{
Sub_ADC
                        ;    int_save_registers    // W, STATUS (and PCLATH)
        MOVWF svrWREG_8
        SWAPF STATUS,W
        BCF   0x03,RP0
        BCF   0x03,RP1
        MOVWF svrSTATUS_8
                        ;	
                        ;	ADCIF=0;
        BCF   0x0C,ADCIF
                        ;	
                        ;	PriorityNum[PriorityIndex]=ADC_INDEX;
        BCF   0x03,Carry
        RLF   PriorityIndex,W
        ADDLW 39
        MOVWF FSR
        MOVLW 5
        MOVWF INDF
        INCF  FSR,1
        CLRF  INDF
                        ;	PriorityIndex++;
        INCF  PriorityIndex,1
                        ;	
                        ;    int_restore_registers // W, STATUS (and PCLATH)
        SWAPF svrSTATUS_8,W
        MOVWF STATUS
        SWAPF svrWREG_8,1
        SWAPF svrWREG_8,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);		
m004    BSF   0x03,RP0
        BTFSS 0x8E,TXIF
        GOTO  m004
                        ;			
                        ;	TXIF=0;		
        BSF   0x03,RP0
        BCF   0x8E,TXIF
                        ;}
        RETURN
                        ;
                        ;/*******************************************************************************/
                        ;// Main
                        ;/*******************************************************************************/
                        ;void main() 
                        ;{  
main
                        ;	uns16 tmp;
                        ;	
                        ;	
                        ;	PriorityIndex=0;
        BCF   0x03,RP0
        CLRF  PriorityIndex
                        ;
                        ;    //0: digital, 1:analog
                        ;	ANSELA=0x00 ;
        CLRF  ANSELA
                        ;	ANSELB=0x0;
        CLRF  ANSELB
                        ;	
                        ;	//-------------------------------------
                        ;	//enable interrupt
                        ;	INTCON=0x7F;
        MOVLW 127
        MOVWF INTCON
                        ;	LVC |=0x80;
        BSF   LVC,7
                        ;	WDTC |= 0x10;
        BSF   WDTC,4
                        ;	
                        ;	//-------------------------------------
                        ;	//enable special interrupt mode
                        ;	TAKEY=0x55;
        MOVLW 85
        MOVWF TAKEY
                        ;	TAKEY=0xAA;
        MOVLW 170
        MOVWF TAKEY
                        ;	TAKEY=0x5A;
        MOVLW 90
        MOVWF TAKEY
                        ;
                        ;	INTFS=0xFF;
        MOVLW 255
        MOVWF INTFS
                        ;	
                        ;	//SCON0=0x03;
                        ;
                        ;	TAKEY=0x00;
        CLRF  TAKEY
                        ;	
                        ;	//-------------------------------------
                        ;	//delay
                        ;	for(tmp=0;tmp<0xf0;tmp++);
        CLRF  tmp
        CLRF  tmp+1
m005    BCF   0x03,RP0
        MOVF  tmp+1,W
        BTFSS 0x03,Zero_
        GOTO  m006
        MOVLW 240
        SUBWF tmp,W
        BTFSC 0x03,Carry
        GOTO  m006
        INCF  tmp,1
        BTFSC 0x03,Zero_
        INCF  tmp+1,1
        GOTO  m005
                        ;	
                        ;	//Set GIE
                        ;	INTCON |=0x80;
m006    BSF   INTCON,7
                        ;	
                        ;	//waiting  execution of all interrupt routine is complete
                        ;	for(tmp=0;tmp<0xf000;tmp++);	
        BCF   0x03,RP0
        CLRF  tmp
        CLRF  tmp+1
m007    MOVLW 240
        BCF   0x03,RP0
        SUBWF tmp+1,W
        BTFSC 0x03,Carry
        GOTO  m008
        INCF  tmp,1
        BTFSC 0x03,Zero_
        INCF  tmp+1,1
        GOTO  m007
                        ;	
                        ;	//-------------------------------------
                        ;	//disable interrupt
                        ;	INTCON=0x00;
m008    CLRF  INTCON
                        ;
                        ;	//-------------------------------------
                        ;	//send data for verification
                        ;	Initiate_UART();
        CALL  Initiate_UART
                        ;	
                        ;	Send_Data(PriorityIndex);
        BCF   0x03,RP0
        MOVF  PriorityIndex,W
        CALL  Send_Data
                        ;	Send_Data(0xFF);
        MOVLW 255
        CALL  Send_Data
                        ;	
                        ;	// for(tmp=0;tmp<8;tmp++)
                        ;	Send_Data(PriorityNum[0]);
        BCF   0x03,RP0
        MOVF  PriorityNum,W
        CALL  Send_Data
                        ;	Send_Data(PriorityNum[1]);
        BCF   0x03,RP0
        MOVF  PriorityNum+2,W
        CALL  Send_Data
                        ;	Send_Data(PriorityNum[2]);
        BCF   0x03,RP0
        MOVF  PriorityNum+4,W
        CALL  Send_Data
                        ;	Send_Data(PriorityNum[3]);
        BCF   0x03,RP0
        MOVF  PriorityNum+6,W
        CALL  Send_Data
                        ;	Send_Data(PriorityNum[4]);
        BCF   0x03,RP0
        MOVF  PriorityNum+8,W
        CALL  Send_Data
                        ;	Send_Data(PriorityNum[5]);
        BCF   0x03,RP0
        MOVF  PriorityNum+10,W
        CALL  Send_Data
                        ;	Send_Data(PriorityNum[6]);
        BCF   0x03,RP0
        MOVF  PriorityNum+12,W
        CALL  Send_Data
                        ;	Send_Data(PriorityNum[7]);
        BCF   0x03,RP0
        MOVF  PriorityNum+14,W
        CALL  Send_Data
                        ;	
                        ;		
                        ;	while(1)
                        ;	{
                        ;		PB_0=!PB_0;
m009    MOVLW 1
        BCF   0x03,RP0
        XORWF PORTB,1
                        ;	}
        GOTO  m009

        END


; *** KEY INFO ***

; 0x0006   34 word(s)  3 % : Sub_ALLINT
; 0x0028   19 word(s)  1 % : Sub_WATCHDOG
; 0x003B   21 word(s)  2 % : Sub_IOC
; 0x0050   20 word(s)  1 % : Sub_TMR0
; 0x0064   20 word(s)  1 % : Sub_TMR1
; 0x0078   20 word(s)  1 % : Sub_LVI
; 0x008C   39 word(s)  3 % : Sub_UART
; 0x00B3   20 word(s)  1 % : Sub_ADC
; 0x0004    2 word(s)  0 % : INTR_ISR
; 0x00C7    9 word(s)  0 % : Initiate_UART
; 0x00D0   11 word(s)  1 % : Send_Data
; 0x00DB   79 word(s)  7 % : main

; RAM usage: 28 bytes (7 local), 36 bytes free
; Maximum call level: 1 (+3 for interrupt)
; Total of 295 code words (28 %)
