        radix dec
global__variables__bank0 equ 7
global__variables__bank1 equ 48
global__bit__variables__bank0 equ 28
global__bit__variables__bank1 equ 48
indf___register equ 0
pcl___register equ 2
c___byte equ 3
c___bit equ 0
z___byte equ 3
z___bit equ 2
        ; On 12-bit PIC's, RP0 is actually bit 5 in FSR (=4)
rp0___byte equ 4
rp0___bit equ 5
        ; On 12-bit PIC's, RP1 is actually bit 6 in FSR (=4)
rp1___byte equ 4
rp1___bit equ 6
        ; On 12-bit PIC's, PA0 is actually bit 5 in STATUS (=3)
pa0___byte equ 3
pa0___bit equ 5
fsr___register equ 4
        org 0
start:
        ; Use oscillator calibration value already in register W
        movwf 5
        ; Initialize TRIS registers
        movlw 223
        tris 6
        ; Switch from code bank 0 to code bank 1 before possible transfer (goto)
        bsf pa0___byte,pa0___bit
        goto main
        ; comment #############################################################################
        ; comment {}
        ; comment {Copyright < c > 2000 - 2001 by Wayne C . Gramlich & William T . Benson .}
        ; comment {All rights reserved .}
        ; comment {}
        ; comment {Permission to use , copy , modify , distribute , and sell this software}
        ; comment {for any purpose is hereby granted without fee provided that the above}
        ; comment {copyright notice and this permission are retained . The author makes}
        ; comment {no representations about the suitability of this software for any purpose .}
        ; comment {It is provided { as is } without express or implied warranty .}
        ; comment {}
        ; comment {This is the code that implements the LED4 RoboBrick . Basically}
        ; comment {it just waits for commands that come in at 2400 baud and responds}
        ; comment {to them . See}
        ; comment {}
        ; comment {http : / / web . gramlich . net / projects / robobricks / thresh4 / index . html}
        ; comment {}
        ; comment {for more details .}
        ; comment {}
        ; comment #############################################################################
        ;   processor pic12c509 cp = off wdte = on mclre = off fosc = intrc  
        ; 14=0xe 4095=0xfff
        __config 14
configuration___address equ 4095
        ; comment {define processor constants}
        ;   constant clock_rate 4000000  
clock_rate equ 4000000
        ;   constant clocks_per_instruction 4  
clocks_per_instruction equ 4
        ;   constant instruction_rate clock_rate / clocks_per_instruction  
instruction_rate equ 1000000
        ; comment {define serial communication control constants}
        ;   constant baud_rate 2400  
baud_rate equ 2400
        ;   constant instructions_per_bit instruction_rate / baud_rate  
instructions_per_bit equ 416
        ;   constant delays_per_bit 3  
delays_per_bit equ 3
        ;   constant instructions_per_delay instructions_per_bit / delays_per_bit  
instructions_per_delay equ 138
        ; comment {For the 509 , there are 4 - bits of OSCCAL , for the 509 A , 6 - bits :}
osccal equ 5
        ;   constant osccal_unit 0x10  
osccal_unit equ 16
        ; comment {Define port bit assignments :}
porta equ 6
in0__byte equ 6
in0__bit equ 0
in1__byte equ 6
in1__bit equ 1
in2__byte equ 6
in2__bit equ 2
in3__byte equ 6
in3__bit equ 3
serial_in__byte equ 6
serial_in__bit equ 4
serial_out__byte equ 6
serial_out__bit equ 5
        ; string_constants Start
        ; Switch from code bank 1 to code bank 0 before possible transfer (label)
        bcf pa0___byte,pa0___bit
string___fetch:
        movwf pcl___register
        ;   id = 1 , 0 , 19 , 0 , 0 , 0 , 0 , 0 , 0r'16' , 11 , 0s'Threshold4A' , 15 , 0s'Gramlich&Benson'  
id___string equ 0
id:
        addwf pcl___register,f
        ; Length = 52
        retlw 52
        ; 1
        retlw 1
        ; 0
        retlw 0
        ; 19
        retlw 19
        ; 0
        retlw 0
        ; 0
        retlw 0
        ; 0
        retlw 0
        ; 0
        retlw 0
        ; 0
        retlw 0
        ; 0r'16'
        retlw 109 ; random number
        retlw 231 ; random number
        retlw 168 ; random number
        retlw 250 ; random number
        retlw 241 ; random number
        retlw 47 ; random number
        retlw 190 ; random number
        retlw 108 ; random number
        retlw 166 ; random number
        retlw 66 ; random number
        retlw 18 ; random number
        retlw 17 ; random number
        retlw 226 ; random number
        retlw 111 ; random number
        retlw 29 ; random number
        retlw 112 ; random number
        ; 11
        retlw 11
        ; `Threshold4A'
        retlw 84
        retlw 104
        retlw 114
        retlw 101
        retlw 115
        retlw 104
        retlw 111
        retlw 108
        retlw 100
        retlw 52
        retlw 65
        ; 15
        retlw 15
        ; `Gramlich&Benson'
        retlw 71
        retlw 114
        retlw 97
        retlw 109
        retlw 108
        retlw 105
        retlw 99
        retlw 104
        retlw 38
        retlw 66
        retlw 101
        retlw 110
        retlw 115
        retlw 111
        retlw 110
        ; string__constants End
        ; comment {Globals :}
complement equ global__variables__bank0+0
receiving equ global__bit__variables__bank0+0
receiving__byte equ global__bit__variables__bank0+0
receiving__bit equ 0
falling equ global__variables__bank0+1
high equ global__variables__bank0+2
low equ global__variables__bank0+3
raising equ global__variables__bank0+4
interrupt_enable equ global__bit__variables__bank0+0
interrupt_enable__byte equ global__bit__variables__bank0+0
interrupt_enable__bit equ 1
interrupt_pending equ global__bit__variables__bank0+0
interrupt_pending__byte equ global__bit__variables__bank0+0
interrupt_pending__bit equ 2
        ; comment {For now put all the smaller routines first so that they can live}
        ; comment {within the first 256 bytes of main memory . The PIC12C5xx chips}
        ; comment {can only call routines that are within the first 256 bytes < i . e .}
        ; comment {the first half > of the code page .}

        ; procedure get_byte start
get_byte:
        ; Procedure must be called with PCLATH set to code bank 0
get_byte__variables__base equ global__variables__bank0+5
get_byte__bytes__base equ get_byte__variables__base+0
get_byte__bits__base equ get_byte__variables__base+3
get_byte__total__bytes equ 4
        ;   arguments_none  
get_byte__0return__byte equ get_byte__bytes__base+0
        ; Wait for a character and return it .
        ; The get_byte < > procedure only waits for 9 - 2 / 3 bits . That
        ; way the next call to get_byte < > will sychronize on the start
        ; bit instead of possibly starting a little later .
get_byte__count equ get_byte__bytes__base+1
get_byte__char equ get_byte__bytes__base+2
        ; Wait for start bit :
        ;   receiving := 1  
        bsf receiving__byte,receiving__bit
        ; `while serial_in ...' start
get_byte__83while__continue:
        ; expression=`serial_in' exp_delay=0 true_delay=1  false_delay=2 true_size=2 false_size=1
        btfss serial_in__byte,serial_in__bit
        goto get_byte__83while__break
        ;   call delay {{ }}  
        call delay
        goto get_byte__83while__continue
        ; if exp=`serial_in' false goto
        ; Other expression=`serial_in' delay=-1
get_byte__83while__break:
        ; `while serial_in ...' end
        ; Clear any interrupt being sent :
        ;   serial_out := 1  
        bsf serial_out__byte,serial_out__bit
        ; Skip over start bit :
        ;   call delay {{ }}  
        call delay
        ;   call delay {{ }}  
        call delay
        ;   call delay {{ }}  
        call delay
        ; Sample in the middle third of each data bit :
        ;   char := 0  
        clrf get_byte__char
        ; `count_down count 8 ...' start
        movlw 8
        movwf get_byte__count
get_byte__97_loop:
        ;   call delay {{ }}  
        call delay
        ;   char := char >> 1  
        bcf c___byte,c___bit
        rrf get_byte__char,f
        ; if { serial_in } start
        ; expression=`{ serial_in }' exp_delay=0 true_delay=2  false_delay=0 true_size=2 false_size=0
        btfss serial_in__byte,serial_in__bit
        goto label100__0end
        ; if { serial_in } body start
        ;   char := char | 0x80  
        movlw 128
        iorwf get_byte__char,f
        ; if { serial_in } body end
label100__0end:
        ; if exp=`serial_in' empty false
        ; Other expression=`{ serial_in }' delay=-1
        ; if { serial_in } end
        ;   call delay {{ }}  
        call delay
        ;   call delay {{ }}  
        call delay
        decfsz get_byte__count,f
        goto get_byte__97_loop
get_byte__97_done:
        ; `count_down count 8 ...' end
        ; Skip over 2 / 3 ' s of stop bit :
        ;   call delay {{ }}  
        call delay
        ;   call delay {{ }}  
        call delay
        ;   return char  
        movf get_byte__char,w
        movwf get_byte__0return__byte
        retlw 0
        ; procedure get_byte end

        ; procedure put_byte start
put_byte:
        ; Procedure must be called with PCLATH set to code bank 0
put_byte__variables__base equ global__variables__bank0+9
put_byte__bytes__base equ put_byte__variables__base+0
put_byte__bits__base equ put_byte__variables__base+2
put_byte__total__bytes equ 2
put_byte__char equ put_byte__bytes__base+0
        ; Send < char > to < tx > :
put_byte__count equ put_byte__bytes__base+1
        ; < receiving > will be 1 if the last get / put routine was a get .
        ; Before we start transmitting a response back , we want to ensure
        ; that there has been enough time to turn the line line around .
        ; We delay the first 1 / 3 of a bit to pad out the 9 - 2 / 3 bits from
        ; for get_byte to 10 bits . We delay another 1 / 3 of a bit just
        ; for good measure . Technically , the second call to delay < >
        ; is not really needed .
        ; if { receiving } start
        ; expression=`{ receiving }' exp_delay=0 true_delay=-1  false_delay=0 true_size=3 false_size=0
        btfss receiving__byte,receiving__bit
        goto label129__0end
        ; if { receiving } body start
        ;   receiving := 0  
        bcf receiving__byte,receiving__bit
        ;   call delay {{ }}  
        call delay
        ;   call delay {{ }}  
        call delay
        ; if { receiving } body end
label129__0end:
        ; if exp=`receiving' empty false
        ; Other expression=`{ receiving }' delay=-1
        ; if { receiving } end
        ; Send the start bit :
        ;   serial_out := 0  
        bcf serial_out__byte,serial_out__bit
        ;   call delay {{ }}  
        call delay
        ;   call delay {{ }}  
        call delay
        ;   call delay {{ }}  
        call delay
        ; Send the data :
        ; `count_down count 8 ...' start
        movlw 8
        movwf put_byte__count
put_byte__142_loop:
        ;   serial_out := char @ 0  
        ; Alias variable for select char @ 0
put_byte__char__143select0 equ put_byte__char+0
put_byte__char__143select0__byte equ put_byte__char+0
put_byte__char__143select0__bit equ 0
        btfss put_byte__char__143select0__byte,put_byte__char__143select0__bit
        bcf serial_out__byte,serial_out__bit
        btfsc put_byte__char__143select0__byte,put_byte__char__143select0__bit
        bsf serial_out__byte,serial_out__bit
        ;   char := char >> 1  
        bcf c___byte,c___bit
        rrf put_byte__char,f
        ;   call delay {{ }}  
        call delay
        ;   call delay {{ }}  
        call delay
        ;   call delay {{ }}  
        call delay
        decfsz put_byte__count,f
        goto put_byte__142_loop
put_byte__142_done:
        ; `count_down count 8 ...' end
        ; Send the stop bit :
        ;   serial_out := 1  
        bsf serial_out__byte,serial_out__bit
        ;   call delay {{ }}  
        call delay
        ;   call delay {{ }}  
        call delay
        ;   call delay {{ }}  
        call delay
        ; procedure put_byte end
        retlw 0

        ; procedure delay start
        ; optimize 0
delay:
        ; Procedure must be called with PCLATH set to code bank 0
delay__variables__base equ global__variables__bank0+11
delay__bytes__base equ delay__variables__base+0
delay__bits__base equ delay__variables__base+5
delay__total__bytes equ 5
delay__177byte0 equ delay__bytes__base+4
delay__157byte1 equ delay__bytes__base+4
        ;   arguments_none  
        ;   uniform_delay instructions_per_delay  
        ; Uniform delay remaining = 134 Accumulated Delay = 0
        ; Uniform delay remaining = 134 Accumulated Delay = 0
        ; This procedure will delay for 1 / 3 of a bit time .
        ; Uniform delay remaining = 134 Accumulated Delay = 0
        ; Uniform delay remaining = 134 Accumulated Delay = 0
delay__changed equ delay__bytes__base+0
        ; Uniform delay remaining = 134 Accumulated Delay = 0
delay__current equ delay__bytes__base+1
        ; Uniform delay remaining = 134 Accumulated Delay = 0
delay__previous equ delay__bytes__base+2
        ; Uniform delay remaining = 134 Accumulated Delay = 0
delay__not_current equ delay__bytes__base+3
        ; Uniform delay remaining = 134 Accumulated Delay = 0
        ; Uniform delay remaining = 134 Accumulated Delay = 0
        ; Kick the dog :
        ; Uniform delay remaining = 134 Accumulated Delay = 0
        ;   watch_dog_reset  
        clrwdt
        ; Uniform delay remaining = 133 Accumulated Delay = 1
        ; Uniform delay remaining = 133 Accumulated Delay = 1
        ; Compute interrupt pending :
        ; Uniform delay remaining = 133 Accumulated Delay = 1
        ;   previous := current  
        movf delay__current,w
        movwf delay__previous
        ; Uniform delay remaining = 131 Accumulated Delay = 3
        ;   current := {{ porta ^ 0xf ^ complement }} & 0xf  
        movlw 15
        xorwf porta,w
        xorwf complement,w
        andlw 15
        movwf delay__current
        ; Uniform delay remaining = 126 Accumulated Delay = 8
        ;   not_current := current ^ 0xf  
        movlw 15
        xorwf delay__current,w
        movwf delay__not_current
        ; Uniform delay remaining = 123 Accumulated Delay = 11
        ;   changed := current ^ previous  
        movf delay__current,w
        xorwf delay__previous,w
        movwf delay__changed
        ; Uniform delay remaining = 120 Accumulated Delay = 14
        ; if { {{ low & not_current }} | {{ high & current }} | {{ changed & current & raising }} | {{ changed & previous & falling }} != 0 } start
        movf low,w
        andwf delay__not_current,w
        movwf delay__177byte0
        movf high,w
        andwf delay__current,w
        iorwf delay__177byte0,f
        movf delay__changed,w
        andwf delay__current,w
        andwf raising,w
        iorwf delay__177byte0,f
        movf delay__changed,w
        andwf delay__previous,w
        andwf falling,w
        iorwf delay__177byte0,w
        ; expression=`{ {{ low & not_current }} | {{ high & current }} | {{ changed & current & raising }} | {{ changed & previous & falling }} != 0 }' exp_delay=14 true_delay=1  false_delay=0 true_size=1 false_size=0
        btfss z___byte,z___bit
        ; if { {{ low & not_current }} | {{ high & current }} | {{ changed & current & raising }} | {{ changed & previous & falling }} != 0 } body start
        ; Uniform delay remaining = 120 Accumulated Delay = 0
        ;   interrupt_pending := 1  
        bsf interrupt_pending__byte,interrupt_pending__bit
        ; Uniform delay remaining = 119 Accumulated Delay = 1
        ; Uniform delay remaining = 119 Accumulated Delay = 1
        ; if { {{ low & not_current }} | {{ high & current }} | {{ changed & current & raising }} | {{ changed & previous & falling }} != 0 } body end
        ; if exp=` {{ low & not_current }} | {{ high & current }} | {{ changed & current & raising }} | {{ changed & previous & falling }} != 0 ' false skip delay=16
        ; Other expression=`{ {{ low & not_current }} | {{ high & current }} | {{ changed & current & raising }} | {{ changed & previous & falling }} != 0 }' delay=16
        ; if { {{ low & not_current }} | {{ high & current }} | {{ changed & current & raising }} | {{ changed & previous & falling }} != 0 } end
        ; Uniform delay remaining = 104 Accumulated Delay = 30
        ; Uniform delay remaining = 104 Accumulated Delay = 30
        ; Send an interrupt if interrupts are enabled :
        ; Uniform delay remaining = 104 Accumulated Delay = 30
        ; if { interrupt_pending && interrupt_enable } start
        ; expression=`interrupt_pending' exp_delay=0 true_delay=6  false_delay=5 true_size=8 false_size=1
        btfsc interrupt_pending__byte,interrupt_pending__bit
        goto label182__2true
label182__2false:
        ; Delay 2 cycles
        nop
        nop
        goto and182__0false
label182__2true:
        ; expression=`interrupt_enable' exp_delay=0 true_delay=2  false_delay=0 true_size=2 false_size=0
        btfss interrupt_enable__byte,interrupt_enable__bit
        goto label182__1false
label182__1true:
and182__0true:
        ; if { interrupt_pending && interrupt_enable } body start
        ; Uniform delay remaining = 104 Accumulated Delay = 0
        ; Shove serial_out to low to indicate an interrupt :
        ; Uniform delay remaining = 104 Accumulated Delay = 0
        ;   interrupt_enable := 0  
        bcf interrupt_enable__byte,interrupt_enable__bit
        ; Uniform delay remaining = 103 Accumulated Delay = 1
        ;   serial_out := 0  
        bcf serial_out__byte,serial_out__bit
        ; Uniform delay remaining = 102 Accumulated Delay = 2
        ; Uniform delay remaining = 102 Accumulated Delay = 2
        ; if { interrupt_pending && interrupt_enable } body end
        goto label182__1end
label182__1false:
        ; Delay 3 cycles
        nop
        nop
        nop
        ; if exp=`interrupt_enable' total delay=6
        ; if exp=`interrupt_enable' generic
label182__1end:
        ; Other expression=`interrupt_enable' delay=6
        ; if exp=`interrupt_pending' total delay=9
        ; if exp=`interrupt_pending' generic
label182__2end:
        ; Other expression=`interrupt_pending' delay=9
and182__0false:
and182__0end:
        ; if { interrupt_pending && interrupt_enable } end
        ; Uniform delay remaining = 95 Accumulated Delay = 39
        ; Uniform delay remaining = 95 Accumulated Delay = 39
        ; Soak up remaining 95 cycles
        ; Delay 95 cycles
        movlw 31
        movwf delay__157byte1
delay__157delay0:
        decfsz delay__157byte1,f
        goto delay__157delay0
        nop
        ; procedure delay end
        retlw 0
        ; optimize 1
        ; comment {The main routine can span the 256 byte boundary :}
        ;   origin 0x200  
        org 512

        ; procedure main start
switch__231block_start:
        addwf pcl___register,f
        goto switch__231block232
        goto switch__231block236
        goto switch__231block240
        goto switch__231block244
        goto switch__231block248
        goto switch__231block252
        goto switch__231block256
        goto switch__231default260
switch__231block_end:
        ; switch_check 231 switch__231block_start switch__231block_end
switch__228block_start:
        addwf pcl___register,f
        goto switch__228block229
        goto switch__228block265
        goto switch__228block269
        goto switch__228block269
        goto switch__228block273
        goto switch__228block273
        goto switch__228block277
        goto switch__228block277
switch__228block_end:
        ; switch_check 228 switch__228block_start switch__228block_end
switch__285block_start:
        addwf pcl___register,f
        goto switch__285block286
        goto switch__285block290
        goto switch__285default294
        goto switch__285default294
switch__285block_end:
        ; switch_check 285 switch__285block_start switch__285block_end
switch__323block_start:
        addwf pcl___register,f
        goto switch__323block324
        goto switch__323block324
        goto switch__323block329
        goto switch__323block333
switch__323block_end:
        ; switch_check 323 switch__323block_start switch__323block_end
switch__341block_start:
        addwf pcl___register,f
        goto switch__341block342
        goto switch__341block346
        goto switch__341block350
        goto switch__341block354
        goto switch__341block358
        goto switch__341block369
        goto switch__341block373
        goto switch__341block378
switch__341block_end:
        ; switch_check 341 switch__341block_start switch__341block_end
switch__306block_start:
        addwf pcl___register,f
        goto switch__306end
        goto switch__306end
        goto switch__306end
        goto switch__306end
        goto switch__306end
        goto switch__306block307
        goto switch__306block321
        goto switch__306block339
switch__306block_end:
        ; switch_check 306 switch__306block_start switch__306block_end
switch__225block_start:
        addwf pcl___register,f
        goto switch__225block226
        goto switch__225block283
        goto switch__225block300
        goto switch__225block304
switch__225block_end:
        ; switch_check 225 switch__225block_start switch__225block_end
main:
        ; Procedure must be called with PCLATH set to code bank 0
main__variables__base equ global__variables__bank0+16
main__bytes__base equ main__variables__base+0
main__bits__base equ main__variables__base+5
main__total__bytes equ 5
main__306byte0 equ main__bytes__base+4
main__225byte0 equ main__bytes__base+4
main__309byte0 equ main__bytes__base+4
main__228byte0 equ main__bytes__base+4
        ;   arguments_none  
main__command equ main__bytes__base+0
main__glitch equ main__bytes__base+1
main__id_index equ main__bytes__base+2
main__result equ main__bytes__base+3
        ; For Threshold4A specific commands see :
        ; http : / / web . gramlich . com / projects / robobricks / threshold4 / rev_a / index . html
        ; For shared commands see :
        ; http : / / web . gramlich . com / projects / robobricks / index . html # Software_Protocol
        ; For shared interruptcommands see :
        ; http : / / web . gramlich . com / projects / robobricks / index . html # Interrupts
        ; Initialize everything :
        ;   interrupt_enable := 0  
        bcf interrupt_enable__byte,interrupt_enable__bit
        ;   interrupt_pending := 0  
        bcf interrupt_pending__byte,interrupt_pending__bit
        ;   falling := 0  
        clrf falling
        ;   high := 0  
        clrf high
        ;   low := 0  
        clrf low
        ;   raising := 0  
        clrf raising
        ;   glitch := 0  
        clrf main__glitch
        ;   id_index := 0  
        clrf main__id_index
        ; Loop waiting for commands :
        ; loop_forever ... start
main__220loop__forever:
        ; Get a command byte :
        ;   command := get_byte {{ }}  
        ; Switch from code bank 1 to code bank 0 before possible transfer (call)
        bcf pa0___byte,pa0___bit
        call get_byte
        movf get_byte__0return__byte,w
        movwf main__command
        ; Dispatch on command :
        ; switch { command >> 6 }
        swapf main__command,w
        movwf main__225byte0
        rrf main__225byte0,f
        rrf main__225byte0,w
        andlw 3
        ; case 0
        ; case 1
        ; case 2
        ; case 3
        ; Switch from code bank 0 to code bank 1 before possible transfer (goto)
        bsf pa0___byte,pa0___bit
        goto switch__225block_start
switch__225block226:
        ; Command = 00 xx xxxx :
        ; switch { {{ command >> 3 }} & 7 }
        rrf main__command,w
        movwf main__228byte0
        rrf main__228byte0,f
        rrf main__228byte0,w
        andlw 7
        ; case 0
        ; case 1
        ; case 2 3
        ; case 4 5
        ; case 6 7
        goto switch__228block_start
switch__228block229:
        ; Command = 0000 0 xxx :
        ; switch { command & 7 }
        movlw 7
        andwf main__command,w
        ; case 0
        ; case 1
        ; case 2
        ; case 3
        ; case 4
        ; case 5
        ; case 6
        goto switch__231block_start
switch__231block232:
        ; Read Inputs < Command = 0000 0000 > :
        ;   call put_byte {{ {{ porta ^ 0xf ^ complement }} & 0xf }}  
        movlw 15
        xorwf porta,w
        xorwf complement,w
        andlw 15
        movwf put_byte__char
        ; Switch from code bank 1 to code bank 0 before possible transfer (call)
        bcf pa0___byte,pa0___bit
        call put_byte
        ; Switch from code bank 0 to code bank 1 before possible transfer (goto)
        bsf pa0___byte,pa0___bit
        goto switch__231end
switch__231block236:
        ; Read Complement Mask < Command = 0000 0001 > :
        ;   call put_byte {{ complement }}  
        movf complement,w
        movwf put_byte__char
        ; Switch from code bank 1 to code bank 0 before possible transfer (call)
        bcf pa0___byte,pa0___bit
        call put_byte
        ; Switch from code bank 0 to code bank 1 before possible transfer (goto)
        bsf pa0___byte,pa0___bit
        goto switch__231end
switch__231block240:
        ; Read High Mask < Command = 0000 0010 > :
        ;   call put_byte {{ high }}  
        movf high,w
        movwf put_byte__char
        ; Switch from code bank 1 to code bank 0 before possible transfer (call)
        bcf pa0___byte,pa0___bit
        call put_byte
        ; Switch from code bank 0 to code bank 1 before possible transfer (goto)
        bsf pa0___byte,pa0___bit
        goto switch__231end
switch__231block244:
        ; Read Low Mask < Command = 0000 0011 > :
        ;   call put_byte {{ low }}  
        movf low,w
        movwf put_byte__char
        ; Switch from code bank 1 to code bank 0 before possible transfer (call)
        bcf pa0___byte,pa0___bit
        call put_byte
        ; Switch from code bank 0 to code bank 1 before possible transfer (goto)
        bsf pa0___byte,pa0___bit
        goto switch__231end
switch__231block248:
        ; Read Raising Mask < Command = 0000 0100 > :
        ;   call put_byte {{ raising }}  
        movf raising,w
        movwf put_byte__char
        ; Switch from code bank 1 to code bank 0 before possible transfer (call)
        bcf pa0___byte,pa0___bit
        call put_byte
        ; Switch from code bank 0 to code bank 1 before possible transfer (goto)
        bsf pa0___byte,pa0___bit
        goto switch__231end
switch__231block252:
        ; Read Falling Mask < Command = 0000 0101 > :
        ;   call put_byte {{ falling }}  
        movf falling,w
        movwf put_byte__char
        ; Switch from code bank 1 to code bank 0 before possible transfer (call)
        bcf pa0___byte,pa0___bit
        call put_byte
        ; Switch from code bank 0 to code bank 1 before possible transfer (goto)
        bsf pa0___byte,pa0___bit
        goto switch__231end
switch__231block256:
        ; Read Raw < Command = 0000 0110 > :
        ;   call put_byte {{ {{ porta ^ 0xf }} & 0xf }}  
        movlw 15
        xorwf porta,w
        andlw 15
        movwf put_byte__char
        ; Switch from code bank 1 to code bank 0 before possible transfer (call)
        bcf pa0___byte,pa0___bit
        call put_byte
        ; Switch from code bank 0 to code bank 1 before possible transfer (goto)
        bsf pa0___byte,pa0___bit
        goto switch__231end
switch__231default260:
        ; Undefined command ; do nothing < Command = 0000 0111 > :
switch__231end:
        goto switch__228end
switch__228block265:
        ; Command = 0000 1 xxx :
        ; Do nothing :
        goto switch__228end
switch__228block269:
        ; Set Complement Mask < Command = 0001 cccc > :
        ;   complement := command & 0xf  
        movlw 15
        andwf main__command,w
        movwf complement
        goto switch__228end
switch__228block273:
        ; Set High Mask < Command = 0010 hhhh > :
        ;   high := command & 0xf  
        movlw 15
        andwf main__command,w
        movwf high
        goto switch__228end
switch__228block277:
        ; Set Low Mask < Command = 0011 llll > :
        ;   low := command & 0xf  
        movlw 15
        andwf main__command,w
        movwf low
switch__228end:
        goto switch__225end
switch__225block283:
        ; Command = 01 xx xxxx :
        ; switch { {{ command >> 4 }} & 3 }
        swapf main__command,w
        andlw 3
        ; case 0
        ; case 1
        goto switch__285block_start
switch__285block286:
        ; Set Raising Mask < Command = 0100 rrrr > :
        ;   raising := command & 0xf  
        movlw 15
        andwf main__command,w
        movwf raising
        goto switch__285end
switch__285block290:
        ; Set Falling Mask < Command = 0101 ffff > :
        ;   falling := command & 0xf  
        movlw 15
        andwf main__command,w
        movwf falling
        goto switch__285end
switch__285default294:
        ; Command = 011 x xxxx :
        ; Do nothing :
switch__285end:
        goto switch__225end
switch__225block300:
        ; Command = 10 xx xxxx :
        ; Do nothing :
        goto switch__225end
switch__225block304:
        ; Command = 11 xx xxxx :
        ; switch { {{ command >> 3 }} & 7 }
        rrf main__command,w
        movwf main__306byte0
        rrf main__306byte0,f
        rrf main__306byte0,w
        andlw 7
        ; case 5
        ; case 6
        ; case 7
        goto switch__306block_start
switch__306block307:
        ; Command = 1110 1 xxx :
        ; if { {{ command & 7 }} = 7 } start
        movlw 7
        andwf main__command,w
        movwf main__309byte0
        movlw 7
        subwf main__309byte0,w
        ; expression=`{ {{ command & 7 }} = 7 }' exp_delay=5 true_delay=-1  false_delay=0 true_size=12 false_size=0
        btfss z___byte,z___bit
        goto label309__1end
        ; if { {{ command & 7 }} = 7 } body start
        ; Return Interrupt Bits < Command = 1110 1111 > :
        ;   result := 0  
        clrf main__result
        ; if { interrupt_enable } start
        ; expression=`{ interrupt_enable }' exp_delay=0 true_delay=2  false_delay=0 true_size=2 false_size=0
        btfss interrupt_enable__byte,interrupt_enable__bit
        goto label312__0end
        ; if { interrupt_enable } body start
        ;   result := result | 2  
        movlw 2
        iorwf main__result,f
        ; if { interrupt_enable } body end
label312__0end:
        ; if exp=`interrupt_enable' empty false
        ; Other expression=`{ interrupt_enable }' delay=-1
        ; if { interrupt_enable } end
        ; if { interrupt_pending } start
        ; expression=`{ interrupt_pending }' exp_delay=0 true_delay=2  false_delay=0 true_size=2 false_size=0
        btfss interrupt_pending__byte,interrupt_pending__bit
        goto label315__0end
        ; if { interrupt_pending } body start
        ;   result := result | 1  
        movlw 1
        iorwf main__result,f
        ; if { interrupt_pending } body end
label315__0end:
        ; if exp=`interrupt_pending' empty false
        ; Other expression=`{ interrupt_pending }' delay=-1
        ; if { interrupt_pending } end
        ;   call put_byte {{ result }}  
        movf main__result,w
        movwf put_byte__char
        ; Switch from code bank 1 to code bank 0 before possible transfer (call)
        bcf pa0___byte,pa0___bit
        call put_byte
        ; if { {{ command & 7 }} = 7 } body end
        ; Switch from code bank 0 to code bank 1 before possible transfer (label)
        bsf pa0___byte,pa0___bit
label309__1end:
        ; if exp=` {{ command & 7 }} = 7 ' empty false
        ; Other expression=`{ {{ command & 7 }} = 7 }' delay=-1
        ; if { {{ command & 7 }} = 7 } end
        goto switch__306end
switch__306block321:
        ; Shared Interrupt commands .
        ; switch { {{ command >> 1 }} & 3 }
        bcf c___byte,c___bit
        rrf main__command,w
        andlw 3
        ; case 0 1
        ; case 2
        ; case 3
        goto switch__323block_start
switch__323block324:
        ; Set Interrupt Bits < Command = 1110 00 ep > :
        ;   interrupt_enable := command @ 1  
        ; Alias variable for select command @ 1
main__command__326select0 equ main__command+0
main__command__326select0__byte equ main__command+0
main__command__326select0__bit equ 1
        bcf interrupt_enable__byte,interrupt_enable__bit
        btfsc main__command__326select0__byte,main__command__326select0__bit
        bsf interrupt_enable__byte,interrupt_enable__bit
        ;   interrupt_pending := command @ 0  
        ; Alias variable for select command @ 0
main__command__327select0 equ main__command+0
main__command__327select0__byte equ main__command+0
main__command__327select0__bit equ 0
        bcf interrupt_pending__byte,interrupt_pending__bit
        btfsc main__command__327select0__byte,main__command__327select0__bit
        bsf interrupt_pending__byte,interrupt_pending__bit
        goto switch__323end
switch__323block329:
        ; Set Interrupt Pending < Command = 1110 010 p > :
        ;   interrupt_pending := command @ 0  
        ; Alias variable for select command @ 0
main__command__331select0 equ main__command+0
main__command__331select0__byte equ main__command+0
main__command__331select0__bit equ 0
        bcf interrupt_pending__byte,interrupt_pending__bit
        btfsc main__command__331select0__byte,main__command__331select0__bit
        bsf interrupt_pending__byte,interrupt_pending__bit
        goto switch__323end
switch__323block333:
        ; Set Interrupt Enable < Command = 1110 011 e > :
        ;   interrupt_enable := command @ 0  
        ; Alias variable for select command @ 0
main__command__335select0 equ main__command+0
main__command__335select0__byte equ main__command+0
main__command__335select0__bit equ 0
        bcf interrupt_enable__byte,interrupt_enable__bit
        btfsc main__command__335select0__byte,main__command__335select0__bit
        bsf interrupt_enable__byte,interrupt_enable__bit
switch__323end:
        goto switch__306end
switch__306block339:
        ; Shared commands < Command = 1111 1 ccc > :
        ; switch { command & 7 }
        movlw 7
        andwf main__command,w
        ; case 0
        ; case 1
        ; case 2
        ; case 3
        ; case 4
        ; case 5
        ; case 6
        ; case 7
        goto switch__341block_start
switch__341block342:
        ; Clock Decrement < Command = 1111 1000 > :
        ;   osccal := osccal - osccal_unit  
        movlw 240
        addwf osccal,f
        goto switch__341end
switch__341block346:
        ; Clock Increment < Command = 1111 1001 > :
        ;   osccal := osccal + osccal_unit  
        movlw 16
        addwf osccal,f
        goto switch__341end
switch__341block350:
        ; Clock Read < Command = 1111 1010 > :
        ;   call put_byte {{ osccal }}  
        movf osccal,w
        movwf put_byte__char
        ; Switch from code bank 1 to code bank 0 before possible transfer (call)
        bcf pa0___byte,pa0___bit
        call put_byte
        ; Switch from code bank 0 to code bank 1 before possible transfer (goto)
        bsf pa0___byte,pa0___bit
        goto switch__341end
switch__341block354:
        ; Clock Pulse < Command = 1111 1011 > :
        ;   call put_byte {{ 0 }}  
        clrf put_byte__char
        ; Switch from code bank 1 to code bank 0 before possible transfer (call)
        bcf pa0___byte,pa0___bit
        call put_byte
        ; Switch from code bank 0 to code bank 1 before possible transfer (goto)
        bsf pa0___byte,pa0___bit
        goto switch__341end
switch__341block358:
        ; ID Next < Command = 1111 1100 > :
        ; if { id_index >= id . size } start
        movlw 52
        subwf main__id_index,w
        ; expression=`{ id_index >= id . size }' exp_delay=2 true_delay=1  false_delay=0 true_size=1 false_size=0
        btfsc c___byte,c___bit
        ; if { id_index >= id . size } body start
        ;   id_index := 0  
        clrf main__id_index
        ; if { id_index >= id . size } body end
        ; if exp=` id_index >= id . size ' false skip delay=4
        ; Other expression=`{ id_index >= id . size }' delay=4
        ; if { id_index >= id . size } end
        ;   call put_byte {{ id ~~ {{ id_index }} }}  
        incf main__id_index,w
        ; Switch from code bank 1 to code bank 0 before possible transfer (call)
        bcf pa0___byte,pa0___bit
        call id
        movwf put_byte__char
        call put_byte
        ;   id_index := id_index + 1  
        incf main__id_index,f
        ; if { id_index >= id . size } start
        movlw 52
        subwf main__id_index,w
        ; expression=`{ id_index >= id . size }' exp_delay=2 true_delay=1  false_delay=0 true_size=1 false_size=0
        ; Switch from code bank 0 to code bank 1 before possible transfer (btfsc)
        bsf pa0___byte,pa0___bit
        btfsc c___byte,c___bit
        ; if { id_index >= id . size } body start
        ;   id_index := 0  
        clrf main__id_index
        ; if { id_index >= id . size } body end
        ; if exp=` id_index >= id . size ' false skip delay=4
        ; Other expression=`{ id_index >= id . size }' delay=4
        ; if { id_index >= id . size } end
        goto switch__341end
switch__341block369:
        ; ID Reset < Command = 1111 1101 > :
        ;   id_index := 0  
        clrf main__id_index
        goto switch__341end
switch__341block373:
        ; Glitch Read < Command = 1111 1110 > :
        ;   call put_byte {{ glitch }}  
        movf main__glitch,w
        movwf put_byte__char
        ; Switch from code bank 1 to code bank 0 before possible transfer (call)
        bcf pa0___byte,pa0___bit
        call put_byte
        ;   glitch := 0  
        clrf main__glitch
        ; Switch from code bank 0 to code bank 1 before possible transfer (goto)
        bsf pa0___byte,pa0___bit
        goto switch__341end
switch__341block378:
        ; Glitch < Command = 1111 1111 > :
        ; if { glitch != 0xff } start
        incf main__glitch,w
        ; expression=`{ glitch != 0xff }' exp_delay=1 true_delay=1  false_delay=0 true_size=1 false_size=0
        btfss z___byte,z___bit
        ; if { glitch != 0xff } body start
        ;   glitch := glitch + 1  
        incf main__glitch,f
        ; if { glitch != 0xff } body end
        ; if exp=` glitch != 0xff ' false skip delay=3
        ; Other expression=`{ glitch != 0xff }' delay=3
        ; if { glitch != 0xff } end
switch__341end:
switch__306end:
switch__225end:
        goto main__220loop__forever
        ; loop_forever ... end
        ; procedure main end

        ; Register bank 0 used 21 bytes of 25 available bytes
        ; Register bank 1 used 0 bytes of 16 available bytes

        end

