近在用18B20想测温度,但是纠结了好多天,温度总是0,8,16,2000多这样乱跳,大多还是0,时序我也是按照18B20手册的,但是还是不对。还有一个不懂的是释放总线这个概念,有些地方说是直接给总线置1,有些是把IO改为输入模式,我试了下用置1的方法不成功。 下面是我的代码:::
C/C++ code
#include <linux/miscdevice.h>
#include <linux/delay.h>
#include <asm/irq.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/moduleparam.h>
#include <linux/slab.h>
#include <linux/errno.h>
#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/module.h>
#include<linux/fs.h>
#include<asm/uaccess.h>
#include<asm/io.h>
#include<linux/device.h>
#include<asm/gpio.h>
#include<linux/poll.h>
#include<linux/interrupt.h>
#include<linux/irq.h>
#include<linux/time.h>
#include<linux/delay.h>
#include<asm/hardware.h>
#include <asm-arm/arch-s3c2410/regs-gpio.h>
MODULE_LICENSE("GPL");
#define DEVICE_NAME "18B20-drv"
#define GPJCON (unsigned long)(0x560000D0)
#define GPJDAT (unsigned long)(0x560000D4)
#define GPJUP (unsigned long) (0x560000D8)
typedef char BYTE;
static volatile unsigned long* _io_gpjcon;
static volatile unsigned long* _io_gpjdat;
static volatile unsigned long* _io_gpjup;
static BYTE data[2];//store 18B20rature 1 and 0
static int major=0;
static int minor=0;
static int temp_open(struct inode *, struct file *);
static int temp_release(struct inode *, struct file *);
static ssize_t temp_read(struct file *, char *, size_t, loff_t *);
//static ssize_t temp_write(struct file *, const char *, size_t, loff_t *);
//static int temp_ioctl(struct inode *, struct file *, unsigned int cmd, unsigned long arg);
void DQ_OUT
[1] [2] [3] [4] [5] [6] [7] 下一页