This system is created so that a 10 microseconds pulse is sent through the microcontroller to trigger the ultrasonic ranger. This is done by writing a delay function. The timer register, TMR0 is programmed with decimal value 200, such that it makes 55 counts.
The output that is obtained from SRF04, i.e. echo signal is obtained from RA4.T he Timer clock pin provides an external clock pulse into the timer. After the echo signal makes a transition from HIGH to LOW, the timer will get activated. Due to the fact that the timer counts, the interrupt flag bit, T0IE. Once programmed, the timer is deactivated.
The process is repeated for the next echo pulse and so forth. The sheer number of times the timer operates is calculated and also this denotes the number of echo pulses. We have stated earlier that each echo pulse is of 58 microseconds, it denotes 1 cm. Hence 5 echo pulses would denote 5cm. This data is then used to regulate the DC motor. The direction flow of the motor can also be controlled using the same system.