📄 ds1820test.c
字号:
/*****************************************************************************
;Institue of Automation, Chinese Academy of Sciences
;www.emsyschina.com
;File Name: DS1820.c测试程序
;
;Description: 调用DS81B20读取环境温度,打印在终端上
;Date: 2007-11-30
;Author: 王亮
;E_mail: wangl@emsyschina.com
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <signal.h>
//*********************************************************
//主函数
//*********************************************************
int main(void)
{
int fd;
signed short int temp;
int retval;
char i;
//以可读、写的方式打开设备文件;
if((fd=open("/dev/DS1820",O_RDWR))==-1)
{
perror("open error");
exit(1);
}
// while(1)
for(i=0;i<10;i++)
{
retval=read(fd, &temp, 2);
if (retval> 0)
printf("temp = %d.%d \n",temp/10,temp%10);
sleep(1);
}
//关闭设备文件
close(fd);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -