static ssize_t ds18b20_read(struct file* file,char __user* buf, size_t size,loff_t* offset){ unsigned long flags; unsigned char DL= 0,DH = 0; unsigned char de1,de2,del; unsigned int integer; local_irq_save(flags); if(ds18b20_reset()){ local_irq_restore(flags); return -ENODEV; } ds18b20_write_byte(0xcc); ds18b20_write_byte(0x44);//启动温转 gpiod_direction_output(ds18b20_pin,1); local_irq_restore(flags); set_current_state(TASK_INTERRUPTIBLE);//使用schedule_timeout先设置状态 schedule_timeout(HZ);//延时1s,温转需要时间 local_irq_save(flags);//再次关中断 ds18b20_write_byte(0xcc); ds18b20_write_byte(0xbe);//读取寄存器 // 读取的字节顺序? DL = ds18b20_read_byte();//低八位 DH = ds18b20_read_byte();//高八位 if(DH > 0x7f){ DL = ~DL;
//待完善 } else{ //分辨率:0.0625 integer = DL/16 + DH*16; de1 = (DL&0x0f)*10/16; de2 = (DL&0x0f)*100/16; del = de1*10 + de2; }
标签:DL,DH,ds18b20,DS18B20,unsigned,flags,温转,模块,byte From: https://www.cnblogs.com/xuan01/p/16858217.html