#include <8051.h> #include "ads7841.h" /***************************** Main Program **********************************/ void main() { float x,y; // Distance and Analog voltage output y = analog(0); // Read volt out if the sensor connect to channel 0 of ADS7841 y = 0.00122*y; // Convert BCD to DEC by multiply voltage by 5/4096 if ( (y > 0.4) && (y < 2.8) ) { x = (y-0.19)/20.99; // Solve the linear equation x = 1/x; // Inverse back get distance in cm. } }