
; PicBasic Pro Compiler 2.42a, (c) 1998, 2002 microEngineering Labs, Inc. All Rights Reserved. 
PM_USED			EQU	1

	INCLUDE	"PBPPROC.INC"


; Define statements.
#define		ADC_BITS			8	
#define		ADC_CLOCK			3	
#define		ADC_SAMPLEUS			50	

RAM_START       		EQU	0000Ch
RAM_END         		EQU	0004Fh
RAM_BANKS       		EQU	00001h
BANK0_START     		EQU	0000Ch
BANK0_END       		EQU	0004Fh
EEPROM_START    		EQU	02100h
EEPROM_END      		EQU	0213Fh

R0              		EQU	RAM_START + 000h
R1              		EQU	RAM_START + 002h
R2              		EQU	RAM_START + 004h
R3              		EQU	RAM_START + 006h
R4              		EQU	RAM_START + 008h
R5              		EQU	RAM_START + 00Ah
R6              		EQU	RAM_START + 00Ch
R7              		EQU	RAM_START + 00Eh
R8              		EQU	RAM_START + 010h
T1              		EQU	RAM_START + 012h
T2              		EQU	RAM_START + 014h
T3              		EQU	RAM_START + 016h
FLAGS           		EQU	RAM_START + 018h
GOP             		EQU	RAM_START + 019h
RM1             		EQU	RAM_START + 01Ah
RM2             		EQU	RAM_START + 01Bh
RR1             		EQU	RAM_START + 01Ch
RR2             		EQU	RAM_START + 01Dh
_BckTime         		EQU	RAM_START + 01Eh
_Cntr            		EQU	RAM_START + 020h
_Cruisetime      		EQU	RAM_START + 022h
_dutyl           		EQU	RAM_START + 024h
_dutyr           		EQU	RAM_START + 026h
_IDtime          		EQU	RAM_START + 028h
_pspin           		EQU	RAM_START + 02Ah
_RecTime         		EQU	RAM_START + 02Ch
_ADCntr          		EQU	RAM_START + 02Eh
_ADleft          		EQU	RAM_START + 02Fh
_ADRight         		EQU	RAM_START + 030h
PB01            		EQU	RAM_START + 031h
_Pyro            		EQU	RAM_START + 032h
_trntime         		EQU	RAM_START + 033h
_PORTL           		EQU	 PORTB
_PORTH           		EQU	 PORTA
_TRISL           		EQU	 TRISB
_TRISH           		EQU	 TRISA
#define _LCD             	_PORTB_0
#define _trndir          	 PB01, 006h
#define _Lbump           	 PB01, 002h
#define _Rbump           	 PB01, 004h
#define _Bbump           	 PB01, 000h
#define _ID              	 PB01, 001h
#define _RecOut          	 PB01, 005h
#define _pour            	 PB01, 003h
#define _PORTB_0         	 PORTB, 000h
#define _TRISC_2         	 TRISC, 002h
#define _TRISC_1         	 TRISC, 001h
#define _CCP1CON_4       	 CCP1CON, 004h
#define _dutyr_0         	_dutyr, 000h
#define _CCP1CON_5       	 CCP1CON, 005h
#define _dutyr_1         	_dutyr, 001h
#define _CCP2CON_4       	 CCP2CON, 004h
#define _dutyl_0         	_dutyl, 000h
#define _CCP2CON_5       	 CCP2CON, 005h
#define _dutyl_1         	_dutyl, 001h
#define _PORTB_5         	 PORTB, 005h
#define _PORTB_3         	 PORTB, 003h
#define _PORTB_7         	 PORTB, 007h
#define _PORTB_2         	 PORTB, 002h
#define _PORTB_6         	 PORTB, 006h
#define _PORTB_4         	 PORTB, 004h
#define _PORTD_0         	 PORTD, 000h
#define _PORTD_1         	 PORTD, 001h
#define _PORTD_2         	 PORTD, 002h
#define _trntime_1       	_trntime, 001h
#define _PORTC_7         	 PORTC, 007h
#define _PORTC_6         	 PORTC, 006h
#define _PORTC_5         	 PORTC, 005h
#define _PORTC_4         	 PORTC, 004h
	INCLUDE	"BEERBOT5.MAC"
	INCLUDE	"PBPPIC14.LIB"

	MOVE?CT	000h, _TRISC_2
	MOVE?CB	00Ch, CCP1CON
	MOVE?CB	005h, T2CON
	MOVE?CT	000h, _TRISC_1
	MOVE?CB	00Ch, CCP2CON
	MOVE?CB	0F9h, PR2
	MOVE?CW	01Eh, _dutyr
	MOVE?CW	078h, _dutyl
	MOVE?TT	_dutyr_0, _CCP1CON_4
	MOVE?TT	_dutyr_1, _CCP1CON_5
	SHIFTR?WCB	_dutyr, 002h, CCPR1L
	MOVE?TT	_dutyl_0, _CCP2CON_4
	MOVE?TT	_dutyl_1, _CCP2CON_5
	SHIFTR?WCB	_dutyl, 002h, CCPR2L
	OUTPUT?T	_LCD
	LOW?T	_LCD
	PAUSE?C	032h
	SERPIN?T	_LCD
	SERMODE?C	002h
	SEROUT?C	0FEh
	SEROUT?C	001h
	MOVE?CB	0FFh, TRISA
	MOVE?CB	002h, ADCON1
	PAUSE?C	001F4h

	LABEL?L	_loop2	
	ADCIN?CB	003h, _Pyro
	GOSUB?L	_DisPyro
	PAUSE?C	032h
	LABEL?L	L00001	
	CMPGE?BCL	_Pyro, 07Eh, L00002
	GOTO?L	_loop2
	GOTO?L	L00001
	LABEL?L	L00002	

	LABEL?L	_loop3	
	GOSUB?L	_pfind
	GOSUB?L	_getperson
	GOSUB?L	_Identify
	CMPNE?TCL	_ID, 001h, L00003
	GOSUB?L	_offer
	GOTO?L	L00004
	LABEL?L	L00003	
	GOSUB?L	_message4
	GOSUB?L	_ObsAvoid
	LABEL?L	L00004	
	CMPNE?TCL	_pour, 001h, L00005
	GOSUB?L	_waitn
	GOTO?L	L00006
	LABEL?L	L00005	
	LABEL?L	L00006	
	GOSUB?L	_ObsAvoid
	GOTO?L	_loop3
	END?	

	LABEL?L	_DisplayLR	
	SERPIN?T	_LCD
	SERMODE?C	002h
	SEROUT?C	0FEh
	SEROUT?C	001h
	PAUSE?C	00Ah
	SERPIN?T	_LCD
	SERMODE?C	002h
	SEROUT?C	04Ch
	SEROUT?C	065h
	SEROUT?C	066h
	SEROUT?C	074h
	SEROUT?C	020h
	SEROUT?C	049h
	SEROUT?C	052h
	SEROUT?C	03Ah
	SEROUT?C	020h
	DIG?BCW	_ADleft, 002h, T1
	SEROUTD?W	T1
	DIG?BCW	_ADleft, 001h, T1
	SEROUTD?W	T1
	DIG?BCW	_ADleft, 000h, T1
	SEROUTD?W	T1
	SERPIN?T	_LCD
	SERMODE?C	002h
	SEROUT?C	0FEh
	SEROUT?C	0C0h
	SERPIN?T	_LCD
	SERMODE?C	002h
	SEROUT?C	052h
	SEROUT?C	069h
	SEROUT?C	067h
	SEROUT?C	068h
	SEROUT?C	074h
	SEROUT?C	020h
	SEROUT?C	049h
	SEROUT?C	052h
	SEROUT?C	03Ah
	SEROUT?C	020h
	DIG?BCW	_ADRight, 002h, T1
	SEROUTD?W	T1
	DIG?BCW	_ADRight, 001h, T1
	SEROUTD?W	T1
	DIG?BCW	_ADRight, 000h, T1
	SEROUTD?W	T1
	RETURN?	

	LABEL?L	_DisPyro	
	ADCIN?CB	003h, _Pyro
	ADCIN?CB	001h, _ADCntr
	SERPIN?T	_LCD
	SERMODE?C	002h
	SEROUT?C	0FEh
	SEROUT?C	001h
	PAUSE?C	00Ah
	SERPIN?T	_LCD
	SERMODE?C	002h
	SEROUT?C	050h
	SEROUT?C	079h
	SEROUT?C	072h
	SEROUT?C	06Fh
	SEROUT?C	03Ah
	SEROUT?C	020h
	DIG?BCW	_Pyro, 002h, T1
	SEROUTD?W	T1
	DIG?BCW	_Pyro, 001h, T1
	SEROUTD?W	T1
	DIG?BCW	_Pyro, 000h, T1
	SEROUTD?W	T1
	RETURN?	

	LABEL?L	_Forward	
	GOSUB?L	_RmotorGo
	GOSUB?L	_LmotorGo
	RETURN?	

	LABEL?L	_RmotorStop	
	LOW?T	_PORTB_5
	PAUSE?C	00Ah
	LOW?T	_PORTB_3
	LOW?T	_PORTB_7
	PAUSE?C	00Ah
	RETURN?	

	LABEL?L	_RmotorGo	
	LOW?T	_PORTB_3
	HIGH?T	_PORTB_7
	PAUSE?C	00Ah
	HIGH?T	_PORTB_5
	PAUSE?C	00Ah
	RETURN?	

	LABEL?L	_LmotorStop	
	LOW?T	_PORTB_2
	PAUSE?C	00Ah
	LOW?T	_PORTB_6
	LOW?T	_PORTB_4
	PAUSE?C	00Ah
	RETURN?	

	LABEL?L	_LmotorGo	
	LOW?T	_PORTB_6
	HIGH?T	_PORTB_4
	PAUSE?C	00Ah
	HIGH?T	_PORTB_2
	PAUSE?C	00Ah
	RETURN?	

	LABEL?L	_ObsAvoid	
	MOVE?CW	06Eh, _Cruisetime
	LABEL?L	L00007	
	CMPLE?WCL	_Cruisetime, 000h, L00008
	SUB?WCW	_Cruisetime, 001h, _Cruisetime
	PAUSE?C	064h
	ADCIN?CB	000h, _ADleft
	ADCIN?CB	001h, _ADCntr
	ADCIN?CB	002h, _ADRight
	MOVE?TT	_PORTD_0, _Lbump
	MOVE?TT	_PORTD_1, _Rbump
	CMPGT?BCB	_ADCntr, 032h, T1
	CMPEQ?TCB	_Lbump, 001h, T2
	LOR?BBW	T1, T2, T2
	CMPEQ?TCB	_Rbump, 001h, T3
	LOR?WBW	T2, T3, T3
	CMPF?WL	T3, L00009
	RANDOM?B	_trntime
	LOW?T	_PORTB_5
	LOW?T	_PORTB_2
	PAUSE?C	001F4h
	HIGH?T	_PORTB_3
	LOW?T	_PORTB_7
	HIGH?T	_PORTB_6
	LOW?T	_PORTB_4
	HIGH?T	_PORTB_5
	HIGH?T	_PORTB_2
	MOVE?CW	003E8h, _BckTime
	LABEL?L	L00011	
	CMPLE?WCL	_BckTime, 000h, L00012
	PAUSE?C	001h
	SUB?WCW	_BckTime, 001h, _BckTime
	MOVE?TT	_PORTD_2, _Bbump
	CMPNE?TCL	_Bbump, 001h, L00013
	MOVE?CW	000h, _BckTime
	GOTO?L	L00014
	LABEL?L	L00013	
	LABEL?L	L00014	
	GOTO?L	L00011
	LABEL?L	L00012	
	MOVE?TT	_trntime_1, _trndir
	CMPNE?TCL	_trndir, 001h, L00015
	LOW?T	_PORTB_5
	GOTO?L	L00016
	LABEL?L	L00015	
	LOW?T	_PORTB_2
	LABEL?L	L00016	
	PAUSE?C	002EEh
	PAUSE?B	_trntime
	LOW?T	_PORTB_5
	LOW?T	_PORTB_2
	LABEL?L	L00009	
	CMPLE?BCL	_ADleft, 032h, L00017
	GOSUB?L	_RmotorStop
	GOTO?L	L00018
	LABEL?L	L00017	
	GOSUB?L	_RmotorGo
	LABEL?L	L00018	
	CMPLE?BCL	_ADRight, 032h, L00019
	GOSUB?L	_LmotorStop
	GOTO?L	L00020
	LABEL?L	L00019	
	GOSUB?L	_LmotorGo
	LABEL?L	L00020	
	GOTO?L	L00007
	LABEL?L	L00008	
	RETURN?	

	LABEL?L	_pfind	
	MOVE?CW	096h, _pspin
	ADCIN?CB	000h, _ADleft
	ADCIN?CB	001h, _ADCntr
	ADCIN?CB	002h, _ADRight
	ADCIN?CB	003h, _Pyro
	GOSUB?L	_LmotorStop
	GOSUB?L	_RmotorGo
	LABEL?L	L00021	
	CMPGT?BCB	_Pyro, 076h, T1
	CMPLT?BCB	_Pyro, 08Ah, T2
	LAND?BBW	T1, T2, T2
	CMPGT?WCB	_pspin, 000h, T3
	LAND?WBW	T2, T3, T3
	CMPF?WL	T3, L00022
	SUB?WCW	_pspin, 001h, _pspin
	PAUSE?C	064h
	ADCIN?CB	003h, _Pyro
	ADCIN?CB	001h, _ADCntr
	MOVE?TT	_PORTD_0, _Lbump
	MOVE?TT	_PORTD_1, _Rbump
	CMPGT?BCB	_ADCntr, 032h, T1
	CMPEQ?TCB	_Lbump, 001h, T2
	LOR?BBW	T1, T2, T2
	CMPEQ?TCB	_Rbump, 001h, T3
	LOR?WBW	T2, T3, T3
	CMPF?WL	T3, L00023
	MOVE?CB	064h, _Pyro
	GOTO?L	L00024
	LABEL?L	L00023	
	LABEL?L	L00024	
	GOTO?L	L00021
	LABEL?L	L00022	
	GOSUB?L	_RmotorStop
	RETURN?	

	LABEL?L	_getperson	

	LABEL?L	_keepgoing	
	ADCIN?CB	000h, _ADleft
	ADCIN?CB	001h, _ADCntr
	ADCIN?CB	002h, _ADRight
	MOVE?TT	_PORTD_0, _Lbump
	MOVE?TT	_PORTD_1, _Rbump
	GOSUB?L	_LmotorGo
	GOSUB?L	_RmotorGo
	CMPGT?BCB	_ADCntr, 032h, T1
	CMPGT?BCB	_ADleft, 032h, T2
	LOR?BBW	T1, T2, T2
	CMPGT?BCB	_ADRight, 032h, T3
	LOR?WBW	T2, T3, T3
	CMPF?WL	T3, L00025
	GOSUB?L	_RmotorStop
	GOSUB?L	_LmotorStop
	GOTO?L	L00026
	LABEL?L	L00025	
	GOTO?L	_keepgoing
	LABEL?L	L00026	
	RETURN?	

	LABEL?L	_Identify	
	CMPLE?BCL	_ADleft, 032h, L00027
	GOSUB?L	_RmotorGo
	GOTO?L	L00028
	LABEL?L	L00027	
	GOSUB?L	_LmotorGo
	LABEL?L	L00028	
	MOVE?CW	001F4h, _IDtime
	LABEL?L	L00029	
	CMPLE?WCL	_IDtime, 000h, L00030
	ADCIN?CB	003h, _Pyro
	SUB?WCW	_IDtime, 001h, _IDtime
	PAUSE?C	002h
	CMPLT?BCB	_Pyro, 076h, T1
	CMPGT?BCB	_Pyro, 08Ah, T2
	LOR?BBW	T1, T2, T2
	CMPF?WL	T2, L00031
	MOVE?CT	001h, _ID
	MOVE?CW	000h, _IDtime
	GOTO?L	L00032
	LABEL?L	L00031	
	MOVE?CT	000h, _ID
	LABEL?L	L00032	
	GOTO?L	L00029
	LABEL?L	L00030	
	GOSUB?L	_RmotorStop
	GOSUB?L	_LmotorStop
	RETURN?	

	LABEL?L	_offer	
	GOSUB?L	_message1
	MOVE?CT	000h, _RecOut
	MOVE?CW	0EA60h, _RecTime
	MOVE?TT	_PORTC_7, _RecOut
	LABEL?L	L00033	
	CMPGT?WCB	_RecTime, 000h, T1
	CMPEQ?TCB	_RecOut, 000h, T2
	LAND?BBW	T1, T2, T2
	CMPF?WL	T2, L00034
	SUB?WCW	_RecTime, 001h, _RecTime
	MOVE?TT	_PORTC_7, _RecOut
	GOTO?L	L00033
	LABEL?L	L00034	
	CMPNE?TCL	_RecOut, 001h, L00035
	GOSUB?L	_message2
	MOVE?CT	001h, _pour
	GOTO?L	L00036
	LABEL?L	L00035	
	GOSUB?L	_message3
	MOVE?CT	000h, _pour
	LABEL?L	L00036	
	RETURN?	

	LABEL?L	_waitn	
	MOVE?CT	000h, _RecOut
	GOSUB?L	_message5
	PAUSE?C	01F40h
	GOSUB?L	_message7
	PAUSE?C	00FA0h
	GOSUB?L	_message6
	LABEL?L	L00037	
	CMPNE?TCL	_RecOut, 000h, L00038
	MOVE?TT	_PORTC_7, _RecOut
	GOTO?L	L00037
	LABEL?L	L00038	
	MOVE?CT	000h, _pour
	MOVE?CT	000h, _RecOut
	RETURN?	

	LABEL?L	_showIRnBump	
	SERPIN?T	_LCD
	SERMODE?C	002h
	SEROUT?C	0FEh
	SEROUT?C	001h
	PAUSE?C	00Ah
	SERPIN?T	_LCD
	SERMODE?C	002h
	SEROUT?C	04Ch
	SEROUT?C	03Ah
	SEROUT?C	020h
	SEROUTD?T	_Lbump
	SEROUT?C	020h
	SEROUT?C	043h
	SEROUT?C	03Ah
	SEROUT?C	020h
	DIG?BCW	_ADCntr, 002h, T1
	SEROUTD?W	T1
	DIG?BCW	_ADCntr, 001h, T1
	SEROUTD?W	T1
	DIG?BCW	_ADCntr, 000h, T1
	SEROUTD?W	T1
	SERPIN?T	_LCD
	SERMODE?C	002h
	SEROUT?C	0FEh
	SEROUT?C	0C0h
	SERPIN?T	_LCD
	SERMODE?C	002h
	SEROUT?C	052h
	SEROUT?C	03Ah
	SEROUT?C	020h
	SEROUTD?T	_Rbump
	SEROUT?C	050h
	SEROUT?C	03Ah
	SEROUT?C	020h
	DIG?BCW	_Pyro, 002h, T1
	SEROUTD?W	T1
	DIG?BCW	_Pyro, 001h, T1
	SEROUTD?W	T1
	DIG?BCW	_Pyro, 000h, T1
	SEROUTD?W	T1
	RETURN?	

	LABEL?L	_message1	
	HIGH?T	_PORTC_6
	PAUSE?C	064h
	LOW?T	_PORTC_6
	HIGH?T	_PORTC_5
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	00BB8h
	RETURN?	

	LABEL?L	_message2	
	HIGH?T	_PORTC_6
	PAUSE?C	001F4h
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_6
	PAUSE?C	064h
	HIGH?T	_PORTC_4
	PAUSE?C	001F4h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_4
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	00BB8h
	RETURN?	

	LABEL?L	_message3	
	HIGH?T	_PORTC_6
	PAUSE?C	001F4h
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_6
	PAUSE?C	064h
	HIGH?T	_PORTC_4
	PAUSE?C	001F4h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_4
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	00BB8h
	RETURN?	

	LABEL?L	_message4	
	HIGH?T	_PORTC_6
	PAUSE?C	001F4h
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_6
	PAUSE?C	064h
	HIGH?T	_PORTC_4
	PAUSE?C	001F4h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_4
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	00BB8h
	RETURN?	

	LABEL?L	_message5	
	HIGH?T	_PORTC_6
	PAUSE?C	001F4h
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_6
	PAUSE?C	064h
	HIGH?T	_PORTC_4
	PAUSE?C	001F4h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_4
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	00BB8h
	RETURN?	

	LABEL?L	_message6	
	HIGH?T	_PORTC_6
	PAUSE?C	001F4h
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_6
	PAUSE?C	064h
	HIGH?T	_PORTC_4
	PAUSE?C	001F4h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_4
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	00BB8h
	RETURN?	

	LABEL?L	_message7	
	HIGH?T	_PORTC_6
	PAUSE?C	001F4h
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_6
	PAUSE?C	064h
	HIGH?T	_PORTC_4
	PAUSE?C	001F4h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	064h
	LOW?T	_PORTC_4
	PAUSE?C	064h
	LOW?T	_PORTC_5
	HIGH?T	_PORTC_5
	PAUSE?C	00BB8h
	RETURN?	

	END
