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

        processor  OB36A01A1
        radix  DEC

STATUS      EQU   0x03
PORTA       EQU   0x05
PORTB       EQU   0x06
Zero_       EQU   2
RP0         EQU   5
RP1         EQU   6
ANSELA      EQU   0x07
ANSELB      EQU   0x08
PAM0        EQU   0x0F
PAM1        EQU   0x10
PBIM        EQU   0x11
RSTS        EQU   0x1D
TAKEY       EQU   0x1F
SWRES       EQU   0x98
PB_0        EQU   0
SWRF        EQU   3
svrWREG     EQU   0x20
svrSTATUS   EQU   0x21
TMP         EQU   0x7F
ErrorCode   EQU   0x7F

        GOTO main

  ; FILE .\SWReset.c
                        ;#include "int16CXX.h"
                        ;
                        ;#pragma interruptSaveCheck  n
                        ;
                        ;
                        ;////////////////////////////////////////////////////////////////////////////////
                        ;// Interrupt ISR
                        ;////////////////////////////////////////////////////////////////////////////////
                        ;
                        ;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()
                        ;{
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 Check_SFR()
                        ;{
Check_SFR
                        ;	uns8 TMP,ErrorCode;
                        ;	
                        ;	PB_0=1;		
        BCF   0x03,RP0
        BSF   0x06,PB_0
                        ;	
                        ;	RSTS=0x55;	
        MOVLW 85
        MOVWF RSTS
                        ;	TMP=RSTS;
        MOVF  RSTS,W
        MOVWF TMP
                        ;	
                        ;	if(TMP!=RSTS)
        MOVF  TMP,W
        XORWF RSTS,W
        BTFSC 0x03,Zero_
        GOTO  m001
                        ;	{
                        ;		ErrorCode=1;
        MOVLW 1
        MOVWF ErrorCode
                        ;		goto Error;
        GOTO  m007
                        ;	}
                        ;	
                        ;	RSTS=0xAA;	
m001    MOVLW 170
        BCF   0x03,RP0
        MOVWF RSTS
                        ;	TMP=RSTS;
        MOVF  RSTS,W
        MOVWF TMP
                        ;	
                        ;	if(TMP!=RSTS)
        MOVF  TMP,W
        XORWF RSTS,W
        BTFSC 0x03,Zero_
        GOTO  m002
                        ;	{		
                        ;		ErrorCode=2;
        MOVLW 2
        MOVWF ErrorCode
                        ;		goto Error;	
        GOTO  m007
                        ;	}
                        ;	
                        ;	//------------------------------------------
                        ;	TAKEY=0x55;	
m002    MOVLW 85
        BCF   0x03,RP0
        MOVWF TAKEY
                        ;	TMP=TAKEY;
        MOVF  TAKEY,W
        MOVWF TMP
                        ;	
                        ;	if(TMP!=TAKEY)
        MOVF  TMP,W
        XORWF TAKEY,W
        BTFSC 0x03,Zero_
        GOTO  m003
                        ;	{
                        ;		ErrorCode=3;
        MOVLW 3
        MOVWF ErrorCode
                        ;		goto Error;
        GOTO  m007
                        ;	}
                        ;	
                        ;	TAKEY=0xAA;	
m003    MOVLW 170
        BCF   0x03,RP0
        MOVWF TAKEY
                        ;	TMP=TAKEY;
        MOVF  TAKEY,W
        MOVWF TMP
                        ;	
                        ;	if(TMP!=TAKEY)
        MOVF  TMP,W
        XORWF TAKEY,W
        BTFSC 0x03,Zero_
        GOTO  m004
                        ;	{		
                        ;		ErrorCode=4;
        MOVLW 4
        MOVWF ErrorCode
                        ;		goto Error;	
        GOTO  m007
                        ;	}
                        ;
                        ;	//------------------------------------------
                        ;	SWRES=0x55;	
m004    MOVLW 85
        BSF   0x03,RP0
        MOVWF SWRES
                        ;	TMP=SWRES;
        MOVF  SWRES,W
        BCF   0x03,RP0
        MOVWF TMP
                        ;	
                        ;	if(TMP!=SWRES)
        MOVF  TMP,W
        BSF   0x03,RP0
        XORWF SWRES,W
        BTFSC 0x03,Zero_
        GOTO  m005
                        ;	{
                        ;		ErrorCode=5;
        MOVLW 5
        BCF   0x03,RP0
        MOVWF ErrorCode
                        ;		goto Error;
        GOTO  m007
                        ;	}
                        ;	
                        ;	SWRES=0xAA;	
m005    MOVLW 170
        BSF   0x03,RP0
        MOVWF SWRES
                        ;	TMP=SWRES;
        MOVF  SWRES,W
        BCF   0x03,RP0
        MOVWF TMP
                        ;	
                        ;	if(TMP!=SWRES)
        MOVF  TMP,W
        BSF   0x03,RP0
        XORWF SWRES,W
        BTFSC 0x03,Zero_
        GOTO  m006
                        ;	{		
                        ;		ErrorCode=6;
        MOVLW 6
        BCF   0x03,RP0
        MOVWF ErrorCode
                        ;		goto Error;	
        GOTO  m007
                        ;	}	
                        ;	
                        ;	//------------------------------------------
                        ;	PORTA=0x60;
m006    MOVLW 96
        BCF   0x03,RP0
        MOVWF PORTA
                        ;	return;
        RETURN
                        ;	
                        ;Error:
                        ;	PB_0=0;	
m007    BCF   0x03,RP0
        BCF   0x06,PB_0
                        ;	PORTA=ErrorCode;
        MOVF  ErrorCode,W
        MOVWF PORTA
                        ;	
                        ;}
        RETURN
                        ;
                        ;/*******************************************************************************/
                        ;// Main
                        ;/*******************************************************************************/
                        ;void main() 
                        ;{   
main
                        ;	uns8 tmp;
                        ;    
                        ;	ANSELA=0x00;
        BCF   0x03,RP0
        CLRF  ANSELA
                        ;	ANSELB=0x00;
        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
                        ;
                        ;	//check software reset flag
                        ;	if(SWRF)
        BTFSS 0x1D,SWRF
        GOTO  m008
                        ;	{
                        ;		SWRF=0;
        BCF   0x1D,SWRF
                        ;		
                        ;		if(SWRF==0)
        BTFSC 0x1D,SWRF
        GOTO  m008
                        ;			PB_0=!PB_0;
        MOVLW 1
        XORWF PORTB,1
                        ;	}
                        ;			
                        ;	
                        ;	//------------------------------------------
                        ;	//Check_SFR();
                        ;
                        ;	//------------------------------------------
                        ;	//enable software reset
                        ;	TAKEY=0x55;
m008    MOVLW 85
        BCF   0x03,RP0
        MOVWF TAKEY
                        ;	TAKEY=0xAA;
        MOVLW 170
        MOVWF TAKEY
                        ;	TAKEY=0X5A;
        MOVLW 90
        MOVWF TAKEY
                        ;	
                        ;	SWRES=0xFF;
        MOVLW 255
        BSF   0x03,RP0
        MOVWF SWRES
                        ;	
                        ;	while(1)
                        ;	{
                        ;		PA_7=PA_7^1;
m009    MOVLW 128
        BCF   0x03,RP0
        XORWF PORTA,1
                        ;	}
        GOTO  m009

        END


; *** KEY INFO ***

; 0x0006   10 word(s)  0 % : Sub_ALLINT
; 0x0010   88 word(s)  8 % : Check_SFR
; 0x0004    2 word(s)  0 % : INTR_ISR
; 0x0068   33 word(s)  3 % : main

; RAM usage: 3 bytes (3 local), 61 bytes free
; Maximum call level: 0 (+2 for interrupt)
; Total of 134 code words (13 %)
