captenusop WROTE:so i have modified to
void pulse ( void )// L-H-L
{ RB1=0;
__delay_us(10);
RB1=1;
__delay_us(10);
RB1=0;
__delay_us(10);
}
but stil not working
Your pulse is still wrong
Take a look at the arduino code
- CODE: SELECT_ALL_CODE
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
The Trigger pin is brought LOW for 2uS then HIGH for 10uS and then LOW again without any delay. The reason is very clear. After the pulse is sent, you should immediately starts monitoring the echo pin and starts the timer0/1 and then wait for the echo pin to go from H_L to stop the timer0/1. The (stop - start)uS reading of timer0/1 is critical for the calculation of the distance. Use timer0 (8 bit)if the distance you are interested is near and timer1 (16 bit) if object is far.
Not sure if HiTechC has the function PulseIn() like arduino. That would make things so much simpler. Or else, You would need to write a subroutine just to emulate pulsein(). Did you also set the TRISB for your RB0 and RB1?
Your "pulse" pin should be output and the "echo" pin should be input. Now I know why people like to use Arduino so much. They really make designing with arduino much less headache and the codes are so neat.
Take a look at the pulsein() function description here
Arduino - PulseIn
http://arduino.cc/en/Reference/pulseInAllen