Page 288 - Amphibionics : Build Your Own Biologically Inspired Robot
P. 288
Amphibionics 06 3/24/03 9:02 AM Page 267
Chapter 6 / Crocobot: Build Your Own Robotic Crocodile
' PortB set as outputs. Pin 2 input
tx-remote.bas program
listing (continued)
trisb = %00000100 PROGRAM 6.13
'------------------------------------------------------------------------------------------------------------------------------
' 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
control 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"]
267