S3C6410 DS18B20温度传感器驱动(四) --- 读取温度的应用程序

/*****读取温度的应用程序***********/

/************ds18b20_test.c**************/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>


int main(int argc,char ** argv)
{
	int fd;
	int i;
	int tem;
	float temp;

	fd = open("/dev/ds18b20",0);
	if(fd < 0)
	{
		printf("open ds18b20 dev error!\n");
		return -1;
	}

	for(i = 0;i < 1000;i ++)
	{
		tem = ioctl(fd,0,0);
		temp = tem * 0.0625;		
		printf("%f\n",temp);				
	}

	close(fd);

	return 0;
}

你可能感兴趣的:(c)