Hello everyone ,
I am working on a robot which is autonomous hence need an obstacle avoidance mechanism hence i chose ultrasonic sensor for the robot and used this circuit :-
https://www.micro-examples.com/pics/090-ULTRASONIC-RANGER-schematic.png
i wrote this code to check whether the circuit's transmitter is working perfectly
#include <htc.h>
/*
* 16F877A test code for ultrasonic sensor
* This code will generate a 250Hz square
* wave signal on RC2, which should be fed
* to the input of the ultrasonic sensor
*/
/*
* Low Voltage Programming Off
* Code Protection Off
* Data Code Protection Off
* Write Protection Off
* Brown Out Reset Off
* Power Up Timer On
* Watchdog Timer Off
* High Speed Oscillator (10MHz)
*/
__CONFIG(LVPDIS & BORDIS & PWRTEN & WDTDIS & HS);
#define _XTAL_FREQ 10000000 //10Mhz Fosc for delay routine calculations
void main(void)
{
PORTA = 0; //clear port output latches
PORTB = 0;
PORTC = 0;
PORTD = 0;
ADCON1 = 0x06; //all ports digital I/O mode
TRISA = 0; //RA0-RA5 output
TRISB = 0; //RB0 - RB7 output
TRISC = 0; //RC0-RC7 output
TRISD = 0; //RD0-RD7 output
while(1)
{
RC2 = 1; //generate 250Hz square wave
__delay_ms(2); //2mS delay per state change for period of 4mS total
RC2 = 0;
__delay_ms(2);
}
}
it din't produce any sound but for 15KHzand 20KHz yess it did
now i want to interface thic circuit to my PIC 16F877A's RA1 to obtain the distance value in RB5
(I am using MPLAB IDE v8.63 and Hi Tech C v 9.80 complier )
somebody please help me with the coding
thanks
I am working on a robot which is autonomous hence need an obstacle avoidance mechanism hence i chose ultrasonic sensor for the robot and used this circuit :-
https://www.micro-examples.com/pics/090-ULTRASONIC-RANGER-schematic.png
i wrote this code to check whether the circuit's transmitter is working perfectly
#include <htc.h>
/*
* 16F877A test code for ultrasonic sensor
* This code will generate a 250Hz square
* wave signal on RC2, which should be fed
* to the input of the ultrasonic sensor
*/
/*
* Low Voltage Programming Off
* Code Protection Off
* Data Code Protection Off
* Write Protection Off
* Brown Out Reset Off
* Power Up Timer On
* Watchdog Timer Off
* High Speed Oscillator (10MHz)
*/
__CONFIG(LVPDIS & BORDIS & PWRTEN & WDTDIS & HS);
#define _XTAL_FREQ 10000000 //10Mhz Fosc for delay routine calculations
void main(void)
{
PORTA = 0; //clear port output latches
PORTB = 0;
PORTC = 0;
PORTD = 0;
ADCON1 = 0x06; //all ports digital I/O mode
TRISA = 0; //RA0-RA5 output
TRISB = 0; //RB0 - RB7 output
TRISC = 0; //RC0-RC7 output
TRISD = 0; //RD0-RD7 output
while(1)
{
RC2 = 1; //generate 250Hz square wave
__delay_ms(2); //2mS delay per state change for period of 4mS total
RC2 = 0;
__delay_ms(2);
}
}
it din't produce any sound but for 15KHzand 20KHz yess it did
now i want to interface thic circuit to my PIC 16F877A's RA1 to obtain the distance value in RB5
(I am using MPLAB IDE v8.63 and Hi Tech C v 9.80 complier )
somebody please help me with the coding
thanks