'------------------------------------------------------- ' Name : tx-remote.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. '------------------------------------------------------- ' PIC 16C71 A/D converter registers ' ' PORTA = 05 hex = 5 dec ' five I/O lines RA0 RA1 RA2 RA3 RA4 ' ' TRISA = 85 hex = 133 dec ' data direction register ' ---1 1111 inputs ' ---0 0000 outputs ' ' ADCON1 = 88 hex = 136 dec ' configure as A to D converter or digital I/O ' bits RA0,RA1 RA2 RA3 Vref ' ---- --00 analog analog analog VDD ' ---- --01 analog analog ref input RA3 ' ---- --10 analog digital digital VDD ' ---- --11 digital digital digital VDD ' ' ADCON0 = 08 hex = 8 dec ' A/D control and status register - 8 bits ' bit7 - ADCS1 ' BIT6 - ADCS0 ' bit5 - reserved ' bit4 - CHS1 ' bit3 - CHS0 ' bit2 - GO/DONE ' bit1 - ADIF ' bit0 - ADON ' ADCS1 and ADCS2 - bit7 and bit6 ' A/D conversion clock select: ' ADCS1,0 = 00: fosc/2 ' 01: fosc/8 ' 10: fosc/32 ' 11: f rc (derived from internal ' rc oscillator) ' bit5 - reserved ' Analog channel select - bit4 and bit3 ' CHS1, CHS0 = 00: channel 0 (AIN0) ' 01: channel 1 (AIN1) ' 10: channel 2 (AIN2) ' 11: channel 3 (AIN3) ' GO/DONE - bit2: must be set to begin a ' conversion. It is automatically ' reset in hardware when conversion ' is done. ' ADIF - bit1: A/D conversion complete interupt flag bit. Set ' when conversion is completed. Reset in software. ' ADON - bit0: If ADON = 0 A/D converter module is shut off and ' consumes no operating current. ADON = 1 A/D ' converter module is on. ' ' ADRES = 09 hex = 9 dec ' A/D conversion result register ' ' INTCON = 0B hex = 11 dec ' interupt control register '------------------------------------------------------ ' 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