www.pudn.com > 18b20.rar > 18b20.c


#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); 
}