test_irsensor.c

来自「P98v51RD2 source codes for all the perip」· C语言 代码 · 共 18 行

C
18
字号
#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.
	}
}   

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?