⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tester.c

📁 在linux中arm9对温度传感器18B20进行的驱动开发
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -