Page 327 - Amphibionics : Build Your Own Biologically Inspired Robot
P. 327
Amphibionics 07 3/24/03 9:13 AM Page 306
Amphibionics
PROGRAM 7.3
turtle-trans.bas listing
'------------------------------------------------------------------------------------------------------------------------------
(continued) 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
306