You divide the duration by 29 because that is evidently how you convert the unspecified time period into a distance of unspecified units.

Without knowing what the time period is measured in, nor the units of the distance you expect, why 29 was chosen is anyone's guess.

While I am not familiar with the language you are using, I can kind of follow the flow of it, however that is a completely pointless exercise since without knowing what pins are connected to what and in what way we can't know what the program is supposed to be doing.

My understanding:

* Timer is set to 1:2 prescale, so ticks at 2MHz.
* Set port C3 (receiver, which is an input) HIGH - what is this supposed to achieve?!
* Set port D7 to an output
* Clear timer.
* Wait 1ms (why?!)
* Wait while C3 is low
* Start the timer
* Wait while C3 is high
* Turn off the timer
* Divide the time (in 500ns counts) by 29
* Set port D7 high
* Output the distance to PORTB

Now, is it me, or does that program make no sense whatsoever?  At no point is the trigger being activated. You're randomly setting other port pins to input or output or high or low for no apparent reason.