tester.c

来自「在linux中arm9对温度传感器18B20进行的驱动开发」· C语言 代码 · 共 59 行

C
59
字号
#include <stdio.h>#include <stdlib.h>#include <iostream>#include <sys/types.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>using namespace std;int main(){/* 打开端口 */	int hHandle = open("/dev/rpt1820",O_RDWR);	if( hHandle < 0 )	{		cout<<"端口打开失败!"<<endl;		return 1;	}    // --------------------------------------------------------------------------------		char uiWBuf = 0;	static double read_value;	int cnt =0;	int mid_data;	int mid_value;	static double temp_value;	int  iRBuf;	//while( 1 )	while((cnt++) < 10 )	{		int nRead = read(hHandle,&iRBuf,10);		sleep(1);		nRead = read(hHandle,&iRBuf,11);		if( nRead < 0 )		{			cout<<"端口读失败!"<<endl;			break;		}		else		{			mid_value = (iRBuf & 0xFFFF) >> 4;			temp_value = (float)mid_value;			temp_value = temp_value + ((float)(iRBuf & 0x0F)) * 0.0625;			printf("temp_value = %f\n",temp_value);		}			//	sleep(3);	}    // --------------------------------------------------------------------------------	close(hHandle);	return 0;}

⌨️ 快捷键说明

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