;/////////////////////////////////////////////////////////////////////////////////
;// Code Generator: BoostC Compiler - http://www.sourceboost.com
;// Version       : 6.95
;// License Type  : Lite License (Unregistered)
;// Limitations   : PIC12,PIC16 max code size:2048 words, max RAM banks:2, Non commercial use only
;/////////////////////////////////////////////////////////////////////////////////

	include "P16F819.inc"
; Heap block 0, size:96 (0x000000A0 - 0x000000FF)
__HEAP_BLOCK0_BANK               EQU	0x00000001
__HEAP_BLOCK0_START_OFFSET       EQU	0x00000020
__HEAP_BLOCK0_END_OFFSET         EQU	0x0000007F
; Heap block 1, size:61 (0x00000033 - 0x0000006F)
__HEAP_BLOCK1_BANK               EQU	0x00000000
__HEAP_BLOCK1_START_OFFSET       EQU	0x00000033
__HEAP_BLOCK1_END_OFFSET         EQU	0x0000006F
; Heap block 2, size:0 (0x00000000 - 0x00000000)
__HEAP_BLOCK2_BANK               EQU	0x00000000
__HEAP_BLOCK2_START_OFFSET       EQU	0x00000000
__HEAP_BLOCK2_END_OFFSET         EQU	0x00000000
; Heap block 3, size:0 (0x00000000 - 0x00000000)
__HEAP_BLOCK3_BANK               EQU	0x00000000
__HEAP_BLOCK3_START_OFFSET       EQU	0x00000000
__HEAP_BLOCK3_END_OFFSET         EQU	0x00000000
gbl_status                       EQU	0x00000003 ; bytes:1
__mul_8u_8_00006_arg_a           EQU	0x0000002A ; bytes:1
__mul_8u_8_00006_arg_b           EQU	0x0000002B ; bytes:1
CompTempVarRet375                EQU	0x00000031 ; bytes:2
__mul_8u_8_00006_1_i             EQU	0x0000002E ; bytes:1
__mul_8u_8_00006_1_t             EQU	0x0000002F ; bytes:2
gbl_indf                         EQU	0x00000000 ; bytes:1
gbl_tmr0                         EQU	0x00000001 ; bytes:1
gbl_pcl                          EQU	0x00000002 ; bytes:1
gbl_fsr                          EQU	0x00000004 ; bytes:1
gbl_porta                        EQU	0x00000005 ; bytes:1
gbl_portb                        EQU	0x00000006 ; bytes:1
gbl_pclath                       EQU	0x0000000A ; bytes:1
gbl_intcon                       EQU	0x0000000B ; bytes:1
gbl_pir1                         EQU	0x0000000C ; bytes:1
gbl_pir2                         EQU	0x0000000D ; bytes:1
gbl_tmr1l                        EQU	0x0000000E ; bytes:1
gbl_tmr1h                        EQU	0x0000000F ; bytes:1
gbl_t1con                        EQU	0x00000010 ; bytes:1
gbl_tmr2                         EQU	0x00000011 ; bytes:1
gbl_t2con                        EQU	0x00000012 ; bytes:1
gbl_sspbuf                       EQU	0x00000013 ; bytes:1
gbl_sspcon                       EQU	0x00000014 ; bytes:1
gbl_ccpr1l                       EQU	0x00000015 ; bytes:1
gbl_ccpr1h                       EQU	0x00000016 ; bytes:1
gbl_ccp1con                      EQU	0x00000017 ; bytes:1
gbl_adresh                       EQU	0x0000001E ; bytes:1
gbl_adcon0                       EQU	0x0000001F ; bytes:1
gbl_option_reg                   EQU	0x00000081 ; bytes:1
gbl_trisa                        EQU	0x00000085 ; bytes:1
gbl_trisb                        EQU	0x00000086 ; bytes:1
gbl_pie1                         EQU	0x0000008C ; bytes:1
gbl_pie2                         EQU	0x0000008D ; bytes:1
gbl_pcon                         EQU	0x0000008E ; bytes:1
gbl_osccon                       EQU	0x0000008F ; bytes:1
gbl_osctune                      EQU	0x00000090 ; bytes:1
gbl_pr2                          EQU	0x00000092 ; bytes:1
gbl_sspadd                       EQU	0x00000093 ; bytes:1
gbl_sspstat                      EQU	0x00000094 ; bytes:1
gbl_adresl                       EQU	0x0000009E ; bytes:1
gbl_adcon1                       EQU	0x0000009F ; bytes:1
gbl_eedata                       EQU	0x0000010C ; bytes:1
gbl_eeadr                        EQU	0x0000010D ; bytes:1
gbl_eedath                       EQU	0x0000010E ; bytes:1
gbl_eeadrh                       EQU	0x0000010F ; bytes:1
gbl_eecon1                       EQU	0x0000018C ; bytes:1
gbl_eecon2                       EQU	0x0000018D ; bytes:1
out_portb_00000_arg_buf          EQU	0x00000026 ; bytes:1
out_portb_00000_1_duty           EQU	0x00000027 ; bytes:1
out_portb_00000_1_base           EQU	0x00000028 ; bytes:1
out_portb_00000_1_interval       EQU	0x00000029 ; bytes:1
CompTempVar580                   EQU	0x0000002C ; bytes:1
CompTempVar581                   EQU	0x0000002D ; bytes:1
CompTempVar583                   EQU	0x0000002C ; bytes:1
CompTempVar584                   EQU	0x0000002D ; bytes:1
CompTempVarRet585                EQU	0x0000002A ; bytes:1
read_porta_00013_1_status        EQU	0x00000026 ; bytes:1
read_porta_00013_1_input         EQU	0x00000027 ; bytes:1
read_porta_00013_1_count         EQU	0x00000028 ; bytes:1
read_porta_00013_1_count2        EQU	0x00000029 ; bytes:1
delay_100u_00014_1_c1            EQU	0x00000026 ; bytes:1
main_1_count                     EQU	0x00000020 ; bytes:1
main_1_status                    EQU	0x00000021 ; bytes:1
main_1_i                         EQU	0x00000022 ; bytes:1
main_1_buf                       EQU	0x00000023 ; bytes:1
main_1_recv_bit                  EQU	0x00000024 ; bytes:1
main_1_input                     EQU	0x00000025 ; bytes:1
delay_ms_00000_arg_del           EQU	0x00000026 ; bytes:1
	ORG 0x00000000
	GOTO	_startup
	ORG 0x00000004
delay_ms_00000
; { delay_ms ; function begin
	MOVF delay_ms_00000_arg_del, F
	BTFSS STATUS,Z
	GOTO	label1
	RETURN
label1
	MOVLW 0xF9
label2
	NOP
	NOP
	NOP
	NOP
	ADDLW 0xFF
	BTFSS STATUS,Z
	GOTO	label2
	NOP
	NOP
	NOP
	NOP
	NOP
	DECFSZ delay_ms_00000_arg_del, F
	GOTO	label1
	RETURN
; } delay_ms function end

	ORG 0x00000018
delay_100u_00014
; { delay_100us ; function begin
	MOVLW 0x3F
	BCF STATUS, RP0
	BCF STATUS, RP1
	MOVWF delay_100u_00014_1_c1
label3
	DECFSZ delay_100u_00014_1_c1, F
	GOTO	label3
	RETURN
; } delay_100us function end

	ORG 0x0000001F
read_porta_00013
; { read_porta_1 ; function begin
	BCF STATUS, RP0
	BCF STATUS, RP1
	CLRF read_porta_00013_1_status
	BTFSC gbl_porta,1
	INCF read_porta_00013_1_status, F
	CLRF read_porta_00013_1_count
	CLRF read_porta_00013_1_count2
label4
	INCF read_porta_00013_1_count2, F
	CLRF read_porta_00013_1_input
	BTFSC gbl_porta,1
	INCF read_porta_00013_1_input, F
	MOVF read_porta_00013_1_input, W
	XORWF read_porta_00013_1_status, W
	BTFSS STATUS,Z
	GOTO	label5
	INCF read_porta_00013_1_count, F
	GOTO	label6
label5
	MOVF read_porta_00013_1_input, W
	MOVWF read_porta_00013_1_status
	CLRF read_porta_00013_1_count
label6
	MOVLW 0x05
	SUBWF read_porta_00013_1_count, W
	BTFSC STATUS,C
	GOTO	label7
	MOVLW 0x14
	SUBWF read_porta_00013_1_count2, W
	BTFSS STATUS,C
	GOTO	label4
	MOVLW 0x02
	MOVWF CompTempVarRet585
	RETURN
label7
	MOVF read_porta_00013_1_status, W
	MOVWF CompTempVarRet585
	RETURN
; } read_porta_1 function end

	ORG 0x00000041
__mul_8u_8_00006
; { __mul_8u_8u ; function begin
	CLRF __mul_8u_8_00006_1_i
	CLRF CompTempVarRet375
	CLRF CompTempVarRet375+D'1'
	MOVF __mul_8u_8_00006_arg_a, W
	MOVWF __mul_8u_8_00006_1_t
	CLRF __mul_8u_8_00006_1_t+D'1'
label8
	BTFSC __mul_8u_8_00006_1_i,3
	RETURN
	BTFSS __mul_8u_8_00006_arg_b,0
	GOTO	label9
	MOVF __mul_8u_8_00006_1_t, W
	ADDWF CompTempVarRet375, F
	BTFSC gbl_status,0
	INCF CompTempVarRet375+D'1', F
	MOVF __mul_8u_8_00006_1_t+D'1', W
	ADDWF CompTempVarRet375+D'1', F
label9
	RRF __mul_8u_8_00006_arg_b, F
	BCF gbl_status,0
	RLF __mul_8u_8_00006_1_t, F
	RLF __mul_8u_8_00006_1_t+D'1', F
	INCF __mul_8u_8_00006_1_i, F
	GOTO	label8
; } __mul_8u_8u function end

	ORG 0x00000057
out_portb_00000
; { out_portb ; function begin
	MOVLW 0x1E
	MOVWF out_portb_00000_1_base
	MOVLW 0x0F
	MOVWF out_portb_00000_1_interval
	MOVLW 0x0F
	ANDWF out_portb_00000_arg_buf, W
	MOVWF out_portb_00000_arg_buf
	MOVF out_portb_00000_arg_buf, W
	XORLW 0x08
	BTFSS STATUS,Z
	GOTO	label10
	CLRF out_portb_00000_1_duty
	BCF gbl_portb,4
	BCF gbl_portb,5
	GOTO	label12
label10
	MOVF out_portb_00000_arg_buf, W
	SUBLW 0x08
	BTFSC STATUS,C
	GOTO	label11
	MOVLW 0x08
	SUBWF out_portb_00000_arg_buf, W
	MOVWF __mul_8u_8_00006_arg_b
	MOVF out_portb_00000_1_interval, W
	MOVWF __mul_8u_8_00006_arg_a
	CALL __mul_8u_8_00006
	MOVF CompTempVarRet375, W
	MOVWF CompTempVar580
	MOVF CompTempVarRet375+D'1', W
	MOVWF CompTempVar581
	MOVF CompTempVar580, W
	ADDWF out_portb_00000_1_base, W
	MOVWF out_portb_00000_1_duty
	BCF gbl_portb,4
	BSF gbl_portb,5
	GOTO	label12
label11
	MOVF out_portb_00000_arg_buf, W
	SUBLW 0x08
	MOVWF __mul_8u_8_00006_arg_b
	MOVF out_portb_00000_1_interval, W
	MOVWF __mul_8u_8_00006_arg_a
	CALL __mul_8u_8_00006
	MOVF CompTempVarRet375, W
	MOVWF CompTempVar583
	MOVF CompTempVarRet375+D'1', W
	MOVWF CompTempVar584
	MOVF CompTempVar583, W
	ADDWF out_portb_00000_1_base, W
	MOVWF out_portb_00000_1_duty
	BSF gbl_portb,4
	BCF gbl_portb,5
label12
	MOVF out_portb_00000_1_duty, W
	MOVWF gbl_ccpr1l
	RETURN
; } out_portb function end

	ORG 0x0000008C
find_zero_00000
; { find_zero ; function begin
label13
	CALL read_porta_00013
	MOVF CompTempVarRet585, F
	BTFSS STATUS,Z
	GOTO	label13
	RETURN
; } find_zero function end

	ORG 0x00000091
find_one_00000
; { find_one ; function begin
label14
	CALL read_porta_00013
	DECF CompTempVarRet585, W
	BTFSS STATUS,Z
	GOTO	label14
	RETURN
; } find_one function end

	ORG 0x00000096
main
; { main ; function begin
	MOVLW 0x70
	BSF STATUS, RP0
	BCF STATUS, RP1
	MOVWF gbl_osccon
	MOVLW 0x03
	MOVWF gbl_trisa
	CLRF gbl_trisb
	CLRF gbl_intcon
	MOVLW 0x46
	MOVWF gbl_adcon1
	MOVLW 0x0F
	BCF STATUS, RP0
	MOVWF gbl_ccp1con
	MOVLW 0xFF
	BSF STATUS, RP0
	MOVWF gbl_pr2
	MOVLW 0x07
	BCF STATUS, RP0
	MOVWF gbl_t2con
	CLRF gbl_ccpr1l
	CLRF gbl_portb
	CLRF gbl_porta
	CLRF main_1_status
	CLRF main_1_i
label15
	MOVLW 0x02
	SUBWF main_1_i, W
	BTFSC STATUS,C
	GOTO	label16
	BSF gbl_porta,2
	MOVLW 0xC8
	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
	MOVLW 0x96
	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
	BCF gbl_porta,2
	MOVLW 0xC8
	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
	MOVLW 0x96
	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
	INCF main_1_i, F
	GOTO	label15
label16
	MOVF main_1_status, W
	XORLW 0x00
	BTFSC STATUS,Z
	GOTO	label17
	XORLW 0x01
	BTFSC STATUS,Z
	GOTO	label18
	XORLW 0x03
	BTFSC STATUS,Z
	GOTO	label22
	XORLW 0x01
	BTFSC STATUS,Z
	GOTO	label25
	GOTO	label16
label17
	CALL find_zero_00000
	MOVLW 0x01
	MOVWF main_1_status
	GOTO	label16
label18
	CLRF main_1_count
label19
	CALL delay_100u_00014
	INCF main_1_count, F
	CALL read_porta_00013
	MOVF CompTempVarRet585, W
	MOVWF main_1_input
	MOVF main_1_input, W
	XORLW 0x02
	BTFSS STATUS,Z
	GOTO	label20
	CLRF main_1_status
	GOTO	label16
label20
	DECF main_1_input, W
	BTFSS STATUS,Z
	GOTO	label19
	MOVF main_1_count, W
	SUBLW 0x28
	BTFSC STATUS,C
	GOTO	label21
	MOVLW 0x02
	MOVWF main_1_status
	CLRF main_1_count
	GOTO	label16
label21
	CLRF main_1_status
	GOTO	label16
label22
	CALL delay_100u_00014
	INCF main_1_count, F
	CALL read_porta_00013
	MOVF CompTempVarRet585, W
	MOVWF main_1_input
	MOVF main_1_input, W
	XORLW 0x02
	BTFSS STATUS,Z
	GOTO	label23
	CLRF main_1_status
	GOTO	label16
label23
	MOVF main_1_input, F
	BTFSS STATUS,Z
	GOTO	label22
	MOVF main_1_count, W
	SUBLW 0x14
	BTFSC STATUS,C
	GOTO	label24
	MOVLW 0x03
	MOVWF main_1_status
	GOTO	label16
label24
	CLRF main_1_status
	GOTO	label16
label25
	CLRF main_1_buf
	MOVLW 0x80
	MOVWF main_1_recv_bit
	CLRF main_1_i
label26
	MOVLW 0x08
	SUBWF main_1_i, W
	BTFSC STATUS,C
	GOTO	label32
	CALL find_one_00000
	CLRF main_1_count
label27
	CALL delay_100u_00014
	INCF main_1_count, F
	CALL read_porta_00013
	MOVF CompTempVarRet585, W
	MOVWF main_1_input
	MOVF main_1_count, W
	SUBLW 0x14
	BTFSC STATUS,C
	GOTO	label28
	CLRF main_1_status
	GOTO	label30
label28
	MOVF main_1_input, W
	XORLW 0x02
	BTFSS STATUS,Z
	GOTO	label29
	CLRF main_1_status
	GOTO	label30
label29
	MOVF main_1_input, F
	BTFSS STATUS,Z
	GOTO	label27
label30
	MOVLW 0x07
	SUBWF main_1_count, W
	BTFSS STATUS,C
	GOTO	label31
	MOVF main_1_recv_bit, W
	ADDWF main_1_buf, W
	MOVWF main_1_buf
label31
	MOVF main_1_recv_bit, F
	BCF STATUS,C
	RRF main_1_recv_bit, F
	INCF main_1_i, F
	GOTO	label26
label32
	MOVF main_1_buf, W
	MOVWF out_portb_00000_arg_buf
	CALL out_portb_00000
	CLRF main_1_status
	GOTO	label16
; } main function end

	ORG 0x00000133
_startup
	BCF PCLATH,3
	BCF PCLATH,4
	GOTO	main
	ORG 0x00002007
	DW 0x3F10
	END
