/* Author: Andrew Wilson Date : April 18, 2006 Purpose: This program was written to multiplex output from several sonar units (Maxbotix) into one single serial data stream to interface with a PC */ #include <18F1320.h> #define CLOCKRATE 8000000 #define SONAR_1_XMIT PIN_A3 //the output of the sonar #define SONAR_1_RCV PIN_A2 //the input of the sonar #define SONAR_2_XMIT PIN_A1 //the output of the sonar #define SONAR_2_RCV PIN_A0 //the input of the sonar #fuses INTRC, NOWDT #use delay(clock=CLOCKRATE) #use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B4, stream=PC) //Software RS-232 Ports #use rs232(baud=9600, INVERT, BITS = 8, PARITY = N, rcv=SONAR_1_XMIT, stream=sonar1) #use rs232(baud=9600, INVERT, BITS = 8, PARITY = N, rcv=SONAR_2_XMIT, stream=sonar2) void main() { char c; char reading[10]; fprintf(PC, "Sonar MUX v.1\n\r"); fprintf(PC, "Author: Andrew Wilson 5/2006\n\r"); fprintf(PC, "reconnsworld.com\n\r"); delay_ms(1000); while(1) { //send signal for read //then read, this will block //when the value is read, read from the next stream //when all sonar units are read from, parse output stream // and print output strings //----------beg block code----------- output_high(SONAR_1_RCV); c = fgetc(sonar1); while(c != 'R') { c = fgetc(sonar1); } reading[0] = fgetc(sonar1); reading[1] = fgetc(sonar1); reading[2] = fgetc(sonar1); reading[3] = '\0'; fprintf(PC, "sonar1: %s\n\r", reading); output_low(SONAR_1_RCV); //----------end block code----------- //----------beg block code----------- output_high(SONAR_2_RCV); c = fgetc(sonar2); while(c != 'R') { c = fgetc(sonar1); } reading[0] = fgetc(sonar2); reading[1] = fgetc(sonar2); reading[2] = fgetc(sonar2); reading[3] = '\0'; fprintf(PC, "sonar2: %s\n\r", reading); output_low(SONAR_2_RCV); //----------end block code----------- } }