
; PICBASIC PRO(TM) Compiler 2.50, (c) 1998, 2007 microEngineering Labs, Inc. All Rights Reserved.  
_USED			EQU	1

	INCLUDE	"D:\MICRO\PBP\16F819.INC"


; Define statements.
#define		OSC		 8
#define		ADC_BITS		 8        
#define		ADC_CLOCK		 1       
#define		ADC_SAMPLEUS		 50   

RAM_START       		EQU	00020h
RAM_END         		EQU	0016Fh
RAM_BANKS       		EQU	00003h
BANK0_START     		EQU	00020h
BANK0_END       		EQU	0007Fh
BANK1_START     		EQU	000A0h
BANK1_END       		EQU	000EFh
BANK2_START     		EQU	00120h
BANK2_END       		EQU	0016Fh
EEPROM_START    		EQU	02100h
EEPROM_END      		EQU	021FFh

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
FLAGS           		EQU	RAM_START + 012h
GOP             		EQU	RAM_START + 013h
RM1             		EQU	RAM_START + 014h
RM2             		EQU	RAM_START + 015h
RR1             		EQU	RAM_START + 016h
RR2             		EQU	RAM_START + 017h
T1              		EQU	RAM_START + 018h
T2              		EQU	RAM_START + 01Ah
_INFRARED        		EQU	RAM_START + 01Ch
_LEFT_POT        		EQU	RAM_START + 01Dh
_LEG_STOP_F      		EQU	RAM_START + 01Eh
_LEG_STOP_R      		EQU	RAM_START + 01Fh
PB01            		EQU	RAM_START + 020h
_RIGHT_POT       		EQU	RAM_START + 021h
_TEMP            		EQU	RAM_START + 022h
_VARIANCE        		EQU	RAM_START + 023h
_PORTL           		EQU	 PORTB
_PORTH           		EQU	 PORTA
_TRISL           		EQU	 TRISB
_TRISH           		EQU	 TRISA
#define _M1              	_PORTB??0
#define _M2              	_PORTB??1
#define _M3              	_PORTB??2
#define _M4              	_PORTB??3
#define _LED1            	_PORTB??4
#define _LED2            	_PORTB??5
#define _PIEZO           	_PORTB??6
#define _LCD             	_PORTB??7
#define _FLAG            	 PB01, 000h
#define _PORTB??0        	 PORTB, 000h
#define _PORTB??1        	 PORTB, 001h
#define _PORTB??2        	 PORTB, 002h
#define _PORTB??3        	 PORTB, 003h
#define _PORTB??4        	 PORTB, 004h
#define _PORTB??5        	 PORTB, 005h
#define _PORTB??6        	 PORTB, 006h
#define _PORTB??7        	 PORTB, 007h

; Constants.
_T2400           		EQU	00000h
_T1200           		EQU	00001h
_T9600           		EQU	00002h
_T300            		EQU	00003h
_N2400           		EQU	00004h
_N1200           		EQU	00005h
_N9600           		EQU	00006h
_N300            		EQU	00007h
_OT2400          		EQU	00008h
_OT1200          		EQU	00009h
_OT9600          		EQU	0000Ah
_OT300           		EQU	0000Bh
_ON2400          		EQU	0000Ch
_ON1200          		EQU	0000Dh
_ON9600          		EQU	0000Eh
_ON300           		EQU	0000Fh
_MSBPRE          		EQU	00000h
_LSBPRE          		EQU	00001h
_MSBPOST         		EQU	00002h
_LSBPOST         		EQU	00003h
_LSBFIRST        		EQU	00000h
_MSBFIRST        		EQU	00001h
_CLS             		EQU	00000h
_HOME            		EQU	00001h
_BELL            		EQU	00007h
_BKSP            		EQU	00008h
_TAB             		EQU	00009h
_CR              		EQU	0000Dh
_UnitOn          		EQU	00012h
_UnitOff         		EQU	0001Ah
_UnitsOff        		EQU	0001Ch
_LightsOn        		EQU	00014h
_LightsOff       		EQU	00010h
_Dim             		EQU	0001Eh
_Bright          		EQU	00016h
_LCD_BAUD        		EQU	00004h
	INCLUDE	"BIPED-~1.MAC"
	INCLUDE	"D:\MICRO\PBP\PBPPIC14.LIB"

	MOVE?CB	01Fh, TRISA
	MOVE?CB	000h, TRISB
	MOVE?CB	070h, OSCCON
	LOW?T	_M1
	LOW?T	_M2
	LOW?T	_M3
	LOW?T	_M4
	LOW?T	_LED1
	LOW?T	_LED2
	LOW?T	_PIEZO
	MOVE?CB	080h, _LEG_STOP_F
	MOVE?CB	077h, _LEG_STOP_R
	MOVE?CB	001h, _VARIANCE
	MOVE?CT	000h, _FLAG
	MOVE?CB	000h, ADCON1
	SOUNDPIN?T	_PIEZO
	SOUND?CC	064h, 00Ah
	SOUND?CC	05Ah, 005h
	SOUND?CC	050h, 005h
	SOUND?CC	06Eh, 00Ah

	LABEL?L	_START	
	SOUNDPIN?T	_PIEZO
	SOUND?CC	064h, 005h
	SOUND?CC	06Eh, 005h
	LOW?T	_LED1
	HIGH?T	_LED2
	GOSUB?L	_LEFT_FORWARD
	SOUNDPIN?T	_PIEZO
	SOUND?CC	050h, 005h
	SOUND?CC	05Ah, 005h
	LOW?T	_LED2
	HIGH?T	_LED1
	GOSUB?L	_RIGHT_FORWARD
	ADCIN?CB	002h, _INFRARED
	CMPGT?BCB	_INFRARED, 064h, T1
	CMPLT?BCB	_INFRARED, 082h, T2
	LAND?BBW	T1, T2, T2
	CMPF?WL	T2, L00001
	SOUNDPIN?T	_PIEZO
	SOUND?CC	064h, 00Ah
	SOUND?CC	05Ah, 005h
	SOUND?CC	064h, 005h
	SOUND?CC	06Eh, 00Ah
	SOUND?CC	050h, 014h
	SOUND?CC	05Ah, 014h
	ADD?TCT	_FLAG, 001h, _FLAG
	MOVE?CB	001h, _TEMP
	LABEL?L	L00003	
	CMPGT?BCL	_TEMP, 005h, L00004
	GOSUB?L	_LEFT_REVERSE
	GOSUB?L	_RIGHT_REVERSE
	NEXT?BCL	_TEMP, 001h, L00003
	LABEL?L	L00004	
	CMPF?TL	_FLAG, L00005
	MOVE?CB	001h, _TEMP
	LABEL?L	L00007	
	CMPGT?BCL	_TEMP, 005h, L00008
	GOSUB?L	_LEFT_REVERSE
	GOSUB?L	_RIGHT_FORWARD
	NEXT?BCL	_TEMP, 001h, L00007
	LABEL?L	L00008	
	GOTO?L	L00006
	LABEL?L	L00005	
	MOVE?CB	001h, _TEMP
	LABEL?L	L00009	
	CMPGT?BCL	_TEMP, 005h, L00010
	GOSUB?L	_RIGHT_REVERSE
	GOSUB?L	_LEFT_FORWARD
	NEXT?BCL	_TEMP, 001h, L00009
	LABEL?L	L00010	
	LABEL?L	L00006	
	LABEL?L	L00001	
	GOTO?L	_START
	END?	

	LABEL?L	_RIGHT_FORWARD	
	MOVE?CB	000h, _RIGHT_POT
	LOW?T	_M1
	LOW?T	_M2
	HIGH?T	_M2
	PAUSE?C	00190h
	LABEL?L	L00011	
	SUB?BBW	_LEG_STOP_F, _VARIANCE, T1
	CMPLT?BWB	_RIGHT_POT, T1, T1
	ADD?BBW	_LEG_STOP_F, _VARIANCE, T2
	CMPGT?BWB	_RIGHT_POT, T2, T2
	LOR?BBW	T1, T2, T2
	CMPF?WL	T2, L00012
	ADCIN?CB	001h, _RIGHT_POT
	GOTO?L	L00011
	LABEL?L	L00012	
	LOW?T	_M2
	RETURN?	

	LABEL?L	_RIGHT_REVERSE	
	MOVE?CB	000h, _RIGHT_POT
	LOW?T	_M1
	LOW?T	_M2
	HIGH?T	_M1
	PAUSE?C	0012Ch
	LABEL?L	L00013	
	SUB?BBW	_LEG_STOP_R, _VARIANCE, T1
	CMPLT?BWB	_RIGHT_POT, T1, T1
	ADD?BBW	_LEG_STOP_R, _VARIANCE, T2
	CMPGT?BWB	_RIGHT_POT, T2, T2
	LOR?BBW	T1, T2, T2
	CMPF?WL	T2, L00014
	ADCIN?CB	001h, _RIGHT_POT
	GOTO?L	L00013
	LABEL?L	L00014	
	LOW?T	_M1
	RETURN?	

	LABEL?L	_LEFT_FORWARD	
	MOVE?CB	000h, _LEFT_POT
	LOW?T	_M3
	LOW?T	_M4
	HIGH?T	_M3
	PAUSE?C	00190h
	LABEL?L	L00015	
	SUB?BBW	_LEG_STOP_F, _VARIANCE, T1
	CMPLT?BWB	_LEFT_POT, T1, T1
	ADD?BBW	_LEG_STOP_F, _VARIANCE, T2
	CMPGT?BWB	_LEFT_POT, T2, T2
	LOR?BBW	T1, T2, T2
	CMPF?WL	T2, L00016
	ADCIN?CB	000h, _LEFT_POT
	GOTO?L	L00015
	LABEL?L	L00016	
	LOW?T	_M3
	RETURN?	

	LABEL?L	_LEFT_REVERSE	
	MOVE?CB	000h, _LEFT_POT
	LOW?T	_M3
	LOW?T	_M4
	HIGH?T	_M4
	PAUSE?C	0012Ch
	LABEL?L	L00017	
	SUB?BBW	_LEG_STOP_R, _VARIANCE, T1
	CMPLT?BWB	_LEFT_POT, T1, T1
	ADD?BBW	_LEG_STOP_R, _VARIANCE, T2
	CMPGT?BWB	_LEFT_POT, T2, T2
	LOR?BBW	T1, T2, T2
	CMPF?WL	T2, L00018
	ADCIN?CB	000h, _LEFT_POT
	GOTO?L	L00017
	LABEL?L	L00018	
	LOW?T	_M4
	RETURN?	

	LABEL?L	_CALIBRATE	
	ADCIN?CB	000h, _LEFT_POT
	SERPIN?T	_LCD
	SERMODE?C	_LCD_BAUD
	SEROUT?C	0FEh
	SEROUT?C	080h
	SEROUT?C	04Ch
	SEROUT?C	03Ah
	SEROUTD?B	_LEFT_POT
	SEROUT?C	020h
	SEROUT?C	020h
	ADCIN?CB	001h, _RIGHT_POT
	SERPIN?T	_LCD
	SERMODE?C	_LCD_BAUD
	SEROUT?C	0FEh
	SEROUT?C	086h
	SEROUT?C	052h
	SEROUT?C	03Ah
	SEROUTD?B	_RIGHT_POT
	SEROUT?C	020h
	SEROUT?C	020h
	ADCIN?CB	002h, _INFRARED
	SERPIN?T	_LCD
	SERMODE?C	_LCD_BAUD
	SEROUT?C	0FEh
	SEROUT?C	0C0h
	SEROUT?C	049h
	SEROUT?C	052h
	SEROUT?C	03Ah
	SEROUTD?B	_INFRARED
	SEROUT?C	020h
	SEROUT?C	020h
	RETURN?	

	END
