18b20.c
来自「linux-2.6.12下的温度传感器18b20驱动程序代码」· C语言 代码 · 共 33 行
C
33 行
#include "stdio.h"
#include "sys/types.h"
#include "sys/ioctl.h"
#include "stdlib.h"
#include "termios.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "sys/time.h"
main()
{
int fd;
char buf,ret;
fd=open("/dev/18b20",O_RDWR | O_NDELAY | O_NOCTTY);
if(fd<0)
{
printf("open 18b20 error\n");
exit(1);
}
else
{
printf("success\n");
while(1) {
read(fd,&buf,1);
ret=buf;
printf("%d \n",ret);
sleep(1);
}
}
close(fd);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?