ok. first of all i want to tell u that u dont need to measure the pulses. u need to measure the "hightime" of echo pulse. i measure this using timer0 in pic16f877a.. the program seems like that:
---------------------------------------
int cont;
void interrupt()
{
cont++;
INTCON.TMR0IF=0;
tmr0=110;
}
void main()
{
trisd.b0=0; //trigger pin output.......
trisd.b1=1; // echo pin as input......
do{
PORTD.B0=1;
DELAY_US(10);
PORTD.B0=0;
while(portd.b1==0); wait u
TMR0 = 110; // preset for timer register
INTCON.GIE= 1;
INTCON.TMR0IE=1;
OPTION_REG.PSA = 1; // bit 3 Prescaler Assignment bit.
OPTION_REG.PS2 = 0; // bits 2-0 PS2
S0: Prescaler Rate Select bits
OPTION_REG.PS1 = 0;
OPTION_REG.PS0 = 0;
while(portd.b1==1);
INTCON.GIE=0;
cont=cont/2; // distance is travelled twice from transmitter towater & water to transmiiter so devide by 2.
}while(1);
while choosing the preload value of timer....care must be taken about ur crystal frequency. i have crystal frequency of 20mhz.