/* * Title: Ultrasound * * Author: Blake C. Sutton * * This is a set of functions used to test and read input from * a SRF04 ultrasound ranger connected to a port on the Mavric IIB. * It will have functions to tell the SRF04 to send a pulse out, * read the data back (by counting the cycles the SRF04 output pin * is high ), and be able to display this value on the LCD * * Pulse Trigger input (to SRF04) : Port D, pin 0 * Echo output (to Mavric II) : Port D, pin 1 */ #ifndef __Ultrasound__ #define __Ultrasound__ #include "LCD_Routines.h" #define PULSE_TRIGGER (0x01) #define ECHO_OUTPUT (0x02) //Length of array of sonar readings #define ARRAY_LENGTH 2 //Constants defining thresholds of closeness to an object #define VERY_NEAR 0x00A5 #define NEAR 0x00A8 /* 16-bit unsigned integer used for ultrasound timing */ volatile uint16_t ultrasound_count; /* Array holding the last ARRAY_LENGTH readings from the SRF04 */ volatile uint16_t sonar_readings [ARRAY_LENGTH]; volatile uint8_t sonar_readings_ct; //Internal use only void init_ultrasound_timer(void); //Use this with other port initializing functions void init_ultrasound_port(void); //Internal use only - consider modifying internal 1ms delay void send_pulse(void); //Call this in the main loop to keep updating the sonar with //pings and readings back. Results are added to the sonar_readings //array above. void update_sonar(void); #endif