OK, I tried with this approach and it works, but as you will see in the code, even though the object is under 5 meters away (for eg. 4meters), PORTC.2 goes high & does not toggle. Is there something wrong with my calculation. It is working fine upto 1 meter. LED connected to PortC.2 does alterate it's toggling speed depending upon how far is the object under 1 meter. My latest code goes like this:
Code:; Phase2: RA0=TRIG (OUTPUT) ;;;;RA1- PWM (INPUT) w1 var word pause 500 main1: w1=0 High PortA.0 pause 1 Low PortA.0 pause 1 High PortA.0 main: Pulsin PortA.1,0,w1 if w1>500 or w1=0 then high PortC.2 else toggle PortC.2 pause w1 endif goto main1 end




Bookmarks