Here:
**broken link removed**
**broken link removed**
you will find description of a distance sensor and a method of converting time-to-distance ..
It will be just the matter of "translating" this method to 8051-language ..
you have to use a ultrasonic transducers for sending and receiving ultrasonic sounds and a signal conditioning block then interface it to your uc.this is the least block you have to interface.