;========================================================================================
;                 Assembler code for SNOOP_LOG.vi created with PICLab
;========================================================================================

        LIST    p=16F88

	#include "P16F88.INC" ; Include header file

 __CONFIG _CONFIG1, _BODEN_OFF&_CP_OFF&_PWRTE_ON&_WDT_OFF&_LVP_OFF&_MCLR_OFF&_INTRC_IO

;***************************************Variable definitions***************************************

TEMPPORT8 EQU 0X20
TEMPX8 EQU 0X21
TEMPY8 EQU 0X22
RESULT8 EQU 0X23
TEMPX16 EQU 0X24
TEMPX16_H EQU 0X25
TEMPY16 EQU 0X26
TEMPY16_H EQU 0X27
RESULT16 EQU 0X28
RESULT16_H EQU 0X29
IDX16 EQU 0X2A
IDX16_H EQU 0X2B
TEMPYY EQU 0X2C
OP_SIGN8 EQU 0X2D
ADHBYTE EQU 0X2E
ADLBYTE EQU 0X2F
AD_RESULT EQU 0X30
AD_RESULT_H EQU 0X31
ISR_TEMPPORT8 EQU 0X32
ISR_TEMPX8 EQU 0X33
ISR_TEMPY8 EQU 0X34
ISR_RESULT8 EQU 0X35
ISR_TEMPX16 EQU 0X36
ISR_TEMPX16_H EQU 0X37
ISR_TEMPY16 EQU 0X38
ISR_TEMPY16_H EQU 0X39
ISR_RESULT16 EQU 0X3A
ISR_RESULT16_H EQU 0X3B
ISR_IDX16 EQU 0X3C
ISR_IDX16_H EQU 0X3D
ISR_TEMPYY EQU 0X3E
ISR_OP_SIGN8 EQU 0X3F
ISR_STATUS EQU 0X40
ISR_W EQU 0X41
ISR_FSR EQU 0X42
I EQU 0X43
DEVICE_ERROR EQU 0X44
SD_WAIT_MS_COUNTER EQU 0X45
SD_WAIT_MS_COUNTER_H EQU 0X46
SD_WAIT_MS_TIME EQU 0X47
SD_WAIT_MS_TIME_H EQU 0X48
I2C_ERROR EQU 0X49
BUFFER EQU 0X4A
BITCOUNT EQU 0X4B
DATAO EQU 0X4C
DATAI EQU 0X4D
UART_RX_DATA_LAST_BYTE_ADDR EQU 0X4E
UART_RX_DATA_LAST_BYTE_ADDR_H EQU 0X4F
UART_RX_BUFFER_POINTER EQU 0X50
UART_RX_BUFFER_POINTER_H EQU 0X51
UART_STATE EQU 0X52
UART_CURRENT EQU 0X53
LEGO_HEADER_POINTER EQU 0X54
LEGO_HEADER_POINTER_H EQU 0X55
UART_ERROR EQU 0X56
COMPLEMENT EQU 0X57
PACKET_CHECKSUM EQU 0X58
TMP_OPCODE EQU 0X59
UART_TX_BUFFER_POINTER EQU 0X5A
UART_TX_BUFFER_POINTER_H EQU 0X5B
UART_TX_DATA_LAST_BYTE_ADDR EQU 0X5C
UART_TX_DATA_LAST_BYTE_ADDR_H EQU 0X5D
UART_TX_LENGTH EQU 0X5E
PARITY EQU 0X5F
PA_TEMP EQU 0X60
PA_INDEX EQU 0X61
FW_CHS_HI EQU 0X62
ADDRESS EQU 0X63
ADDRESS_H EQU 0X64
OPCODE EQU 0X65
FW_CHS_LO EQU 0X66
TOGGLE_BIT EQU 0X67
DATA_RAM_ADDRESS EQU 0X68
DATA_RAM_ADDRESS_H EQU 0X69
CHANNEL EQU 0X6A
LOGGER_DATA_BYTE EQU 0X6B
RETRIES EQU 0X6C
LOGGER_SIZE EQU 0X6D
LOGGER_SIZE_H EQU 0X6E
TMP_ADDR EQU 0X6F
I16_COUNT EQU 0X70
I16_COUNT_H EQU 0X71

;**************************Makro definitions and definitions of used operations**************************

BANK0    MACRO
         BCF  STATUS,RP0
         BCF  STATUS,RP1
         ENDM
BANK1    MACRO
         BSF  STATUS,RP0
         BCF  STATUS,RP1
         ENDM
BANK2    MACRO
         BCF  STATUS,RP0
         BSF  STATUS,RP1
         ENDM
BANK3    MACRO
         BSF  STATUS,RP0
         BSF  STATUS,RP1
         ENDM

                 GOTO  START
                 ORG 0X4                 ; select page 1                 
                 BSF PCLATH, 3
                 GOTO LABEL_ISR

SUMV16
  MOVF      TEMPY16,W
  ADDWF  TEMPX16
  BTFSC  STATUS,C
  INCF    TEMPX16_H
  MOVF     TEMPY16_H,W
  ADDWF  TEMPX16_H
  RETURN

ANDV8
  MOVF  TEMPY8,W
  ANDWF TEMPX8
  RETURN

MULV8
  CLRF RESULT8
MULU8LOOP
  MOVF TEMPX8,W
  BTFSC TEMPY8,0
  ADDWF RESULT8
  BCF STATUS,C
  RRF TEMPY8,F
  BCF STATUS,C
  RLF TEMPX8,F
  MOVF TEMPY8,F
  BTFSS STATUS,Z
  GOTO MULU8LOOP
  RETURN

ORV8
  MOVF  TEMPY8,W
  IORWF TEMPX8
  RETURN

SUMV8
  MOVF     TEMPY8,W
  ADDWF  TEMPX8
  RETURN

XOR_V8
  MOVF  TEMPY8,W
  XORWF TEMPX8
  RETURN

SUBV16
  MOVF   TEMPY16,W
  SUBWF  TEMPX16
  BTFSS  STATUS,C
  INCF   TEMPY16_H,F
  MOVF   TEMPY16_H,W
  SUBWF  TEMPX16_H
  RETURN

EQU8U8
  MOVF     TEMPX8,W
  SUBWF  TEMPY8
  BTFSS    STATUS,Z   ;SKIP IF ZERO ->IDENTICAL
  RETLW  0
  RETLW  1

GRU8U8
  MOVF     TEMPX8,W
  SUBWF  TEMPY8
  BTFSS    STATUS,C
  RETLW  0
  RETLW  1

GRU16U16
  MOVF   TEMPX16,W
  SUBWF TEMPY16
  MOVF  TEMPX16_H,W
  BTFSS  STATUS,C
  INCFSZ  TEMPX16_H,W
  SUBWF  TEMPY16_H
  BTFSS  STATUS,C
  RETLW 0
  RETLW 1

;***************************************BEGIN OF MAIN PROGRAM***************************************

START

  ;INITIALIZE PORT A
  BANK0
  CLRF   PORTA
  BANK1
  CLRF ANSEL
  MOVLW  0X07
  MOVWF  CMCON
  MOVLW  0X0
  MOVWF  TRISA

  ;INITIALIZE PORT B
  BANK0
  CLRF   PORTB
  BANK1
  MOVLW  0X0
  MOVWF  TRISB

  ;CONFIGURE INTERNAL OSCILLATOR
  MOVLW 0XFC
  MOVWF OSCCON

  ;CONFIGURE PORT ALL
  ;SET SFR WITH CONSTANT
  MOVLW   0XC0
  MOVWF TRISB

  ;CONFIGURE AD-CONVERTER
  ;CONFIGURE PORT INPUTS
  MOVF TRISA,W
  IORLW 0X1F
  MOVWF TRISA
  MOVLW 0X1F
  MOVWF ANSEL
  MOVLW 0XE0
  MOVWF ADCON1
  MOVLW 0X41
  BANK0
  MOVWF ADCON0

  ;SET SINGLE OUPUT PIN
  BCF PORTA,6

  ;SET SINGLE OUPUT PIN
  BSF PORTB,1

  ;SET VARIABLE U16 WITH CONSTANT
  MOVLW   0XF4
  MOVWF SD_WAIT_MS_TIME
  MOVLW 0X1
  MOVWF SD_WAIT_MS_TIME_H

  CALL LABEL_SD_WAIT_MS

  ;SET SINGLE OUPUT PIN
  BANK0
  BCF PORTB,1

  ;SET VARIABLE U16 WITH CONSTANT
  MOVLW   0XF4
  MOVWF SD_WAIT_MS_TIME
  MOVLW 0X1
  MOVWF SD_WAIT_MS_TIME_H

  CALL LABEL_SD_WAIT_MS

  BANK0
  CLRF BUFFER

  CLRF DATAI

  CLRF DATAO

  CLRF BITCOUNT

  CLRF I2C_ERROR

  ;*******************BIT DEFINITIONS*******************************
  SCL         EQU     4           ; I2C CLOCK PIN, PORTB PIN 4
  SDA         EQU     3           ; I2C DATA PIN, PORTB PIN 5
  DO          EQU     0           ; TX/RX BUFFER OUTPUT BIT
  DI          EQU     1           ; TX/RX BUFFER INPUT BIT
  ACKB        EQU     2           ; ACK/NO ACK SELECT BIT
  ;*******************MACRO DEFINITIONS*****************************
  WRITE_ADDR  EQU     B'10100000' ; CONTROL BYTE FOR WRITE OPERATIONS
  READ_ADDR   EQU     B'10100001' ; CONTROL BYTE FOR READ OPERATIONS
  ;*******************DELAY MACROS**********************************
  ;           EACH MACRO DELAY FOR 1 INST. CYCLE LESS THAN
  ;           REQUIRED, AS THE INSTRUCTION IMMEDIATELY
  ;           BEFORE THE MACRO CALL PROVIDES 1 INST. CYCLE.
  ;*****************************************************************
  ; CLOCK HIGH TIME DELAY (5 US)
  THIGH   MACRO
        NOP
        NOP
        NOP
        NOP
        ENDM

  ; START CONDITION HOLD TIME DELAY (5 US)
  THDSTA  MACRO
          NOP
          NOP
          NOP
          NOP
          ENDM

  ; START CONDITION SETUP TIME DELAY (5 US)
  TSUSTA  MACRO
          NOP
          NOP
          NOP
          NOP
          ENDM

  ; STOP CONDITION SETUP TIME DELAY (5 US)
  TSUSTO  MACRO
          NOP
          NOP
          NOP
          NOP
          ENDM

  ; OUTPUT VALID FROM CLOCK DELAY (4 US)
  TAA     MACRO
          NOP
          NOP
          NOP
          ENDM

  NOP                         ; CONFIGURE SDA TO BE AN INPUT
      BANK1
      BSF    TRISB,SDA               ; SET TRISB SDA BIT
      BANK0

  _RX_OPCODE EQU 0X110

  _RX_BL_COUNT_LO EQU 0X111

  _RX_BL_COUNT_HI EQU 0X112

  _RX_CHECKSUM EQU 0X16F

  _RX_FW_CHECKSUM_LO EQU 0X113

  _RX_FW_CHECKSUM_HI EQU 0X114

  _RX_MESSAGE EQU 0X111

  _RX_VARIABLE EQU 0X111

  _RX_SOURCE EQU 0X112

  _RX_VALUE_LO EQU 0X113

  _RX_VALUE_HI EQU 0X114

  ;CONFIGURE TMR0
  BANK1
  MOVLW B'11010000'
  ANDWF OPTION_REG
  MOVLW   B'111'
  IORWF   OPTION_REG

  MOVLW 0X55
  MOVWF 0XA0
  MOVLW 0XFF
  MOVWF 0XA1
  MOVLW 0X0
  MOVWF 0XA2
  BANK0

  ;CONFIGURE UART
  BANK1
  BSF TRISB,2
  BSF TRISB,5
  MOVLW   0X33
  MOVWF   SPBRG
  BCF    TXSTA,BRGH
  BCF     TXSTA,SYNC
  BANK0
  BSF     RCSTA,SPEN
  BCF     RCSTA,RX9
  BSF     RCSTA,CREN
  BANK1
  BCF     TXSTA,TX9
  BSF     TXSTA,TXEN

  BANK0
  BSF RCSTA,6

  CALL LABEL_RESET_UART_RX

  _TX_OPCODE EQU 0X190

  _TX_BL_COUNT_LO EQU 0X191

  _TX_BL_COUNT_HI EQU 0X192

  _TX_BYTE_COUNT_LO EQU 0X193

  _TX_BYTE_COUNT_HI EQU 0X194

  ;CONFIGURE PWM
  CLRF TMR2
  BANK1
  MOVLW 0X34
  MOVWF  PR2
  BANK0
  MOVLW 0X1A
  MOVWF  CCPR1L   ;SET 8MSB
  CLRF  CCP1CON
  MOVLW B'00001111'
  IORWF CCP1CON,F  ;SET PWM MODE
  MOVLW 0X20
  IORWF  CCP1CON,F  ;SET 2 LSB
  BANK1
  BCF  TRISB,0   ;CONFIGURE PIN TO OUTPUT
  BANK0
  BSF  T2CON,TMR2ON  ;TIMER2 ON
  MOVLW 0X0
  IORWF  T2CON,F  ;PRESCALE 0->1; 1->4; 2->16
  BANK1
  BCF  PIE1,TMR2IE ;ALLOW PR2 OVERFLOW

  BANK0
  BCF T2CON,2

  BANK1
  BSF TXSTA,6

  BANK0
  CLRF UART_TX_LENGTH

LABEL_0

  ;BEGIN OF WHILE-LOOP (POLLING BIT/PIN)
LABEL_1051
  BANK0
  BTFSC PORTB,6
  GOTO LABEL_1052

                ;SET SINGLE OUPUT PIN
                BANK0
                BSF PORTA,6

                ;SET VARIABLE U16 WITH CONSTANT
                MOVLW   0XF4
                MOVWF SD_WAIT_MS_TIME
                MOVLW 0X1
                MOVWF SD_WAIT_MS_TIME_H

                CALL LABEL_SD_WAIT_MS

                ;SET SINGLE OUPUT PIN
                BANK0
                BCF PORTA,6

                ;SET VARIABLE U16 WITH CONSTANT
                MOVLW   0X10
                MOVWF SD_WAIT_MS_TIME
                MOVLW 0X27
                MOVWF SD_WAIT_MS_TIME_H

                CALL LABEL_SD_WAIT_MS

  GOTO LABEL_1051
LABEL_1052
;END OF FOR/WHILE-LOOP

  ;SET VARIABLE U8 WITH CONSTANT
  MOVLW   0X0
  BANK0
  MOVWF DEVICE_ERROR

  ;BEGIN OF IF-STRUCTURE (DEPENDING ON BIT/PIN)
  BTFSS PORTB,7
  GOTO LABEL_1053

                ;BEGIN OF IF-STRUCTURE
                ;COMPARE-OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   UART_STATE,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X3
                MOVWF TEMPY8
                CALL EQU8U8
                BANK0
                MOVWF RESULT8
                BTFSC RESULT8,0
                GOTO LABEL_1054

                              ;BEGIN OF IF-STRUCTURE
                              ;COMPARE-OPERATION
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              BANK0
                              MOVF   UART_STATE,W
                              MOVWF TEMPX8
                              ;SET VARIABLE U8 WITH CONSTANT
                              MOVLW   0X4
                              MOVWF TEMPY8
                              CALL EQU8U8
                              BANK0
                              MOVWF RESULT8
                              BTFSC RESULT8,0
                              GOTO LABEL_1055

                              GOTO LABEL_1056
                            LABEL_1055

                                            ;SET VARIABLE U8 WITH CONSTANT
                                            MOVLW   0X2
                                            BANK0
                                            MOVWF DEVICE_ERROR

                            LABEL_1056
                            ;END OF IF-STRUCTURE

                GOTO LABEL_1099
              LABEL_1054

                              ;SET VARIABLE U8 WITH SFR
                              BANK2
                              MOVF   _RX_OPCODE,W
                              BANK0
                              MOVWF OPCODE

                              ;SET VARIABLE U8 WITH VARIABLE U8
                              MOVF   OPCODE,W
                              MOVWF TMP_OPCODE

                              ;OPERATION
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              MOVF   TMP_OPCODE,W
                              MOVWF TEMPX8
                              ;SET VARIABLE U8 WITH CONSTANT
                              MOVLW   0XF7
                              MOVWF TEMPY8
                              CALL ANDV8
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              BANK0
                              MOVF   TEMPX8,W
                              MOVWF TMP_OPCODE

                              ;BEGIN OF IF-STRUCTURE
                              ;COMPARE-OPERATION
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              MOVF   TMP_OPCODE,W
                              MOVWF TEMPX8
                              ;SET VARIABLE U8 WITH CONSTANT
                              MOVLW   0X14
                              MOVWF TEMPY8
                              CALL EQU8U8
                              BANK0
                              MOVWF RESULT8
                              BTFSC RESULT8,0
                              GOTO LABEL_1057

                              GOTO LABEL_1061
                            LABEL_1057

                                            ;SET VARIABLE U16 WITH SFR
                                            BANK2
                                            MOVF   _RX_VARIABLE,W
                                            BANK0
                                            MOVWF DATA_RAM_ADDRESS
                                            CLRF DATA_RAM_ADDRESS_H

                                            BCF STATUS,C
                                            RLF DATA_RAM_ADDRESS,F
                                            RLF DATA_RAM_ADDRESS_H,F

                                            ;OPERATION
                                            ;SET VARIABLE U16 WITH VARIABLE U16
                                            MOVF   DATA_RAM_ADDRESS,W
                                            MOVWF TEMPX16
                                            MOVF DATA_RAM_ADDRESS_H,W
                                            MOVWF TEMPX16_H
                                            ;SET VARIABLE U16 WITH CONSTANT
                                            MOVLW   0XA4
                                            MOVWF TEMPY16
                                            MOVLW 0X0
                                            MOVWF TEMPY16_H
                                            CALL SUMV16
                                            ;SET VARIABLE U16 WITH VARIABLE U16
                                            BANK0
                                            MOVF   TEMPX16,W
                                            MOVWF DATA_RAM_ADDRESS
                                            MOVF TEMPX16_H,W
                                            MOVWF DATA_RAM_ADDRESS_H

                                            ;BEGIN OF IF-STRUCTURE
                                            ;COMPARE-OPERATION
                                            ;SET VARIABLE U8 WITH SFR
                                            BANK2
                                            MOVF   _RX_VARIABLE,W
                                            BANK0
                                            MOVWF TEMPX8
                                            ;SET VARIABLE U8 WITH CONSTANT
                                            MOVLW   0X4
                                            MOVWF TEMPY8
                                            CALL GRU8U8
                                            BANK0
                                            MOVWF RESULT8
                                            BTFSC RESULT8,0
                                            GOTO LABEL_1058

                                                          ;SET INDIRECT VARIABLE WITH SFR
                                                          ;SET U16 POINTER
                                                          BCF STATUS,IRP
                                                          BANK0
                                                          BTFSC DATA_RAM_ADDRESS_H,0
                                                          BSF STATUS,IRP
                                                          BANK0
                                                          MOVF DATA_RAM_ADDRESS,W
                                                          MOVWF FSR
                                                          BANK2
                                                          MOVF   _RX_VALUE_LO,W
                                                          MOVWF INDF

                                                          BANK0
                                                          INCF DATA_RAM_ADDRESS,F
                                                          BTFSC STATUS,Z
                                                          INCF DATA_RAM_ADDRESS_H,F

                                                          ;SET INDIRECT VARIABLE WITH SFR
                                                          ;SET U16 POINTER
                                                          BCF STATUS,IRP
                                                          BANK0
                                                          BTFSC DATA_RAM_ADDRESS_H,0
                                                          BSF STATUS,IRP
                                                          BANK0
                                                          MOVF DATA_RAM_ADDRESS,W
                                                          MOVWF FSR
                                                          BANK2
                                                          MOVF   _RX_VALUE_HI,W
                                                          MOVWF INDF

                                            GOTO LABEL_1060
                                          LABEL_1058

                                                          ;SET VARIABLE U8 WITH SFR
                                                          BANK2
                                                          MOVF   _RX_VARIABLE,W
                                                          BANK0
                                                          MOVWF CHANNEL

                                                          ;OPERATION
                                                          ;SET VARIABLE U8 WITH VARIABLE U8
                                                          MOVF   CHANNEL,W
                                                          MOVWF TEMPX8
                                                          ;SET VARIABLE U8 WITH CONSTANT
                                                          MOVLW   0X8
                                                          MOVWF TEMPY8
                                                          CALL MULV8
                                                          ;SET VARIABLE U8 WITH VARIABLE U8
                                                          BANK0
                                                          MOVF   RESULT8,W
                                                          MOVWF CHANNEL

                                                          ;OPERATION
                                                          ;SET VARIABLE U8 WITH SFR
                                                          MOVF   ADCON0,W
                                                          MOVWF TEMPX8
                                                          ;SET VARIABLE U8 WITH CONSTANT
                                                          MOVLW   0XC7
                                                          MOVWF TEMPY8
                                                          CALL ANDV8
                                                          ;SET SFR WITH VARIABLE U8
                                                          BANK0
                                                          MOVF   TEMPX8,W
                                                          MOVWF ADCON0

                                                          ;OPERATION
                                                          ;SET VARIABLE U8 WITH SFR
                                                          MOVF   ADCON0,W
                                                          MOVWF TEMPX8
                                                          ;SET VARIABLE U8 WITH VARIABLE U8
                                                          MOVF   CHANNEL,W
                                                          MOVWF TEMPY8
                                                          CALL ORV8
                                                          ;SET SFR WITH VARIABLE U8
                                                          BANK0
                                                          MOVF   TEMPX8,W
                                                          MOVWF ADCON0

                                                          CALL LABEL_AQUISITION

                                                          ;START AD-CONVERSION
                                                          BANK0
                                                          BSF ADCON0,2

                                                          ;FINISH AD-CONVERSION
                                                        LABEL_1059
                                                          BTFSC ADCON0,2
                                                          GOTO LABEL_1059
                                                          ;SET VARIABLE U8 WITH SFR
                                                          BANK0
                                                          MOVF   ADRESH,W
                                                          MOVWF ADHBYTE
                                                          ;SET VARIABLE U8 WITH SFR
                                                          BANK1
                                                          MOVF   ADRESL,W
                                                          BANK0
                                                          MOVWF ADLBYTE
                                                          ;SET VARIABLE U16 WITH VARIABLE U8
                                                          MOVF   ADLBYTE,W
                                                          MOVWF AD_RESULT
                                                          CLRF AD_RESULT_H
                                                          ;SET 16-BIT REGISTER HIGH BYTE THROUGH 8-BIT REGISTER
                                                          MOVF   ADHBYTE,W
                                                          MOVWF AD_RESULT_H

                                                          ;SET INDIRECT VARIABLE WITH VARIABLE U8
                                                          ;SET U16 POINTER
                                                          BCF STATUS,IRP
                                                          BTFSC DATA_RAM_ADDRESS_H,0
                                                          BSF STATUS,IRP
                                                          BANK0
                                                          MOVF DATA_RAM_ADDRESS,W
                                                          MOVWF FSR
                                                          MOVF   ADLBYTE,W
                                                          MOVWF INDF

                                                          INCF DATA_RAM_ADDRESS,F
                                                          BTFSC STATUS,Z
                                                          INCF DATA_RAM_ADDRESS_H,F

                                                          ;SET INDIRECT VARIABLE WITH VARIABLE U8
                                                          ;SET U16 POINTER
                                                          BCF STATUS,IRP
                                                          BANK0
                                                          BTFSC DATA_RAM_ADDRESS_H,0
                                                          BSF STATUS,IRP
                                                          BANK0
                                                          MOVF DATA_RAM_ADDRESS,W
                                                          MOVWF FSR
                                                          MOVF   ADHBYTE,W
                                                          MOVWF INDF

                                          LABEL_1060
                                          ;END OF IF-STRUCTURE

                            LABEL_1061
                            ;END OF IF-STRUCTURE

                              ;BEGIN OF IF-STRUCTURE
                              ;COMPARE-OPERATION
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              BANK0
                              MOVF   TMP_OPCODE,W
                              MOVWF TEMPX8
                              ;SET VARIABLE U8 WITH CONSTANT
                              MOVLW   0XF7
                              MOVWF TEMPY8
                              CALL EQU8U8
                              BANK0
                              MOVWF RESULT8
                              BTFSC RESULT8,0
                              GOTO LABEL_1064

                              GOTO LABEL_1098
                            LABEL_1064

                                            ;BEGIN OF IF-STRUCTURE
                                            ;COMPARE-OPERATION
                                            ;SET VARIABLE U8 WITH SFR
                                            BANK2
                                            MOVF   _RX_MESSAGE,W
                                            BANK0
                                            MOVWF TEMPX8
                                            ;SET VARIABLE U8 WITH CONSTANT
                                            MOVLW   0X1
                                            MOVWF TEMPY8
                                            CALL EQU8U8
                                            BANK0
                                            MOVWF RESULT8
                                            BTFSC RESULT8,0
                                            GOTO LABEL_1065

                                                          ;BEGIN OF IF-STRUCTURE
                                                          ;COMPARE-OPERATION
                                                          ;SET VARIABLE U8 WITH SFR
                                                          BANK2
                                                          MOVF   _RX_MESSAGE,W
                                                          BANK0
                                                          MOVWF TEMPX8
                                                          ;SET VARIABLE U8 WITH CONSTANT
                                                          MOVLW   0X2
                                                          MOVWF TEMPY8
                                                          CALL EQU8U8
                                                          BANK0
                                                          MOVWF RESULT8
                                                          BTFSC RESULT8,0
                                                          GOTO LABEL_1068

                                                                        ;BEGIN OF IF-STRUCTURE
                                                                        ;COMPARE-OPERATION
                                                                        ;SET VARIABLE U8 WITH SFR
                                                                        BANK2
                                                                        MOVF   _RX_MESSAGE,W
                                                                        BANK0
                                                                        MOVWF TEMPX8
                                                                        ;SET VARIABLE U8 WITH CONSTANT
                                                                        MOVLW   0X39
                                                                        MOVWF TEMPY8
                                                                        CALL EQU8U8
                                                                        BANK0
                                                                        MOVWF RESULT8
                                                                        BTFSC RESULT8,0
                                                                        GOTO LABEL_1069

                                                                        GOTO LABEL_1079
                                                                      LABEL_1069

                                                                                      ;START WRITING TO EEPROM
                                                                                      MOVLW 0X0
                                                                                      BANK2
                                                                                      MOVWF EEADR
                                                                                      MOVLW 0X0
                                                                                      MOVWF EEDATA
                                                                                      BANK3
                                                                                      BCF EECON1,EEPGD
                                                                                      BSF EECON1,WREN
                                                                                      BCF INTCON,GIE
                                                                                      MOVLW 0X55
                                                                                      MOVWF EECON2
                                                                                      MOVLW 0XAA
                                                                                      MOVWF EECON2
                                                                                      BSF EECON1,WR
                                                                                      BSF INTCON,GIE
                                                                                      BCF EECON1,WREN

                                                                                      ;FINISH WRITING TO EEPROM
                                                                                    LABEL_1074
                                                                                      BTFSC EECON1,WR
                                                                                      GOTO LABEL_1074

                                                                                      ;START WRITING TO EEPROM
                                                                                      MOVLW 0X1
                                                                                      BANK2
                                                                                      MOVWF EEADR
                                                                                      MOVLW 0X0
                                                                                      MOVWF EEDATA
                                                                                      BANK3
                                                                                      BCF EECON1,EEPGD
                                                                                      BSF EECON1,WREN
                                                                                      BCF INTCON,GIE
                                                                                      MOVLW 0X55
                                                                                      MOVWF EECON2
                                                                                      MOVLW 0XAA
                                                                                      MOVWF EECON2
                                                                                      BSF EECON1,WR
                                                                                      BSF INTCON,GIE
                                                                                      BCF EECON1,WREN

                                                                                      ;FINISH WRITING TO EEPROM
                                                                                    LABEL_1075
                                                                                      BTFSC EECON1,WR
                                                                                      GOTO LABEL_1075

                                                                      LABEL_1079
                                                                      ;END OF IF-STRUCTURE

                                                          GOTO LABEL_1094
                                                        LABEL_1068

                                                                        BANK0
                                                                        CLRF ADDRESS
                                                                        CLRF ADDRESS_H

                                                                        ;READ EEPROM
                                                                        MOVLW 0X0
                                                                        BANK2
                                                                        MOVWF EEADR
                                                                        BANK3
                                                                        BCF EECON1,EEPGD
                                                                        BSF EECON1,RD
                                                                        BANK2
                                                                        MOVF EEDATA,W
                                                                        BANK0
                                                                        MOVWF LOGGER_SIZE

                                                                        ;FINISH WRITING TO EEPROM
                                                                        BANK3
                                                                      LABEL_1070
                                                                        BTFSC EECON1,WR
                                                                        GOTO LABEL_1070

                                                                        ;READ EEPROM
                                                                        MOVLW 0X1
                                                                        BANK2
                                                                        MOVWF EEADR
                                                                        BANK3
                                                                        BCF EECON1,EEPGD
                                                                        BSF EECON1,RD
                                                                        BANK2
                                                                        MOVF EEDATA,W
                                                                        BANK0
                                                                        MOVWF TMP_ADDR

                                                                        ;FINISH WRITING TO EEPROM
                                                                        BANK3
                                                                      LABEL_1071
                                                                        BTFSC EECON1,WR
                                                                        GOTO LABEL_1071

                                                                        ;SET 16-BIT REGISTER HIGH BYTE THROUGH 8-BIT REGISTER
                                                                        BANK0
                                                                        MOVF   TMP_ADDR,W
                                                                        MOVWF LOGGER_SIZE_H

                                                                        CLRF RETRIES

                                                                        ;BEGIN OF WHILE-LOOP
                                                                      LABEL_1072
                                                                        ;COMPARE-OPERATION
                                                                        ;SET VARIABLE U8 WITH VARIABLE U8
                                                                        BANK0
                                                                        MOVF   RETRIES,W
                                                                        MOVWF TEMPY8
                                                                        ;SET VARIABLE U8 WITH CONSTANT
                                                                        MOVLW   0X4
                                                                        MOVWF TEMPX8
                                                                        CALL GRU8U8
                                                                        BANK0
                                                                        MOVWF RESULT8
                                                                        BTFSC RESULT8,0
                                                                        GOTO LABEL_1073

                                                                                      ;BEGIN OF 16-BIT FOR-LOOP
                                                                                      ;SET VARIABLE U16 WITH VARIABLE U16
                                                                                      BANK0
                                                                                      MOVF   LOGGER_SIZE,W
                                                                                      MOVWF I16_COUNT
                                                                                      MOVF LOGGER_SIZE_H,W
                                                                                      MOVWF I16_COUNT_H
                                                                                      INCF I16_COUNT,F
                                                                                      BTFSC STATUS,Z
                                                                                      INCF I16_COUNT_H,F
                                                                                    LABEL_1077
                                                                                      MOVF I16_COUNT,F
                                                                                      BTFSC STATUS,Z
                                                                                      DECF I16_COUNT_H,F
                                                                                      DECF I16_COUNT,F
                                                                                      
                                                                                      MOVF I16_COUNT_H,F
                                                                                      BTFSS STATUS,Z
                                                                                      GOTO LABEL_1076
                                                                                      MOVF I16_COUNT,F
                                                                                    LABEL_1076
                                                                                      BTFSC STATUS,Z
                                                                                      GOTO LABEL_1078

                                                                                                    BANK0

                                                                                                    CALL LABEL_BSTART

                                                                                                    ;SET VARIABLE U8 WITH CONSTANT
                                                                                                    MOVLW   0XA2
                                                                                                    BANK0
                                                                                                    MOVWF DATAO

                                                                                                    CALL LABEL_TX

                                                                                                    ;SET  16-BIT REGISTER HIGH-BYTE THROUGH 8-BIT REGISTER
                                                                                                    BANK0
                                                                                                    MOVF   ADDRESS_H,W
                                                                                                    MOVWF  DATAO

                                                                                                    CALL LABEL_TX

                                                                                                    ;SET VARIABLE U8 WITH VARIABLE U16
                                                                                                    BANK0
                                                                                                    MOVF   ADDRESS,W
                                                                                                    MOVWF DATAO

                                                                                                    CALL LABEL_TX

                                                                                                    CALL LABEL_BSTART

                                                                                                    ;SET VARIABLE U8 WITH CONSTANT
                                                                                                    MOVLW   0XA3
                                                                                                    BANK0
                                                                                                    MOVWF DATAO

                                                                                                    CALL LABEL_TX

                                                                                                    BANK0
                                                                                                    BCF BUFFER,ACKB      ;SELECT TO SEND NO ACK BIT

                                                                                                    CALL LABEL_RX

                                                                                                    CALL LABEL_BSTOP

                                                                                                    ;SET VARIABLE U8 WITH VARIABLE U8
                                                                                                    BANK0
                                                                                                    MOVF   DATAI,W
                                                                                                    MOVWF LOGGER_DATA_BYTE

                                                                                                    ;SEND MAIL
                                                                                                  LABEL_1087
                                                                                                    BTFSS PIR1,TXIF
                                                                                                    GOTO LABEL_1087
                                                                                                    ;SET SFR WITH VARIABLE U8
                                                                                                    BANK0
                                                                                                    MOVF   LOGGER_DATA_BYTE,W
                                                                                                    MOVWF TXREG

                                                                                                    
                                                                                                  LABEL_1086

                                                                                                    BTFSS PIR1,TXIF

                                                                                                    GOTO LABEL_1086

                                                                                                    BANK0
                                                                                                    INCF ADDRESS,F
                                                                                                    BTFSC STATUS,Z
                                                                                                    INCF ADDRESS_H,F

                                                                                                    ;SET VARIABLE U16 WITH CONSTANT
                                                                                                    MOVLW   0X1
                                                                                                    BANK0
                                                                                                    MOVWF SD_WAIT_MS_TIME
                                                                                                    MOVLW 0X0
                                                                                                    MOVWF SD_WAIT_MS_TIME_H

                                                                                                    CALL LABEL_SD_WAIT_MS

                                                                                      GOTO LABEL_1077
                                                                                    LABEL_1078
                                                                                    ;END OF FOR/WHILE-LOOP

                                                                                      ;BEGIN OF IF-STRUCTURE
                                                                                      ;COMPARE-OPERATION
                                                                                      ;SET VARIABLE U8 WITH VARIABLE U8
                                                                                      BANK0
                                                                                      MOVF   I2C_ERROR,W
                                                                                      MOVWF TEMPX8
                                                                                      ;SET VARIABLE U8 WITH CONSTANT
                                                                                      MOVLW   0X0
                                                                                      MOVWF TEMPY8
                                                                                      CALL EQU8U8
                                                                                      BANK0
                                                                                      MOVWF RESULT8
                                                                                      BTFSC RESULT8,0
                                                                                      GOTO LABEL_1090

                                                                                                    BANK0
                                                                                                    INCF RETRIES,F

                                                                                                    CLRF I2C_ERROR

                                                                                      GOTO LABEL_1092
                                                                                    LABEL_1090

                                                                                                    GOTO LABEL_1062

                                                                                    LABEL_1092
                                                                                    ;END OF IF-STRUCTURE

                                                                        GOTO LABEL_1072
                                                                      LABEL_1073
                                                                      ;END OF FOR/WHILE-LOOP

                                                                        ;SET VARIABLE U8 WITH CONSTANT
                                                                        MOVLW   0X1
                                                                        BANK0
                                                                        MOVWF DEVICE_ERROR

                                                                      LABEL_1062

                                                        LABEL_1094
                                                        ;END OF IF-STRUCTURE

                                            GOTO LABEL_1097
                                          LABEL_1065

                                                          BANK0
                                                          CLRF RETRIES

                                                          ;BEGIN OF WHILE-LOOP
                                                        LABEL_1066
                                                          ;COMPARE-OPERATION
                                                          ;SET VARIABLE U8 WITH VARIABLE U8
                                                          BANK0
                                                          MOVF   RETRIES,W
                                                          MOVWF TEMPY8
                                                          ;SET VARIABLE U8 WITH CONSTANT
                                                          MOVLW   0X4
                                                          MOVWF TEMPX8
                                                          CALL GRU8U8
                                                          BANK0
                                                          MOVWF RESULT8
                                                          BTFSC RESULT8,0
                                                          GOTO LABEL_1067

                                                                        ;READ EEPROM
                                                                        MOVLW 0X0
                                                                        BANK2
                                                                        MOVWF EEADR
                                                                        BANK3
                                                                        BCF EECON1,EEPGD
                                                                        BSF EECON1,RD
                                                                        BANK2
                                                                        MOVF EEDATA,W
                                                                        BANK0
                                                                        MOVWF ADDRESS

                                                                        ;FINISH WRITING TO EEPROM
                                                                        BANK3
                                                                      LABEL_1080
                                                                        BTFSC EECON1,WR
                                                                        GOTO LABEL_1080

                                                                        ;READ EEPROM
                                                                        MOVLW 0X1
                                                                        BANK2
                                                                        MOVWF EEADR
                                                                        BANK3
                                                                        BCF EECON1,EEPGD
                                                                        BSF EECON1,RD
                                                                        BANK2
                                                                        MOVF EEDATA,W
                                                                        BANK0
                                                                        MOVWF TMP_ADDR

                                                                        ;FINISH WRITING TO EEPROM
                                                                        BANK3
                                                                      LABEL_1081
                                                                        BTFSC EECON1,WR
                                                                        GOTO LABEL_1081

                                                                        ;SET 16-BIT REGISTER HIGH BYTE THROUGH 8-BIT REGISTER
                                                                        BANK0
                                                                        MOVF   TMP_ADDR,W
                                                                        MOVWF ADDRESS_H

                                                                        ;SET VARIABLE U16 WITH CONSTANT
                                                                        MOVLW   0XA4
                                                                        MOVWF DATA_RAM_ADDRESS
                                                                        MOVLW 0X0
                                                                        MOVWF DATA_RAM_ADDRESS_H

                                                                        ;BEGIN OF FOR-LOOP
                                                                        ;SET VARIABLE U8 WITH CONSTANT
                                                                        MOVLW   0X18
                                                                        MOVWF I
                                                                        INCF I,F
                                                                      LABEL_1082
                                                                        BANK0
                                                                        DECF I,F
                                                                        BTFSC STATUS,Z 
                                                                        GOTO LABEL_1083

                                                                                      BANK0

                                                                                      CALL LABEL_BSTART

                                                                                      ;SET VARIABLE U8 WITH CONSTANT
                                                                                      MOVLW   0XA2
                                                                                      BANK0
                                                                                      MOVWF DATAO

                                                                                      CALL LABEL_TX

                                                                                      ;SET  16-BIT REGISTER HIGH-BYTE THROUGH 8-BIT REGISTER
                                                                                      BANK0
                                                                                      MOVF   ADDRESS_H,W
                                                                                      MOVWF  DATAO

                                                                                      CALL LABEL_TX

                                                                                      ;SET VARIABLE U8 WITH VARIABLE U16
                                                                                      BANK0
                                                                                      MOVF   ADDRESS,W
                                                                                      MOVWF DATAO

                                                                                      CALL LABEL_TX

                                                                                      ;SET VARIABLE U8 WITH INDIRECT VARIABLE
                                                                                      ;SET U16 POINTER
                                                                                      BCF STATUS,IRP
                                                                                      BANK0
                                                                                      BTFSC DATA_RAM_ADDRESS_H,0
                                                                                      BSF STATUS,IRP
                                                                                      BANK0
                                                                                      MOVF DATA_RAM_ADDRESS,W
                                                                                      MOVWF FSR
                                                                                      MOVF   INDF,W
                                                                                      MOVWF DATAO

                                                                                      CALL LABEL_TX

                                                                                      CALL LABEL_BSTOP

                                                                                      BANK0
                                                                                      INCF DATA_RAM_ADDRESS,F
                                                                                      BTFSC STATUS,Z
                                                                                      INCF DATA_RAM_ADDRESS_H,F

                                                                                      BANK0
                                                                                      INCF ADDRESS,F
                                                                                      BTFSC STATUS,Z
                                                                                      INCF ADDRESS_H,F

                                                                                      ;SET SINGLE OUPUT PIN
                                                                                      BANK0
                                                                                      BSF PORTB,1

                                                                                      ;SET VARIABLE U16 WITH CONSTANT
                                                                                      MOVLW   0X4
                                                                                      MOVWF SD_WAIT_MS_TIME
                                                                                      MOVLW 0X0
                                                                                      MOVWF SD_WAIT_MS_TIME_H

                                                                                      CALL LABEL_SD_WAIT_MS

                                                                                      ;SET SINGLE OUPUT PIN
                                                                                      BANK0
                                                                                      BCF PORTB,1

                                                                                      ;SET VARIABLE U16 WITH CONSTANT
                                                                                      MOVLW   0X4
                                                                                      MOVWF SD_WAIT_MS_TIME
                                                                                      MOVLW 0X0
                                                                                      MOVWF SD_WAIT_MS_TIME_H

                                                                                      CALL LABEL_SD_WAIT_MS

                                                                        GOTO LABEL_1082
                                                                      LABEL_1083
                                                                      ;END OF FOR/WHILE-LOOP

                                                                        ;BEGIN OF IF-STRUCTURE
                                                                        ;COMPARE-OPERATION
                                                                        ;SET VARIABLE U8 WITH VARIABLE U8
                                                                        BANK0
                                                                        MOVF   I2C_ERROR,W
                                                                        MOVWF TEMPX8
                                                                        ;SET VARIABLE U8 WITH CONSTANT
                                                                        MOVLW   0X0
                                                                        MOVWF TEMPY8
                                                                        CALL EQU8U8
                                                                        BANK0
                                                                        MOVWF RESULT8
                                                                        BTFSC RESULT8,0
                                                                        GOTO LABEL_1088

                                                                                      BANK0
                                                                                      INCF RETRIES,F

                                                                                      CLRF I2C_ERROR

                                                                        GOTO LABEL_1096
                                                                      LABEL_1088

                                                                                      ;BEGIN OF IF-STRUCTURE
                                                                                      ;COMPARE-OPERATION
                                                                                      ;SET VARIABLE U16 WITH VARIABLE U16
                                                                                      BANK0
                                                                                      MOVF   ADDRESS,W
                                                                                      MOVWF TEMPX16
                                                                                      MOVF ADDRESS_H,W
                                                                                      MOVWF TEMPX16_H
                                                                                      ;SET VARIABLE U16 WITH CONSTANT
                                                                                      MOVLW   0XFD
                                                                                      MOVWF TEMPY16
                                                                                      MOVLW 0X7F
                                                                                      MOVWF TEMPY16_H
                                                                                      CALL GRU16U16
                                                                                      BANK0
                                                                                      MOVWF RESULT8
                                                                                      BTFSC RESULT8,0
                                                                                      GOTO LABEL_1089

                                                                                                    ;SET VARIABLE U8 WITH CONSTANT
                                                                                                    MOVLW   0X4
                                                                                                    BANK0
                                                                                                    MOVWF DEVICE_ERROR

                                                                                      GOTO LABEL_1095
                                                                                    LABEL_1089

                                                                                                    ;SET VARIABLE U8 WITH VARIABLE U16
                                                                                                    BANK0
                                                                                                    MOVF   ADDRESS,W
                                                                                                    MOVWF TMP_ADDR

                                                                                                    ;START WRITING TO EEPROM
                                                                                                    MOVLW 0X0
                                                                                                    BANK2
                                                                                                    MOVWF EEADR
                                                                                                    BANK0
                                                                                                    MOVF TMP_ADDR,W
                                                                                                    BANK2
                                                                                                    MOVWF EEDATA
                                                                                                    BANK3
                                                                                                    BCF EECON1,EEPGD
                                                                                                    BSF EECON1,WREN
                                                                                                    BCF INTCON,GIE
                                                                                                    MOVLW 0X55
                                                                                                    MOVWF EECON2
                                                                                                    MOVLW 0XAA
                                                                                                    MOVWF EECON2
                                                                                                    BSF EECON1,WR
                                                                                                    BSF INTCON,GIE
                                                                                                    BCF EECON1,WREN

                                                                                                    ;FINISH WRITING TO EEPROM
                                                                                                  LABEL_1091
                                                                                                    BTFSC EECON1,WR
                                                                                                    GOTO LABEL_1091

                                                                                                    ;SET  16-BIT REGISTER HIGH-BYTE THROUGH 8-BIT REGISTER
                                                                                                    BANK0
                                                                                                    MOVF   ADDRESS_H,W
                                                                                                    MOVWF  TMP_ADDR

                                                                                                    ;START WRITING TO EEPROM
                                                                                                    MOVLW 0X1
                                                                                                    BANK2
                                                                                                    MOVWF EEADR
                                                                                                    BANK0
                                                                                                    MOVF TMP_ADDR,W
                                                                                                    BANK2
                                                                                                    MOVWF EEDATA
                                                                                                    BANK3
                                                                                                    BCF EECON1,EEPGD
                                                                                                    BSF EECON1,WREN
                                                                                                    BCF INTCON,GIE
                                                                                                    MOVLW 0X55
                                                                                                    MOVWF EECON2
                                                                                                    MOVLW 0XAA
                                                                                                    MOVWF EECON2
                                                                                                    BSF EECON1,WR
                                                                                                    BSF INTCON,GIE
                                                                                                    BCF EECON1,WREN

                                                                                                    ;FINISH WRITING TO EEPROM
                                                                                                  LABEL_1093
                                                                                                    BTFSC EECON1,WR
                                                                                                    GOTO LABEL_1093

                                                                                    LABEL_1095
                                                                                    ;END OF IF-STRUCTURE

                                                                                      GOTO LABEL_1063

                                                                      LABEL_1096
                                                                      ;END OF IF-STRUCTURE

                                                          GOTO LABEL_1066
                                                        LABEL_1067
                                                        ;END OF FOR/WHILE-LOOP

                                                          ;SET VARIABLE U8 WITH CONSTANT
                                                          MOVLW   0X1
                                                          BANK0
                                                          MOVWF DEVICE_ERROR

                                                        LABEL_1063

                                          LABEL_1097
                                          ;END OF IF-STRUCTURE

                            LABEL_1098
                            ;END OF IF-STRUCTURE

                              CALL LABEL_RESET_UART_RX

              LABEL_1099
              ;END OF IF-STRUCTURE

  GOTO LABEL_1122
LABEL_1053

                BANK0

                CALL LABEL_BSTART

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0XA0
                BANK0
                MOVWF DATAO

                CALL LABEL_TX

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X0
                BANK0
                MOVWF DATAO

                CALL LABEL_TX

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X0
                BANK0
                MOVWF DATAO

                CALL LABEL_TX

                CALL LABEL_BSTART

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0XA1
                BANK0
                MOVWF DATAO

                CALL LABEL_TX

                BANK0
                BCF BUFFER,ACKB      ;SELECT TO SEND NO ACK BIT

                CALL LABEL_RX

                CALL LABEL_BSTOP

                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   DATAI,W
                MOVWF TOGGLE_BIT

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   TOGGLE_BIT,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X8
                MOVWF TEMPY8
                CALL ANDV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF TOGGLE_BIT

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X65
                MOVWF OPCODE

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   OPCODE,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   TOGGLE_BIT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF OPCODE

                ;SET VARIABLE U16 WITH CONSTANT
                MOVLW   0X90
                MOVWF UART_TX_BUFFER_POINTER
                MOVLW 0X1
                MOVWF UART_TX_BUFFER_POINTER_H

                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   OPCODE,W
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   UART_CURRENT,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X2
                MOVWF UART_TX_LENGTH

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X1
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X3
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X5
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X7
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0XB
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_TX_LENGTH,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X5
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF UART_TX_LENGTH

                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   PACKET_CHECKSUM,W
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;SET VARIABLE U16 WITH CONSTANT
                MOVLW   0X90
                BANK0
                MOVWF UART_TX_BUFFER_POINTER
                MOVLW 0X1
                MOVWF UART_TX_BUFFER_POINTER_H

                CALL LABEL_SEND_UART_TX

                ;BEGIN OF WHILE-LOOP
              LABEL_1084
                ;COMPARE-OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   UART_STATE,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X0
                MOVWF TEMPY8
                CALL EQU8U8
                BANK0
                MOVWF RESULT8
                BTFSC RESULT8,0
                GOTO LABEL_1085

                GOTO LABEL_1084
              LABEL_1085
              ;END OF FOR/WHILE-LOOP

                ;SET VARIABLE U16 WITH CONSTANT
                MOVLW   0XF4
                BANK0
                MOVWF SD_WAIT_MS_TIME
                MOVLW 0X1
                MOVWF SD_WAIT_MS_TIME_H

                CALL LABEL_SD_WAIT_MS

                BANK0

                CALL LABEL_BSTART

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0XA0
                BANK0
                MOVWF DATAO

                CALL LABEL_TX

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X7F
                BANK0
                MOVWF DATAO

                CALL LABEL_TX

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0XFE
                BANK0
                MOVWF DATAO

                CALL LABEL_TX

                CALL LABEL_BSTART

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0XA1
                BANK0
                MOVWF DATAO

                CALL LABEL_TX

                BANK0
                BCF BUFFER,ACKB      ;SELECT TO SEND NO ACK BIT

                CALL LABEL_RX

                CALL LABEL_BSTOP

                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   DATAI,W
                MOVWF FW_CHS_LO


                CALL LABEL_BSTART

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0XA0
                BANK0
                MOVWF DATAO

                CALL LABEL_TX

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X7F
                BANK0
                MOVWF DATAO

                CALL LABEL_TX

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0XFF
                BANK0
                MOVWF DATAO

                CALL LABEL_TX

                CALL LABEL_BSTART

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0XA1
                BANK0
                MOVWF DATAO

                CALL LABEL_TX

                BANK0
                BCF BUFFER,ACKB      ;SELECT TO SEND NO ACK BIT

                CALL LABEL_RX

                CALL LABEL_BSTOP

                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   DATAI,W
                MOVWF FW_CHS_HI

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   TOGGLE_BIT,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X8
                MOVWF TEMPY8
                CALL XOR_V8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF TOGGLE_BIT

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X75
                MOVWF OPCODE

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   OPCODE,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   TOGGLE_BIT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF OPCODE

                ;SET VARIABLE U16 WITH CONSTANT
                MOVLW   0X90
                MOVWF UART_TX_BUFFER_POINTER
                MOVLW 0X1
                MOVWF UART_TX_BUFFER_POINTER_H

                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   OPCODE,W
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   UART_CURRENT,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X2
                MOVWF UART_TX_LENGTH

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X0
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X80
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   FW_CHS_LO,W
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   FW_CHS_HI,W
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X0
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_TX_LENGTH,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X5
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF UART_TX_LENGTH

                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   PACKET_CHECKSUM,W
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;SET VARIABLE U16 WITH CONSTANT
                MOVLW   0X90
                BANK0
                MOVWF UART_TX_BUFFER_POINTER
                MOVLW 0X1
                MOVWF UART_TX_BUFFER_POINTER_H

                CALL LABEL_SEND_UART_TX

                ;BEGIN OF WHILE-LOOP
              LABEL_1100
                ;COMPARE-OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   UART_STATE,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X0
                MOVWF TEMPY8
                CALL EQU8U8
                BANK0
                MOVWF RESULT8
                BTFSC RESULT8,0
                GOTO LABEL_1101

                GOTO LABEL_1100
              LABEL_1101
              ;END OF FOR/WHILE-LOOP

                ;SET VARIABLE U16 WITH CONSTANT
                MOVLW   0XF4
                BANK0
                MOVWF SD_WAIT_MS_TIME
                MOVLW 0X1
                MOVWF SD_WAIT_MS_TIME_H

                CALL LABEL_SD_WAIT_MS

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TOGGLE_BIT,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X8
                MOVWF TEMPY8
                CALL XOR_V8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF TOGGLE_BIT

                CLRF ADDRESS
                CLRF ADDRESS_H

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X60
                MOVWF UART_TX_LENGTH

                ;SET SFR WITH CONSTANT
                MOVLW   0X1
                BANK3
                MOVWF _TX_BL_COUNT_LO

                ;BEGIN OF WHILE-LOOP
              LABEL_1103
                ;COMPARE-OPERATION
                ;SET VARIABLE U8 WITH SFR
                BANK3
                MOVF   _TX_BL_COUNT_LO,W
                BANK0
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X0
                MOVWF TEMPY8
                CALL EQU8U8
                BANK0
                MOVWF RESULT8
                BTFSC RESULT8,0
                GOTO LABEL_1104

                              ;BEGIN OF IF-STRUCTURE
                              ;COMPARE-OPERATION
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              BANK0
                              MOVF   I2C_ERROR,W
                              MOVWF TEMPX8
                              ;SET VARIABLE U8 WITH CONSTANT
                              MOVLW   0X0
                              MOVWF TEMPY8
                              CALL EQU8U8
                              BANK0
                              MOVWF RESULT8
                              BTFSC RESULT8,0
                              GOTO LABEL_1106

                                            BANK0
                                            CLRF I2C_ERROR

                              GOTO LABEL_1115
                            LABEL_1106

                                            ;BEGIN OF IF-STRUCTURE
                                            ;COMPARE-OPERATION
                                            ;SET VARIABLE U16 WITH VARIABLE U16
                                            BANK0
                                            MOVF   ADDRESS,W
                                            MOVWF TEMPX16
                                            MOVF ADDRESS_H,W
                                            MOVWF TEMPX16_H
                                            ;SET VARIABLE U16 WITH CONSTANT
                                            MOVLW   0XC0
                                            MOVWF TEMPY16
                                            MOVLW 0X5D
                                            MOVWF TEMPY16_H
                                            CALL GRU16U16
                                            BANK0
                                            MOVWF RESULT8
                                            BTFSC RESULT8,0
                                            GOTO LABEL_1107

                                                          ;SET VARIABLE U8 WITH CONSTANT
                                                          MOVLW   0X3
                                                          BANK0
                                                          MOVWF DEVICE_ERROR

                                                          GOTO LABEL_1105

                                            GOTO LABEL_1114
                                          LABEL_1107

                                                          BANK0
                                                          CLRF RETRIES

                                                          ;BEGIN OF WHILE-LOOP
                                                        LABEL_1108
                                                          ;COMPARE-OPERATION
                                                          ;SET VARIABLE U8 WITH VARIABLE U8
                                                          BANK0
                                                          MOVF   RETRIES,W
                                                          MOVWF TEMPY8
                                                          ;SET VARIABLE U8 WITH CONSTANT
                                                          MOVLW   0XA
                                                          MOVWF TEMPX8
                                                          CALL GRU8U8
                                                          BANK0
                                                          MOVWF RESULT8
                                                          BTFSC RESULT8,0
                                                          GOTO LABEL_1109

                                                                        ;SET VARIABLE U16 WITH CONSTANT
                                                                        MOVLW   0X90
                                                                        BANK0
                                                                        MOVWF UART_TX_BUFFER_POINTER
                                                                        MOVLW 0X1
                                                                        MOVWF UART_TX_BUFFER_POINTER_H

                                                                        ;SET VARIABLE U16 WITH CONSTANT
                                                                        MOVLW   0XF0
                                                                        MOVWF UART_TX_DATA_LAST_BYTE_ADDR
                                                                        MOVLW 0X1
                                                                        MOVWF UART_TX_DATA_LAST_BYTE_ADDR_H

                                                                        ;BEGIN OF WHILE-LOOP
                                                                      LABEL_1110
                                                                        ;COMPARE-OPERATION
                                                                        ;SET VARIABLE U16 WITH VARIABLE U16
                                                                        BANK0
                                                                        MOVF   UART_TX_BUFFER_POINTER,W
                                                                        MOVWF TEMPY16
                                                                        MOVF UART_TX_BUFFER_POINTER_H,W
                                                                        MOVWF TEMPY16_H
                                                                        ;SET VARIABLE U16 WITH VARIABLE U16
                                                                        MOVF   UART_TX_DATA_LAST_BYTE_ADDR,W
                                                                        MOVWF TEMPX16
                                                                        MOVF UART_TX_DATA_LAST_BYTE_ADDR_H,W
                                                                        MOVWF TEMPX16_H
                                                                        CALL GRU16U16
                                                                        BANK0
                                                                        MOVWF RESULT8
                                                                        BTFSC RESULT8,0
                                                                        GOTO LABEL_1111

                                                                                      BANK0

                                                                                      CALL LABEL_BSTART

                                                                                      ;SET VARIABLE U8 WITH CONSTANT
                                                                                      MOVLW   0XA0
                                                                                      BANK0
                                                                                      MOVWF DATAO

                                                                                      CALL LABEL_TX

                                                                                      ;SET  16-BIT REGISTER HIGH-BYTE THROUGH 8-BIT REGISTER
                                                                                      BANK0
                                                                                      MOVF   ADDRESS_H,W
                                                                                      MOVWF  DATAO

                                                                                      CALL LABEL_TX

                                                                                      ;SET VARIABLE U8 WITH VARIABLE U16
                                                                                      BANK0
                                                                                      MOVF   ADDRESS,W
                                                                                      MOVWF DATAO

                                                                                      CALL LABEL_TX

                                                                                      CALL LABEL_BSTART

                                                                                      ;SET VARIABLE U8 WITH CONSTANT
                                                                                      MOVLW   0XA1
                                                                                      BANK0
                                                                                      MOVWF DATAO

                                                                                      CALL LABEL_TX

                                                                                      BANK0
                                                                                      BCF BUFFER,ACKB      ;SELECT TO SEND NO ACK BIT

                                                                                      CALL LABEL_RX

                                                                                      CALL LABEL_BSTOP

                                                                                      ;SET INDIRECT VARIABLE WITH VARIABLE U8
                                                                                      ;SET U16 POINTER
                                                                                      BCF STATUS,IRP
                                                                                      BANK0
                                                                                      BTFSC UART_TX_BUFFER_POINTER_H,0
                                                                                      BSF STATUS,IRP
                                                                                      BANK0
                                                                                      MOVF UART_TX_BUFFER_POINTER,W
                                                                                      MOVWF FSR
                                                                                      MOVF   DATAI,W
                                                                                      MOVWF INDF

                                                                                      ;SET SINGLE OUPUT PIN
                                                                                      BSF PORTB,1

                                                                                      ;SET VARIABLE U16 WITH CONSTANT
                                                                                      MOVLW   0X3
                                                                                      MOVWF SD_WAIT_MS_TIME
                                                                                      MOVLW 0X0
                                                                                      MOVWF SD_WAIT_MS_TIME_H

                                                                                      CALL LABEL_SD_WAIT_MS

                                                                                      ;SET SINGLE OUPUT PIN
                                                                                      BANK0
                                                                                      BCF PORTB,1

                                                                                      ;SET VARIABLE U16 WITH CONSTANT
                                                                                      MOVLW   0X3
                                                                                      MOVWF SD_WAIT_MS_TIME
                                                                                      MOVLW 0X0
                                                                                      MOVWF SD_WAIT_MS_TIME_H

                                                                                      CALL LABEL_SD_WAIT_MS

                                                                                      BANK0
                                                                                      INCF ADDRESS,F
                                                                                      BTFSC STATUS,Z
                                                                                      INCF ADDRESS_H,F

                                                                                      BANK0
                                                                                      INCF UART_TX_BUFFER_POINTER,F
                                                                                      BTFSC STATUS,Z
                                                                                      INCF UART_TX_BUFFER_POINTER_H,F

                                                                        GOTO LABEL_1110
                                                                      LABEL_1111
                                                                      ;END OF FOR/WHILE-LOOP

                                                                        ;BEGIN OF IF-STRUCTURE
                                                                        ;COMPARE-OPERATION
                                                                        ;SET VARIABLE U8 WITH VARIABLE U8
                                                                        BANK0
                                                                        MOVF   I2C_ERROR,W
                                                                        MOVWF TEMPX8
                                                                        ;SET VARIABLE U8 WITH CONSTANT
                                                                        MOVLW   0X0
                                                                        MOVWF TEMPY8
                                                                        CALL EQU8U8
                                                                        BANK0
                                                                        MOVWF RESULT8
                                                                        BTFSC RESULT8,0
                                                                        GOTO LABEL_1112

                                                                                      BANK0
                                                                                      INCF RETRIES,F

                                                                                      ;OPERATION
                                                                                      ;SET VARIABLE U16 WITH VARIABLE U16
                                                                                      MOVF   ADDRESS,W
                                                                                      MOVWF TEMPX16
                                                                                      MOVF ADDRESS_H,W
                                                                                      MOVWF TEMPX16_H
                                                                                      ;SET VARIABLE U16 WITH CONSTANT
                                                                                      MOVLW   0X60
                                                                                      MOVWF TEMPY16
                                                                                      MOVLW 0X0
                                                                                      MOVWF TEMPY16_H
                                                                                      CALL SUBV16
                                                                                      ;SET VARIABLE U16 WITH VARIABLE U16
                                                                                      BANK0
                                                                                      MOVF   TEMPX16,W
                                                                                      MOVWF ADDRESS
                                                                                      MOVF TEMPX16_H,W
                                                                                      MOVWF ADDRESS_H

                                                                                      CLRF I2C_ERROR

                                                                        GOTO LABEL_1113
                                                                      LABEL_1112

                                                                                      GOTO LABEL_1105

                                                                      LABEL_1113
                                                                      ;END OF IF-STRUCTURE

                                                          GOTO LABEL_1108
                                                        LABEL_1109
                                                        ;END OF FOR/WHILE-LOOP

                                          LABEL_1114
                                          ;END OF IF-STRUCTURE

                            LABEL_1115
                            ;END OF IF-STRUCTURE

                              ;SET VARIABLE U8 WITH CONSTANT
                              MOVLW   0X1
                              BANK0
                              MOVWF DEVICE_ERROR

                            LABEL_1105

                              ;SET VARIABLE U8 WITH SFR
                              BANK3
                              MOVF   _TX_BYTE_COUNT_LO,W
                              BANK0
                              MOVWF UART_TX_LENGTH

                              ;OPERATION
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              MOVF   UART_TX_LENGTH,W
                              MOVWF TEMPX8
                              ;SET VARIABLE U8 WITH CONSTANT
                              MOVLW   0X7
                              MOVWF TEMPY8
                              CALL SUMV8
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              BANK0
                              MOVF   TEMPX8,W
                              MOVWF UART_TX_LENGTH

                              ;BEGIN OF IF-STRUCTURE
                              ;COMPARE-OPERATION
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              MOVF   DEVICE_ERROR,W
                              MOVWF TEMPX8
                              ;SET VARIABLE U8 WITH CONSTANT
                              MOVLW   0X0
                              MOVWF TEMPY8
                              CALL EQU8U8
                              BANK0
                              MOVWF RESULT8
                              BTFSC RESULT8,0
                              GOTO LABEL_1116

                                            GOTO LABEL_1102

                              GOTO LABEL_1119
                            LABEL_1116

                                            CALL LABEL_SEND_UART_TX

                                            ;BEGIN OF WHILE-LOOP
                                          LABEL_1117
                                            ;COMPARE-OPERATION
                                            ;SET VARIABLE U8 WITH VARIABLE U8
                                            BANK0
                                            MOVF   UART_STATE,W
                                            MOVWF TEMPX8
                                            ;SET VARIABLE U8 WITH CONSTANT
                                            MOVLW   0X0
                                            MOVWF TEMPY8
                                            CALL EQU8U8
                                            BANK0
                                            MOVWF RESULT8
                                            BTFSC RESULT8,0
                                            GOTO LABEL_1118

                                            GOTO LABEL_1117
                                          LABEL_1118
                                          ;END OF FOR/WHILE-LOOP

                                            ;SET VARIABLE U16 WITH CONSTANT
                                            MOVLW   0XF4
                                            BANK0
                                            MOVWF SD_WAIT_MS_TIME
                                            MOVLW 0X1
                                            MOVWF SD_WAIT_MS_TIME_H

                                            CALL LABEL_SD_WAIT_MS

                            LABEL_1119
                            ;END OF IF-STRUCTURE

                              ;OPERATION
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              BANK0
                              MOVF   TOGGLE_BIT,W
                              MOVWF TEMPX8
                              ;SET VARIABLE U8 WITH CONSTANT
                              MOVLW   0X8
                              MOVWF TEMPY8
                              CALL XOR_V8
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              BANK0
                              MOVF   TEMPX8,W
                              MOVWF TOGGLE_BIT

                GOTO LABEL_1103
              LABEL_1104
              ;END OF FOR/WHILE-LOOP

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0XA5
                BANK0
                MOVWF OPCODE

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   OPCODE,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   TOGGLE_BIT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF OPCODE

                ;SET VARIABLE U16 WITH CONSTANT
                MOVLW   0X90
                MOVWF UART_TX_BUFFER_POINTER
                MOVLW 0X1
                MOVWF UART_TX_BUFFER_POINTER_H

                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   OPCODE,W
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   UART_CURRENT,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X2
                MOVWF UART_TX_LENGTH

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X4C
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X45
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X47
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X4F
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0XAE
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   PACKET_CHECKSUM,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_CURRENT,W
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF PACKET_CHECKSUM

                ;OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   UART_TX_LENGTH,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X5
                MOVWF TEMPY8
                CALL SUMV8
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   TEMPX8,W
                MOVWF UART_TX_LENGTH

                ;SET VARIABLE U8 WITH VARIABLE U8
                MOVF   PACKET_CHECKSUM,W
                MOVWF UART_CURRENT

                CALL LABEL_SET_TO_UART_TX_BUFFER

                ;SET VARIABLE U16 WITH CONSTANT
                MOVLW   0X90
                BANK0
                MOVWF UART_TX_BUFFER_POINTER
                MOVLW 0X1
                MOVWF UART_TX_BUFFER_POINTER_H

                CALL LABEL_SEND_UART_TX

                ;BEGIN OF WHILE-LOOP
              LABEL_1120
                ;COMPARE-OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   UART_STATE,W
                MOVWF TEMPX8
                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X0
                MOVWF TEMPY8
                CALL EQU8U8
                BANK0
                MOVWF RESULT8
                BTFSC RESULT8,0
                GOTO LABEL_1121

                GOTO LABEL_1120
              LABEL_1121
              ;END OF FOR/WHILE-LOOP

              LABEL_1102

                ;SET VARIABLE U16 WITH CONSTANT
                MOVLW   0X10
                BANK0
                MOVWF SD_WAIT_MS_TIME
                MOVLW 0X27
                MOVWF SD_WAIT_MS_TIME_H

                CALL LABEL_SD_WAIT_MS

                CALL LABEL_RESET_UART_RX

LABEL_1122
;END OF IF-STRUCTURE

  ;BEGIN OF IF-STRUCTURE
  ;COMPARE-OPERATION
  ;SET VARIABLE U8 WITH VARIABLE U8
  BANK0
  MOVF   DEVICE_ERROR,W
  MOVWF TEMPX8
  ;SET VARIABLE U8 WITH CONSTANT
  MOVLW   0X0
  MOVWF TEMPY8
  CALL EQU8U8
  BANK0
  MOVWF RESULT8
  BTFSC RESULT8,0
  GOTO LABEL_1123

                ;BEGIN OF FOR-LOOP
                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X19
                BANK0
                MOVWF I
                INCF I,F
              LABEL_1124
                BANK0
                DECF I,F
                BTFSC STATUS,Z 
                GOTO LABEL_1125

                              ;SET SINGLE OUPUT PIN
                              BANK0
                              BSF PORTB,1

                              ;SET VARIABLE U16 WITH CONSTANT
                              MOVLW   0X20
                              MOVWF SD_WAIT_MS_TIME
                              MOVLW 0X0
                              MOVWF SD_WAIT_MS_TIME_H

                              CALL LABEL_SD_WAIT_MS

                              ;SET SINGLE OUPUT PIN
                              BANK0
                              BCF PORTB,1

                              ;SET VARIABLE U16 WITH CONSTANT
                              MOVLW   0X20
                              MOVWF SD_WAIT_MS_TIME
                              MOVLW 0X0
                              MOVWF SD_WAIT_MS_TIME_H

                              CALL LABEL_SD_WAIT_MS

                GOTO LABEL_1124
              LABEL_1125
              ;END OF FOR/WHILE-LOOP

                ;SET VARIABLE U16 WITH CONSTANT
                MOVLW   0X78
                BANK0
                MOVWF SD_WAIT_MS_TIME
                MOVLW 0X3
                MOVWF SD_WAIT_MS_TIME_H

                CALL LABEL_SD_WAIT_MS

                ;BEGIN OF FOR-LOOP
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   DEVICE_ERROR,W
                MOVWF I
                INCF I,F
              LABEL_1126
                BANK0
                DECF I,F
                BTFSC STATUS,Z 
                GOTO LABEL_1127

                              ;SET SINGLE OUPUT PIN
                              BANK0
                              BSF PORTB,1

                              ;SET VARIABLE U16 WITH CONSTANT
                              MOVLW   0XF4
                              MOVWF SD_WAIT_MS_TIME
                              MOVLW 0X1
                              MOVWF SD_WAIT_MS_TIME_H

                              CALL LABEL_SD_WAIT_MS

                              ;SET SINGLE OUPUT PIN
                              BANK0
                              BCF PORTB,1

                              ;SET VARIABLE U16 WITH CONSTANT
                              MOVLW   0XF4
                              MOVWF SD_WAIT_MS_TIME
                              MOVLW 0X1
                              MOVWF SD_WAIT_MS_TIME_H

                              CALL LABEL_SD_WAIT_MS

                GOTO LABEL_1126
              LABEL_1127
              ;END OF FOR/WHILE-LOOP

                ;SET VARIABLE U16 WITH CONSTANT
                MOVLW   0X93
                BANK0
                MOVWF SD_WAIT_MS_TIME
                MOVLW 0X0
                MOVWF SD_WAIT_MS_TIME_H

                CALL LABEL_SD_WAIT_MS

                CALL LABEL_RESET_UART_RX

  GOTO LABEL_1128
LABEL_1123

LABEL_1128
;END OF IF-STRUCTURE

  GOTO LABEL_0

LABEL_1129

  GOTO LABEL_1129

;***************************************SUBROUTINES***************************************

LABEL_SD_WAIT_MS

  ;BEGIN OF 16-BIT FOR-LOOP
  ;SET VARIABLE U16 WITH VARIABLE U16
  BANK0
  MOVF   SD_WAIT_MS_TIME,W
  MOVWF SD_WAIT_MS_COUNTER
  MOVF SD_WAIT_MS_TIME_H,W
  MOVWF SD_WAIT_MS_COUNTER_H
  INCF SD_WAIT_MS_COUNTER,F
  BTFSC STATUS,Z
  INCF SD_WAIT_MS_COUNTER_H,F
LABEL_1003
  BANK0
  MOVF SD_WAIT_MS_COUNTER,F
  BTFSC STATUS,Z
  DECF SD_WAIT_MS_COUNTER_H,F
  BANK0
  DECF SD_WAIT_MS_COUNTER,F

  MOVF SD_WAIT_MS_COUNTER_H,F
  BTFSS STATUS,Z
  GOTO LABEL_1002
  BANK0
  MOVF SD_WAIT_MS_COUNTER,F
LABEL_1002
  BTFSC STATUS,Z
  GOTO LABEL_1004

                ;WAIT
                BANK0
                MOVLW 0X3
                MOVWF TEMPYY
              LABEL_1005
                MOVLW 0X85
                MOVWF IDX16
              LABEL_1006
                DECFSZ IDX16,F
                GOTO LABEL_1006
                DECFSZ TEMPYY,F
                GOTO LABEL_1005
                NOP
                NOP

  GOTO LABEL_1003
LABEL_1004
;END OF FOR/WHILE-LOOP

  RETURN

LABEL_AQUISITION

  ;WAIT
  BANK0
  MOVLW 0X6
  MOVWF TEMPYY
LABEL_1007
  DECFSZ TEMPYY,F
  GOTO LABEL_1007
  NOP
  NOP

  RETURN

LABEL_BSTART

  ;*******************START BIT SUBROUTINE**************************
  ;           THIS ROUTINE GENERATES A START CONDITION
  ;           (HIGH-TO-LOW TRANSITION OF SDA WHILE SCL
  ;           IS STILL HIGH.
  ;*****************************************************************
      BSF     PORTB,SCL           ; MAKE SURE SCL IS HIGH
      TSUSTA                      ; START CONDITION SETUP TIME DELAY
      NOP                         ; CONFIGURE SDA TO BE AN OUTPUT
      BANK1
      BCF    TRISB,SDA               ; CLEAR TRISB SDA BIT
      BANK0
      BCF     PORTB,SDA           ; PULL SDA LOW TO INITIATE
                                  ; START CONDITION
      THDSTA                      ; START CONDITION HOLD TIME DELAY
      BCF     PORTB,SCL           ; BRING SCL LOW IN PREPARATION
                                  ; FOR DATA TRANSFER
      NOP                         ; CONFIGURE SDA TO BE AN INPUT
      BANK1
      BSF    TRISB,SDA               ; SET TRISB SDA BIT
      BANK0
      NOP
      NOP

  RETURN

LABEL_BSTOP

  ;*******************STOP BIT SUBROUTINE***************************
  ;           THIS ROUTINE GENERATES A STOP CONDITION
  ;           (LOW-TO-HIGH TRANSITION OF SDA WHILE SCL
  ;           IS STILL HIGH.
  ;*****************************************************************
      NOP                         ; CONFIGURE SDA TO BE AN OUTPUT
      BANK1
      BCF    TRISB,SDA               ; CLEAR TRISB SDA BIT
      BANK0
      BCF     PORTB,SDA           ; PULL SDA LOW
      BSF     PORTB,SCL           ; MAKE SURE SCL IS HIGH
      TSUSTO                      ; STOP CONDITION SETUP TIME DELAY
      NOP                         ; CONFIGURE SDA TO BE AN INPUT
      BANK1
      BSF    TRISB,SDA               ; SET TRISB SDA BIT
      BANK0
      NOP
      NOP
                                  ; TO INITIATE STOP CONDITION

  RETURN

LABEL_BITOUT

  ;*******************BIT OUTPUT SUBROUTINE*************************
  ;           THIS ROUTINE OUTPUTS BIT 'DO' IN 'BUFFER' TO
  ;           THE SERIAL EEPROM DEVICE.
  ;*****************************************************************
      BCF     PORTB,SCL           ; MAKE SURE SCL IS LOW
      BTFSS   BUFFER,DO           ; CHECK FOR STATE OF BIT TO XMIT
      GOTO    BITLOW              ; IF BIT IS LOW, PULL SDA LOW
      BSF PORTB,SDA         ; PULL SDA HIGH
      NOP
      NOP
      NOP
  CLOCKOUT                        ; IF BIT IS HIGH, LEAVE SDA HIGH
      BSF     PORTB,SCL           ; BRING SCL HIGH TO BEGIN TRANSFER
      THIGH                       ; CLOCK HIGH TIME DELAY
      BCF     PORTB,SCL           ; BRING SCL LOW AGAIN
      RETLW   0

  BITLOW
      BCF     PORTB,SDA           ; PULL SDA LOW
      GOTO    CLOCKOUT

  ; PICLAB ADDS A DUMMY RETURN HERE

  RETURN

LABEL_BITIN

  ;*******************BIT INPUT SUBROUTINE**************************
  ;           THIS ROUTINE INPUTS A BIT OF DATA FROM THE
  ;           SERIAL EEPROM DEVICE, AND STORES IT IN BIT
  ;           'DO' OF 'BUFFER'.
  ;*****************************************************************
      BCF     PORTB,SCL           ; MAKE SURE SCL IS LOW
      NOP                         ; CONFIGURE SDA TO BE AN INPUT
      BANK1
      BSF    TRISB,SDA               ; SET TRISB SDA BIT
      BANK0
      NOP
      NOP
      BSF     BUFFER,DI           ; ASSUME INPUT BIT IS HIGH
      BSF     PORTB,SCL           ; BRING SCL HIGH TO BEGIN TRANSFER
      TAA                         ; OUTPUT VALID FROM CLOCK DELAY
      BTFSS   PORTB,SDA           ; CHECK FOR STATE OF SDA BIT
      BCF     BUFFER,DI           ; IF SDA IS LOW, SET BIT LOW
      BCF     PORTB,SCL           ; BRING SCL LOW AGAIN
      NOP

  RETURN

LABEL_TX

  ;*******************DATA TRANSMIT SUBROUTINE**********************
  ;           THIS ROUTINE TRANSMITS THE BYTE OF DATA
  ;           STORED IN 'DATAO' TO THE SERIAL EEPROM
  ;           DEVICE. INSTRUCTIONS ARE ALSO IN PLACE
  ;           TO CHECK FOR AN ACK BIT, IF DESIRED.
  ;           JUST REPLACE THE 'GOTO' INSTRUCTION,
  ;           OR CREATE AN 'ACKFAILED' LABEL, TO PROVIDE
  ;           THE FUNCTIONALITY.
  ;*****************************************************************
      BSF     PORTB,SDA           ; PULL SDA HIGH    
      NOP                         ; CONFIGURE SDA TO BE AN OUTPUT
      BANK1
      BCF    TRISB,SDA               ; CLEAR TRISB SDA BIT
      BANK0
      BSF     PORTB,SDA           ; PULL SDA HIGH
      MOVLW   0X8
      MOVWF   BITCOUNT            ; INITIALIZE LOOP COUNTER TO 8
  TXLP
      BSF     BUFFER,DO           ; ASSUME OUTPUT BIT IS HIGH
      BTFSS   DATAO,7             ; CHECK STATE OF NEXT OUTPUT BIT
      BCF     BUFFER,DO           ; IF LOW, SET BUFFER BIT LOW
      CALL    LABEL_BITOUT              ; CALL ROUTINE TO OUTPUT BIT
      RLF     DATAO,F             ; ROTATE DATAO LEFT FOR NEXT BIT
      DECFSZ  BITCOUNT,F          ; DECREMENT COUNTER, CHECK IF DONE
      GOTO    TXLP                ; KEEP LOOPING
      CALL    LABEL_BITIN               ; CALL ROUTINE TO READ ACK BIT
      BTFSC   BUFFER,DI           ; CHECK IF ACK BIT WAS RECEIVED
      GOTO    ACKFAILED           ; THIS EXECUTES IF NO ACK RECEIVED
      NOP
      NOP
      NOP
      NOP
      RETURN
  ACKFAILED
      MOVLW 0X1
      MOVWF I2C_ERROR

  RETURN

LABEL_RX

  ;*******************DATA RECEIVE SUBROUTINE***********************
  ;           THIS ROUTINE READS IN ONE BYTE OF DATA FROM
  ;           THE SERIAL EEPROM DEVICE, AND STORES IT IN
  ;           'DATAI'.  IT THEN RESPONDS WITH EITHER AN
  ;           ACK OR A NO ACK BIT, DEPENDING ON THE VALUE
  ;           OF 'ACKB' IN 'BUFFER'.
  ;*****************************************************************
      CLRF    DATAI               ; CLEAR INPUT BUFFER
      MOVLW   0X8
      MOVWF   BITCOUNT            ; INITIALIZE LOOP COUNTER TO 8
      BCF     STATUS,C            ; MAKE SURE CARRY BIT IS LOW
  RXLP
      RLF     DATAI,F             ; ROTATE DATAI 1 BIT LEFT
      CALL    LABEL_BITIN               ; READ A BIT
      BTFSC   BUFFER,DI
      BSF     DATAI,0             ; SET BIT 0 IF NECESSARY
      DECFSZ  BITCOUNT,F          ; 8 BITS DONE?
      GOTO    RXLP                ; IF NOT, DO ANOTHER
      BSF     BUFFER,DO           ; ASSUME ACK WILL NOT BE SENT
      BTFSC   BUFFER,ACKB         ; CHECK STATE OF ACKB BIT
      BCF     BUFFER,DO           ; IF ACKB = 1, SEND ACK (DO = 0)
      CALL    LABEL_BITOUT              ; SEND BIT

  RETURN

LABEL_RESET_UART_RX

  ;SET VARIABLE U16 WITH CONSTANT
  MOVLW   0XA0
  BANK0
  MOVWF LEGO_HEADER_POINTER
  MOVLW 0X0
  MOVWF LEGO_HEADER_POINTER_H

  ;SET VARIABLE U16 WITH CONSTANT
  MOVLW   0X10
  MOVWF UART_RX_BUFFER_POINTER
  MOVLW 0X1
  MOVWF UART_RX_BUFFER_POINTER_H

  CLRF PACKET_CHECKSUM

  ;SET VARIABLE U16 WITH CONSTANT
  MOVLW   0X70
  MOVWF UART_RX_DATA_LAST_BYTE_ADDR
  MOVLW 0X1
  MOVWF UART_RX_DATA_LAST_BYTE_ADDR_H

  ;SET VARIABLE U8 WITH SFR
  MOVF   RCREG,W
  MOVWF UART_CURRENT

  ;SET VARIABLE U8 WITH SFR
  MOVF   RCREG,W
  MOVWF COMPLEMENT

  ;SET VARIABLE U8 WITH CONSTANT
  MOVLW   0X0
  MOVWF UART_ERROR

  ;CLEAR MAIL ERROR
  BTFSS RCSTA,OERR
  GOTO LABEL_1010
  BCF   RCSTA,CREN
  BSF   RCSTA,CREN
LABEL_1010

  ;SET VARIABLE U8 WITH CONSTANT
  MOVLW   0X0
  BANK0
  MOVWF UART_STATE

  ;START MONITORING INTERRUPTS
  BCF PIR1,RCIF
  BANK1
  BSF PIE1,RCIE
  BSF  INTCON,GIE
  BSF  INTCON,PEIE

  RETURN

LABEL_SET_TO_UART_TX_BUFFER

  ;SET INDIRECT VARIABLE WITH VARIABLE U8
  ;SET U16 POINTER
  BCF STATUS,IRP
  BANK0
  BTFSC UART_TX_BUFFER_POINTER_H,0
  BSF STATUS,IRP
  BANK0
  MOVF UART_TX_BUFFER_POINTER,W
  MOVWF FSR
  MOVF   UART_CURRENT,W
  MOVWF INDF

  INCF UART_TX_BUFFER_POINTER,F
  BTFSC STATUS,Z
  INCF UART_TX_BUFFER_POINTER_H,F

  RETURN

LABEL_SEND_UART_TX

  ;STOP MONITORING INTERRUPTS
  BANK1
  BCF PIE1,RCIE
  BCF INTCON,TMR0IE


  ;SET VARIABLE U8 WITH CONSTANT
  MOVLW   0X2
  BANK0
  MOVWF UART_STATE

  ;SET VARIABLE U16 WITH CONSTANT
  MOVLW   0X90
  MOVWF UART_TX_BUFFER_POINTER
  MOVLW 0X1
  MOVWF UART_TX_BUFFER_POINTER_H

  ;SET VARIABLE U16 WITH CONSTANT
  MOVLW   0XA0
  MOVWF LEGO_HEADER_POINTER
  MOVLW 0X0
  MOVWF LEGO_HEADER_POINTER_H

  ;SET VARIABLE U16 WITH VARIABLE U16
  MOVF   UART_TX_BUFFER_POINTER,W
  MOVWF UART_TX_DATA_LAST_BYTE_ADDR
  MOVF UART_TX_BUFFER_POINTER_H,W
  MOVWF UART_TX_DATA_LAST_BYTE_ADDR_H

  ;OPERATION
  ;SET VARIABLE U16 WITH VARIABLE U16
  MOVF   UART_TX_DATA_LAST_BYTE_ADDR,W
  MOVWF TEMPX16
  MOVF UART_TX_DATA_LAST_BYTE_ADDR_H,W
  MOVWF TEMPX16_H
  ;SET VARIABLE U16 WITH VARIABLE U8
  MOVF   UART_TX_LENGTH,W
  MOVWF TEMPY16
  CLRF TEMPY16_H
  CALL SUMV16
  ;SET VARIABLE U16 WITH VARIABLE U16
  BANK0
  MOVF   TEMPX16,W
  MOVWF UART_TX_DATA_LAST_BYTE_ADDR
  MOVF TEMPX16_H,W
  MOVWF UART_TX_DATA_LAST_BYTE_ADDR_H

  BSF T2CON,2

  ;START MONITORING INTERRUPTS
  BCF PIR1,TXIF
  BANK1
  BSF PIE1,TXIE
  BSF  INTCON,GIE
  BSF  INTCON,PEIE

  RETURN

;**********************************INTERRUPT SERVICE ROUTINE**********************************
  ; PAGE 1
  ORG 0X800

LABEL_ISR
  MOVWF 0X7F
  SWAPF STATUS,W
  BANK0
  MOVWF ISR_STATUS
  MOVF 0X7F,W
  MOVWF ISR_W
  MOVF TEMPPORT8,W
  MOVWF ISR_TEMPPORT8
  MOVF FSR,W
  MOBWF ISR_FSR
  BANK1
  BTFSS PIE1,TXIE
  GOTO LABEL_1130
  BANK0
  BTFSS PIR1,TXIF
  GOTO LABEL_1130
  CALL LABEL_EVENT0
  BANK0
  BCF PIR1,TXIF
LABEL_1130
  BANK1
  BTFSS PIE1,RCIE
  GOTO LABEL_1131
  BANK0
  BTFSS PIR1,RCIF
  GOTO LABEL_1131
  CALL LABEL_EVENT1
  BANK0
  BCF PIR1,RCIF
LABEL_1131
  BANK1
  BTFSS INTCON,TMR0IE
  GOTO LABEL_1132
  BANK0
  BTFSS INTCON,TMR0IF
  GOTO LABEL_1132
  CALL LABEL_EVENT2
  BANK0
  BCF INTCON,TMR0IF
LABEL_1132
  BANK0
  MOVF   ISR_TEMPPORT8,W
  MOVWF  TEMPPORT8
  MOVF ISR_W,W
  MOVWF 0X7F
  SWAPF   ISR_STATUS,W
  MOVWF  STATUS
  SWAPF   0X7F,F
  SWAPF   0X7F,W
  ; SELECT PAGE 0
  BCF PCLATH, 3
  RETFIE

;**************************************EVENT-ROUTINES**************************************

LABEL_EVENT2

  ;BEGIN OF IF-STRUCTURE
  ;COMPARE-OPERATION
  ;SET VARIABLE U8 WITH VARIABLE U8
  BANK0
  MOVF   UART_STATE,W
  MOVWF ISR_TEMPX8
  ;SET VARIABLE U8 WITH CONSTANT
  MOVLW   0X1
  MOVWF ISR_TEMPY8
  CALL ISR_EQU8U8
  BANK0
  MOVWF ISR_RESULT8
  BTFSC ISR_RESULT8,0
  GOTO LABEL_1008

  GOTO LABEL_1009
LABEL_1008

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X5
                BANK0
                MOVWF UART_ERROR

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X4
                MOVWF UART_STATE

LABEL_1009
;END OF IF-STRUCTURE

  ;STOP MONITORING INTERRUPTS
  BANK1
  BCF INTCON,TMR0IE


  RETURN

LABEL_EVENT1

  ;SET VARIABLE U8 WITH SFR
  BANK0
  MOVF   RCREG,W
  MOVWF UART_CURRENT

  ;BEGIN OF IF-STRUCTURE (DEPENDING ON BIT/PIN)
  BTFSS RCSTA,1
  GOTO LABEL_1011

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X1
                BANK0
                MOVWF UART_ERROR

                ;CLEAR MAIL ERROR
                BTFSS RCSTA,OERR
                GOTO LABEL_1013
                BCF   RCSTA,CREN
                BSF   RCSTA,CREN
              LABEL_1013

  GOTO LABEL_1035
LABEL_1011

                ;BEGIN OF IF-STRUCTURE
                ;COMPARE-OPERATION
                ;SET VARIABLE U8 WITH VARIABLE U8
                BANK0
                MOVF   UART_STATE,W
                MOVWF ISR_TEMPX8
                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X1
                MOVWF ISR_TEMPY8
                CALL ISR_GRU8U8
                BANK0
                MOVWF ISR_RESULT8
                BTFSC ISR_RESULT8,0
                GOTO LABEL_1012

                GOTO LABEL_1034
              LABEL_1012

                              ;CLEAR TIMER
                              BANK0
                              CLRF TMR0

                              ;START MONITORING INTERRUPTS
                              BCF INTCON,TMR0IF
                              BANK1
                              BSF INTCON,TMR0IE
                              

                              ;SET VARIABLE U8 WITH CONSTANT
                              MOVLW   0X1
                              BANK0
                              MOVWF UART_STATE

                              ;BEGIN OF IF-STRUCTURE
                              ;COMPARE-OPERATION
                              ;SET VARIABLE U16 WITH VARIABLE U16
                              MOVF   LEGO_HEADER_POINTER,W
                              MOVWF ISR_TEMPX16
                              MOVF LEGO_HEADER_POINTER_H,W
                              MOVWF ISR_TEMPX16_H
                              ;SET VARIABLE U16 WITH CONSTANT
                              MOVLW   0XA2
                              MOVWF ISR_TEMPY16
                              MOVLW 0X0
                              MOVWF ISR_TEMPY16_H
                              CALL ISR_GRU16U16
                              BANK0
                              MOVWF ISR_RESULT8
                              BTFSC ISR_RESULT8,0
                              GOTO LABEL_1014

                                            ;BEGIN OF IF-STRUCTURE (DEPENDING ON BIT/PIN)
                                            BANK0
                                            BTFSS LEGO_HEADER_POINTER,0
                                            GOTO LABEL_1016

                                                          ;BEGIN OF IF-STRUCTURE
                                                          ;COMPARE-OPERATION
                                                          ;SET VARIABLE U16 WITH VARIABLE U16
                                                          BANK0
                                                          MOVF   UART_RX_BUFFER_POINTER,W
                                                          MOVWF ISR_TEMPX16
                                                          MOVF UART_RX_BUFFER_POINTER_H,W
                                                          MOVWF ISR_TEMPX16_H
                                                          ;SET VARIABLE U16 WITH CONSTANT
                                                          MOVLW   0X10
                                                          MOVWF ISR_TEMPY16
                                                          MOVLW 0X1
                                                          MOVWF ISR_TEMPY16_H
                                                          CALL ISR_EQU16U16
                                                          BANK0
                                                          MOVWF ISR_RESULT8
                                                          BTFSC ISR_RESULT8,0
                                                          GOTO LABEL_1019

                                                          GOTO LABEL_1027
                                                        LABEL_1019

                                                                        ;SET VARIABLE U8 WITH VARIABLE U8
                                                                        BANK0
                                                                        MOVF   UART_CURRENT,W
                                                                        MOVWF TMP_OPCODE

                                                                        ;OPERATION
                                                                        ;SET VARIABLE U8 WITH VARIABLE U8
                                                                        MOVF   TMP_OPCODE,W
                                                                        MOVWF ISR_TEMPX8
                                                                        ;SET VARIABLE U8 WITH CONSTANT
                                                                        MOVLW   0XF7
                                                                        MOVWF ISR_TEMPY8
                                                                        CALL ISR_ANDV8
                                                                        ;SET VARIABLE U8 WITH VARIABLE U8
                                                                        BANK0
                                                                        MOVF   ISR_TEMPX8,W
                                                                        MOVWF TMP_OPCODE

                                                                        ;BEGIN OF IF-STRUCTURE
                                                                        ;COMPARE-OPERATION
                                                                        ;SET VARIABLE U8 WITH VARIABLE U8
                                                                        MOVF   TMP_OPCODE,W
                                                                        MOVWF ISR_TEMPX8
                                                                        ;SET VARIABLE U8 WITH CONSTANT
                                                                        MOVLW   0X45
                                                                        MOVWF ISR_TEMPY8
                                                                        CALL ISR_EQU8U8
                                                                        BANK0
                                                                        MOVWF ISR_RESULT8
                                                                        BTFSC ISR_RESULT8,0
                                                                        GOTO LABEL_1023

                                                                                      ;OPERATION
                                                                                      ;SET VARIABLE U8 WITH VARIABLE U8
                                                                                      BANK0
                                                                                      MOVF   TMP_OPCODE,W
                                                                                      MOVWF ISR_TEMPX8
                                                                                      ;SET VARIABLE U8 WITH CONSTANT
                                                                                      MOVLW   0X7
                                                                                      MOVWF ISR_TEMPY8
                                                                                      CALL ISR_ANDV8
                                                                                      ;SET VARIABLE U8 WITH VARIABLE U8
                                                                                      BANK0
                                                                                      MOVF   ISR_TEMPX8,W
                                                                                      MOVWF TMP_OPCODE

                                                                                      ;BEGIN OF IF-STRUCTURE
                                                                                      ;COMPARE-OPERATION
                                                                                      ;SET VARIABLE U8 WITH VARIABLE U8
                                                                                      MOVF   TMP_OPCODE,W
                                                                                      MOVWF ISR_TEMPX8
                                                                                      ;SET VARIABLE U8 WITH CONSTANT
                                                                                      MOVLW   0X5
                                                                                      MOVWF ISR_TEMPY8
                                                                                      CALL ISR_GRU8U8
                                                                                      BANK0
                                                                                      MOVWF ISR_RESULT8
                                                                                      BTFSC ISR_RESULT8,0
                                                                                      GOTO LABEL_1024

                                                                                                    ;OPERATION
                                                                                                    ;SET VARIABLE U8 WITH VARIABLE U8
                                                                                                    BANK0
                                                                                                    MOVF   TMP_OPCODE,W
                                                                                                    MOVWF ISR_TEMPX8
                                                                                                    ;SET VARIABLE U8 WITH CONSTANT
                                                                                                    MOVLW   0X6
                                                                                                    MOVWF ISR_TEMPY8
                                                                                                    CALL ISR_SUBV8
                                                                                                    ;SET VARIABLE U8 WITH VARIABLE U8
                                                                                                    BANK0
                                                                                                    MOVF   ISR_TEMPX8,W
                                                                                                    MOVWF TMP_OPCODE

                                                                                      GOTO LABEL_1025
                                                                                    LABEL_1024

                                                                                    LABEL_1025
                                                                                    ;END OF IF-STRUCTURE

                                                                                      ;OPERATION
                                                                                      ;SET VARIABLE U8 WITH VARIABLE U8
                                                                                      BANK0
                                                                                      MOVF   TMP_OPCODE,W
                                                                                      MOVWF ISR_TEMPX8
                                                                                      ;SET VARIABLE U8 WITH CONSTANT
                                                                                      MOVLW   0X2
                                                                                      MOVWF ISR_TEMPY8
                                                                                      CALL ISR_SUMV8
                                                                                      ;SET VARIABLE U8 WITH VARIABLE U8
                                                                                      BANK0
                                                                                      MOVF   ISR_TEMPX8,W
                                                                                      MOVWF TMP_OPCODE

                                                                                      ;SET VARIABLE U16 WITH CONSTANT
                                                                                      MOVLW   0X10
                                                                                      MOVWF UART_RX_DATA_LAST_BYTE_ADDR
                                                                                      MOVLW 0X1
                                                                                      MOVWF UART_RX_DATA_LAST_BYTE_ADDR_H

                                                                                      ;OPERATION
                                                                                      ;SET VARIABLE U16 WITH VARIABLE U16
                                                                                      MOVF   UART_RX_DATA_LAST_BYTE_ADDR,W
                                                                                      MOVWF ISR_TEMPX16
                                                                                      MOVF UART_RX_DATA_LAST_BYTE_ADDR_H,W
                                                                                      MOVWF ISR_TEMPX16_H
                                                                                      ;SET VARIABLE U16 WITH VARIABLE U8
                                                                                      MOVF   TMP_OPCODE,W
                                                                                      MOVWF ISR_TEMPY16
                                                                                      CLRF ISR_TEMPY16_H
                                                                                      CALL ISR_SUMV16
                                                                                      ;SET VARIABLE U16 WITH VARIABLE U16
                                                                                      BANK0
                                                                                      MOVF   ISR_TEMPX16,W
                                                                                      MOVWF UART_RX_DATA_LAST_BYTE_ADDR
                                                                                      MOVF ISR_TEMPX16_H,W
                                                                                      MOVWF UART_RX_DATA_LAST_BYTE_ADDR_H

                                                                        GOTO LABEL_1026
                                                                      LABEL_1023

                                                                      LABEL_1026
                                                                      ;END OF IF-STRUCTURE

                                                        LABEL_1027
                                                        ;END OF IF-STRUCTURE

                                                          ;OPERATION
                                                          ;SET VARIABLE U8 WITH VARIABLE U8
                                                          BANK0
                                                          MOVF   UART_CURRENT,W
                                                          MOVWF ISR_TEMPY8
                                                          CALL ISR_NOTV8
                                                          ;SET VARIABLE U8 WITH VARIABLE U8
                                                          BANK0
                                                          MOVF   ISR_TEMPY8,W
                                                          MOVWF COMPLEMENT

                                                          ;SET INDIRECT VARIABLE WITH VARIABLE U8
                                                          ;SET U16 POINTER
                                                          BCF STATUS,IRP
                                                          BTFSC UART_RX_BUFFER_POINTER_H,0
                                                          BSF STATUS,IRP
                                                          BANK0
                                                          MOVF UART_RX_BUFFER_POINTER,W
                                                          MOVWF FSR
                                                          MOVF   UART_CURRENT,W
                                                          MOVWF INDF

                                                          INCF UART_RX_BUFFER_POINTER,F
                                                          BTFSC STATUS,Z
                                                          INCF UART_RX_BUFFER_POINTER_H,F

                                                          ;BEGIN OF IF-STRUCTURE
                                                          ;COMPARE-OPERATION
                                                          ;SET VARIABLE U16 WITH VARIABLE U16
                                                          BANK0
                                                          MOVF   UART_RX_BUFFER_POINTER,W
                                                          MOVWF ISR_TEMPX16
                                                          MOVF UART_RX_BUFFER_POINTER_H,W
                                                          MOVWF ISR_TEMPX16_H
                                                          ;SET VARIABLE U16 WITH VARIABLE U16
                                                          MOVF   UART_RX_DATA_LAST_BYTE_ADDR,W
                                                          MOVWF ISR_TEMPY16
                                                          MOVF UART_RX_DATA_LAST_BYTE_ADDR_H,W
                                                          MOVWF ISR_TEMPY16_H
                                                          CALL ISR_EQU16U16
                                                          BANK0
                                                          MOVWF ISR_RESULT8
                                                          BTFSC ISR_RESULT8,0
                                                          GOTO LABEL_1028

                                                                        ;OPERATION
                                                                        ;SET VARIABLE U8 WITH VARIABLE U8
                                                                        BANK0
                                                                        MOVF   PACKET_CHECKSUM,W
                                                                        MOVWF ISR_TEMPX8
                                                                        ;SET VARIABLE U8 WITH VARIABLE U8
                                                                        MOVF   UART_CURRENT,W
                                                                        MOVWF ISR_TEMPY8
                                                                        CALL ISR_SUMV8
                                                                        ;SET VARIABLE U8 WITH VARIABLE U8
                                                                        BANK0
                                                                        MOVF   ISR_TEMPX8,W
                                                                        MOVWF PACKET_CHECKSUM

                                                          GOTO LABEL_1031
                                                        LABEL_1028

                                                                        ;BEGIN OF IF-STRUCTURE
                                                                        ;COMPARE-OPERATION
                                                                        ;SET VARIABLE U8 WITH VARIABLE U8
                                                                        BANK0
                                                                        MOVF   PACKET_CHECKSUM,W
                                                                        MOVWF ISR_TEMPX8
                                                                        ;SET VARIABLE U8 WITH VARIABLE U8
                                                                        MOVF   UART_CURRENT,W
                                                                        MOVWF ISR_TEMPY8
                                                                        CALL ISR_EQU8U8
                                                                        BANK0
                                                                        MOVWF ISR_RESULT8
                                                                        BTFSC ISR_RESULT8,0
                                                                        GOTO LABEL_1029

                                                                                      ;SET VARIABLE U8 WITH CONSTANT
                                                                                      MOVLW   0X4
                                                                                      BANK0
                                                                                      MOVWF UART_ERROR

                                                                        GOTO LABEL_1030
                                                                      LABEL_1029

                                                                      LABEL_1030
                                                                      ;END OF IF-STRUCTURE

                                                        LABEL_1031
                                                        ;END OF IF-STRUCTURE

                                            GOTO LABEL_1032
                                          LABEL_1016

                                                          ;BEGIN OF IF-STRUCTURE
                                                          ;COMPARE-OPERATION
                                                          ;SET VARIABLE U8 WITH VARIABLE U8
                                                          BANK0
                                                          MOVF   COMPLEMENT,W
                                                          MOVWF ISR_TEMPX8
                                                          ;SET VARIABLE U8 WITH VARIABLE U8
                                                          MOVF   UART_CURRENT,W
                                                          MOVWF ISR_TEMPY8
                                                          CALL ISR_EQU8U8
                                                          BANK0
                                                          MOVWF ISR_RESULT8
                                                          BTFSC ISR_RESULT8,0
                                                          GOTO LABEL_1017

                                                                        ;SET VARIABLE U8 WITH CONSTANT
                                                                        MOVLW   0X3
                                                                        BANK0
                                                                        MOVWF UART_ERROR

                                                          GOTO LABEL_1022
                                                        LABEL_1017

                                                                        ;BEGIN OF IF-STRUCTURE
                                                                        ;COMPARE-OPERATION
                                                                        ;SET VARIABLE U16 WITH VARIABLE U16
                                                                        BANK0
                                                                        MOVF   UART_RX_BUFFER_POINTER,W
                                                                        MOVWF ISR_TEMPX16
                                                                        MOVF UART_RX_BUFFER_POINTER_H,W
                                                                        MOVWF ISR_TEMPX16_H
                                                                        ;SET VARIABLE U16 WITH VARIABLE U16
                                                                        MOVF   UART_RX_DATA_LAST_BYTE_ADDR,W
                                                                        MOVWF ISR_TEMPY16
                                                                        MOVF UART_RX_DATA_LAST_BYTE_ADDR_H,W
                                                                        MOVWF ISR_TEMPY16_H
                                                                        CALL ISR_EQU16U16
                                                                        BANK0
                                                                        MOVWF ISR_RESULT8
                                                                        BTFSC ISR_RESULT8,0
                                                                        GOTO LABEL_1020

                                                                        GOTO LABEL_1021
                                                                      LABEL_1020

                                                                                      ;STOP MONITORING INTERRUPTS
                                                                                      BANK1
                                                                                      BCF PIE1,RCIE
                                                                                      BCF INTCON,TMR0IE
                                                                                      

                                                                                      ;SET VARIABLE U8 WITH CONSTANT
                                                                                      MOVLW   0X3
                                                                                      BANK0
                                                                                      MOVWF UART_STATE

                                                                      LABEL_1021
                                                                      ;END OF IF-STRUCTURE

                                                        LABEL_1022
                                                        ;END OF IF-STRUCTURE

                                          LABEL_1032
                                          ;END OF IF-STRUCTURE

                              GOTO LABEL_1033
                            LABEL_1014

                                            ;BEGIN OF IF-STRUCTURE
                                            ;COMPARE-OPERATION
                                            ;SET VARIABLE U8 WITH VARIABLE U8
                                            BANK0
                                            MOVF   UART_CURRENT,W
                                            MOVWF ISR_TEMPX8
                                            ;SET VARIABLE U8 WITH INDIRECT VARIABLE
                                            ;SET U16 POINTER
                                            BCF STATUS,IRP
                                            BTFSC LEGO_HEADER_POINTER_H,0
                                            BSF STATUS,IRP
                                            BANK0
                                            MOVF LEGO_HEADER_POINTER,W
                                            MOVWF FSR
                                            MOVF   INDF,W
                                            MOVWF ISR_TEMPY8
                                            CALL ISR_EQU8U8
                                            BANK0
                                            MOVWF ISR_RESULT8
                                            BTFSC ISR_RESULT8,0
                                            GOTO LABEL_1015

                                                          ;SET VARIABLE U8 WITH CONSTANT
                                                          MOVLW   0X2
                                                          BANK0
                                                          MOVWF UART_ERROR

                                            GOTO LABEL_1018
                                          LABEL_1015

                                          LABEL_1018
                                          ;END OF IF-STRUCTURE

                            LABEL_1033
                            ;END OF IF-STRUCTURE

                              BANK0
                              INCF LEGO_HEADER_POINTER,F
                              BTFSC STATUS,Z
                              INCF LEGO_HEADER_POINTER_H,F

              LABEL_1034
              ;END OF IF-STRUCTURE

LABEL_1035
;END OF IF-STRUCTURE

  ;BEGIN OF IF-STRUCTURE
  ;COMPARE-OPERATION
  ;SET VARIABLE U8 WITH VARIABLE U8
  BANK0
  MOVF   UART_ERROR,W
  MOVWF ISR_TEMPX8
  ;SET VARIABLE U8 WITH CONSTANT
  MOVLW   0X0
  MOVWF ISR_TEMPY8
  CALL ISR_EQU8U8
  BANK0
  MOVWF ISR_RESULT8
  BTFSC ISR_RESULT8,0
  GOTO LABEL_1036

                ;STOP MONITORING INTERRUPTS
                BANK1
                BCF PIE1,RCIE
                BCF INTCON,TMR0IE
                

                ;SET VARIABLE U8 WITH CONSTANT
                MOVLW   0X4
                BANK0
                MOVWF UART_STATE

  GOTO LABEL_1037
LABEL_1036

LABEL_1037
;END OF IF-STRUCTURE

  RETURN

LABEL_EVENT0

  ;BEGIN OF IF-STRUCTURE
  ;COMPARE-OPERATION
  ;SET VARIABLE U16 WITH VARIABLE U16
  BANK0
  MOVF   LEGO_HEADER_POINTER,W
  MOVWF ISR_TEMPX16
  MOVF LEGO_HEADER_POINTER_H,W
  MOVWF ISR_TEMPX16_H
  ;SET VARIABLE U16 WITH CONSTANT
  MOVLW   0XA2
  MOVWF ISR_TEMPY16
  MOVLW 0X0
  MOVWF ISR_TEMPY16_H
  CALL ISR_GRU16U16
  BANK0
  MOVWF ISR_RESULT8
  BTFSC ISR_RESULT8,0
  GOTO LABEL_1038

                ;BEGIN OF IF-STRUCTURE (DEPENDING ON BIT/PIN)
                BANK0
                BTFSS LEGO_HEADER_POINTER,0
                GOTO LABEL_1039

                              ;SET VARIABLE U8 WITH INDIRECT VARIABLE
                              ;SET U16 POINTER
                              BCF STATUS,IRP
                              BANK0
                              BTFSC UART_TX_BUFFER_POINTER_H,0
                              BSF STATUS,IRP
                              BANK0
                              MOVF UART_TX_BUFFER_POINTER,W
                              MOVWF FSR
                              MOVF   INDF,W
                              MOVWF UART_CURRENT

                              ;OPERATION
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              MOVF   UART_CURRENT,W
                              MOVWF ISR_TEMPY8
                              CALL ISR_NOTV8
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              BANK0
                              MOVF   ISR_TEMPY8,W
                              MOVWF COMPLEMENT

                GOTO LABEL_1042
              LABEL_1039

                              ;SET VARIABLE U8 WITH VARIABLE U8
                              BANK0
                              MOVF   COMPLEMENT,W
                              MOVWF UART_CURRENT

                              INCF UART_TX_BUFFER_POINTER,F
                              BTFSC STATUS,Z
                              INCF UART_TX_BUFFER_POINTER_H,F

                              ;BEGIN OF IF-STRUCTURE
                              ;COMPARE-OPERATION
                              ;SET VARIABLE U16 WITH VARIABLE U16
                              BANK0
                              MOVF   UART_TX_BUFFER_POINTER,W
                              MOVWF ISR_TEMPX16
                              MOVF UART_TX_BUFFER_POINTER_H,W
                              MOVWF ISR_TEMPX16_H
                              ;SET VARIABLE U16 WITH VARIABLE U16
                              MOVF   UART_TX_DATA_LAST_BYTE_ADDR,W
                              MOVWF ISR_TEMPY16
                              MOVF UART_TX_DATA_LAST_BYTE_ADDR_H,W
                              MOVWF ISR_TEMPY16_H
                              CALL ISR_GRU16U16
                              BANK0
                              MOVWF ISR_RESULT8
                              BTFSC ISR_RESULT8,0
                              GOTO LABEL_1040

                                            ;STOP MONITORING INTERRUPTS
                                            BANK1
                                            BCF PIE1,TXIE
                                            

                                            BANK0
                                            BCF T2CON,2

                                            ;SET VARIABLE U8 WITH CONSTANT
                                            MOVLW   0X0
                                            MOVWF UART_STATE

                              GOTO LABEL_1041
                            LABEL_1040

                            LABEL_1041
                            ;END OF IF-STRUCTURE

              LABEL_1042
              ;END OF IF-STRUCTURE

  GOTO LABEL_1043
LABEL_1038

                ;SET VARIABLE U8 WITH INDIRECT VARIABLE
                ;SET U16 POINTER
                BCF STATUS,IRP
                BANK0
                BTFSC LEGO_HEADER_POINTER_H,0
                BSF STATUS,IRP
                BANK0
                MOVF LEGO_HEADER_POINTER,W
                MOVWF FSR
                MOVF   INDF,W
                MOVWF UART_CURRENT

LABEL_1043
;END OF IF-STRUCTURE

  BANK0
  INCF LEGO_HEADER_POINTER,F
  BTFSC STATUS,Z
  INCF LEGO_HEADER_POINTER_H,F

  ;SET VARIABLE U8 WITH VARIABLE U8
  BANK0
  MOVF   UART_CURRENT,W
  MOVWF PA_TEMP

  CLRF PARITY

  ;BEGIN OF FOR-LOOP
  ;SET VARIABLE U8 WITH CONSTANT
  MOVLW   0X8
  MOVWF PA_INDEX
  INCF PA_INDEX,F
LABEL_1044
  BANK0
  DECF PA_INDEX,F
  BTFSC STATUS,Z 
  GOTO LABEL_1045

                ;BEGIN OF IF-STRUCTURE (DEPENDING ON BIT/PIN)
                BANK0
                BTFSS PA_TEMP,0
                GOTO LABEL_1046

                GOTO LABEL_1047
              LABEL_1046

                              ;OPERATION
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              BANK0
                              MOVF   PARITY,W
                              MOVWF ISR_TEMPY8
                              CALL ISR_NOTV8
                              ;SET VARIABLE U8 WITH VARIABLE U8
                              BANK0
                              MOVF   ISR_TEMPY8,W
                              MOVWF PARITY

              LABEL_1047
              ;END OF IF-STRUCTURE

                BCF STATUS,C
                BANK0
                RRF PA_TEMP,F

  GOTO LABEL_1044
LABEL_1045
;END OF FOR/WHILE-LOOP

  ;BEGIN OF IF-STRUCTURE
  ;COMPARE-OPERATION
  ;SET VARIABLE U8 WITH VARIABLE U8
  BANK0
  MOVF   PARITY,W
  MOVWF ISR_TEMPX8
  ;SET VARIABLE U8 WITH CONSTANT
  MOVLW   0X0
  MOVWF ISR_TEMPY8
  CALL ISR_EQU8U8
  BANK0
  MOVWF ISR_RESULT8
  BTFSC ISR_RESULT8,0
  GOTO LABEL_1048

                BANK1
                BCF TXSTA,TX9D

  GOTO LABEL_1049
LABEL_1048

                BANK1
                BSF TXSTA,TX9D

LABEL_1049
;END OF IF-STRUCTURE

  ;SEND MAIL
  BANK0
LABEL_1050
  BTFSS PIR1,TXIF
  GOTO LABEL_1050
  ;SET SFR WITH VARIABLE U8
  BANK0
  MOVF   UART_CURRENT,W
  MOVWF TXREG

  RETURN

ISR_EQU8U8
  MOVF     ISR_TEMPX8,W
  SUBWF  ISR_TEMPY8
  BTFSS    STATUS,Z   ;SKIP IF ZERO ->IDENTICAL
  RETLW  0
  RETLW  1

ISR_GRU8U8
  MOVF     ISR_TEMPX8,W
  SUBWF  ISR_TEMPY8
  BTFSS    STATUS,C
  RETLW  0
  RETLW  1

ISR_GRU16U16
  MOVF   ISR_TEMPX16,W
  SUBWF ISR_TEMPY16
  MOVF  ISR_TEMPX16_H,W
  BTFSS  STATUS,C
  INCFSZ  ISR_TEMPX16_H,W
  SUBWF  ISR_TEMPY16_H
  BTFSS  STATUS,C
  RETLW 0
  RETLW 1

ISR_EQU16U16
  MOVF   ISR_TEMPX16,W
  SUBWF  ISR_TEMPY16
  BTFSS  STATUS,Z
  RETLW 0
  MOVF  ISR_TEMPX16_H,W
  SUBWF ISR_TEMPY16_H
  BTFSS  STATUS,Z
  RETLW 0
  RETLW 1

ISR_ANDV8
  MOVF  ISR_TEMPY8,W
  ANDWF ISR_TEMPX8
  RETURN

ISR_SUBV8
  MOVF     ISR_TEMPY8,W
  SUBWF  ISR_TEMPX8
  RETURN

ISR_SUMV8
  MOVF     ISR_TEMPY8,W
  ADDWF  ISR_TEMPX8
  RETURN

ISR_SUMV16
  MOVF      ISR_TEMPY16,W
  ADDWF  ISR_TEMPX16
  BTFSC  STATUS,C
  INCF    ISR_TEMPX16_H
  MOVF     ISR_TEMPY16_H,W
  ADDWF  ISR_TEMPX16_H
  RETURN

ISR_NOTV8
  COMF ISR_TEMPY8,F
  RETURN

  ;пп

;***************************************Data EEPROM***************************************

                ORG 0X2100
                DATA 0X0
                DATA 0X0

  END