Hi Languer
Thanks for the example code - but I only see you toggle the pin once for a duration of 10us then off. I cant seem to understand how this is a 40khz pulse?
sorry its been a while since I checked in, I was just swamped with other projects.
You are certainly correct. The article I provided uses an already built ultrasonic ranger (either PING or SR04). So if you are building one yourself, the transmitter is most easily done with the PWM module (which an MCU running at either 4MHz or 8MHz should halve no problem to run the PWM at 40kHz). For an example using the 16F88 look here. A simpler version (better for the 12F683 - I would use this in place of the 12F675) is just using the PWM output (GP2) and enabling the PWM module to "pulse" the transducer, and then "disabling" the PWM module.
The trickier part may be on the receive side. That is the part that is trickier. When I did one (which I only did because the PING and/or SR04 did not work at +3.3V) that required some timing on the receive side to "detect" the 40kHz signal.