Page 331 - Amphibionics : Build Your Own Biologically Inspired Robot
P. 331
Amphibionics 07 3/24/03 9:13 AM Page 310
Amphibionics
and then program the PICmicro MCU 16F84 with the
sonar-test.hex file listed in Program 7.6. When the PIC is insert-
ed into the 18-pin socket on the main controller board and power
is applied, move your hand slowly toward the ranger and notice
that the tones produced by the PIC get lower the closer your hand
gets to the device. If no tones are produced when power is applied,
then check to make sure that none of the connections from the
sonar module to the controller board have been mixed up.
PROGRAM 7.5 '------------------------------------------------------------------------------------------------------------------------------
' Name : sonar-test.bas
sonar-test.bas program
listing ' Compiler : PicBasic Pro - MicroEngineering Labs
' Notes : Program control of the Devantech SRF04
' : ultrasonic module. Convert the raw distance
' : data to a frequency and output to the piezo
' : element.
'------------------------------------------------------------------------------------------------------------------------------
' PortA set as outputs. Pin 1 input.
trisa = %00000010
' PortB set as outputs.
trisb = %00000000
'------------------------------------------------------------------------------------------------------------------------------
' initialize variables
trigger VAR PORTA.0
echo VAR PORTA.1
piezo VAR PORTA.3
dist_raw VAR WORD
dist_inch VAR WORD
dist_cm VAR WORD
freq VAR WORD
conv_inch CON 15
conv_freq CON 6
310