I believe that you must use 2 digital ports, no analog. How this thing works is you send a 10 microsecond (us) pulse to it, then you have to wait until you get an input pulse on your digital input port, and you have to measure the length of the pulse. This diagram from that site should help
from
http://www.robot-electronics.co.uk/htm/srf04tech.htm
For sending the output pulse you can simply do
Code:
rc_dig_out18 = 1;
for(x=0;x<10;x++);
rc_dig_out18 = 0;
or something similar.
To measure the pulse you have to set up an interrupt on whichever port you are using as an input (I would suggest port 1 or 2) and a timer. I ended up using timer3. I also wrote it to work with two sensors on 2 outputs and 1 input. I haven't tested the second one yet, but it should work. The only problem I am having is converting my time to millimeters...
If you have any questions about that ask away. I believe there is code somewhere on these forums for this as well, or I can post up mine tomorrow when I get back to school.
Edit: Take a look at this:
http://www.chiefdelphi.com/forums/sh...ad.php?t=42717
Interesting code that you could try.