'------------------------------------------------------- ' Name : turtle-trans.bas ' Compiler : PicBasic Pro - MicroEngineering Labs ' Notes : Robot control using the Linx 433LC series ' : transmitter and receiver. ' : Using on-chip analog to digital converters ' : of the PIC 16C71 to read the position of ' : the two control stick potentiometers. '------------------------------------------------------- ' set PortA inputs. trisa = %00011111 ' PortB set as outputs. Pin 2 input trisb = %00000100 '------------------------------------------------------ ' initialize variables include "modedefs.bas" tx_baud CON N2400 pot_y VAR PORTA.0 pot_x VAR PORTA.1 txmit VAR portB.0 txmit_led VAR portB.1 push_button VAR PORTB.2 val_y VAR BYTE val_x VAR BYTE '------------------------------------------------------ ' Set up the analog to digital converters DEFINE ADC_BITS 8 ' Set number of bits in result DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3) DEFINE ADC_SAMPLEUS 10 ' Set sampling time in microseconds ADCON1 = 2 ' Set porta pins 0 and 1 to analog start: low txmit_led ADCIN 0,val_y ' read A/D converter - porta.pin 0 ADCIN 1,val_x ' read A/D converter - porta.pin 1 If val_y < 20 then high txmit_led serout txmit,tx_baud,["ZA"] endif If val_y > 200 then high txmit_led serout txmit,tx_baud,["ZB"] endif If val_X < 20 then high txmit_led serout txmit,tx_baud,["ZC"] endif If val_X > 200 then high txmit_led serout txmit,tx_baud,["ZD"] endif If push_button = 1 then high txmit_led serout txmit,tx_baud,["ZE"] endif If ((val_y > 25) and (val_y < 190)) or ((val_x > 25) and (val_x < 190)) then serout txmit,tx_baud,["ZF"] endif goto start