?? 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 + -