ok
This commit is contained in:
parent
d06b2e9d14
commit
e9ca82542c
12
dev.sh
Executable file
12
dev.sh
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
if [ -n "$1" ];then
|
||||||
|
rmmod ds18b20_224
|
||||||
|
make -j 2
|
||||||
|
insmod ds18b20_224.ko
|
||||||
|
sleep 2
|
||||||
|
fi
|
||||||
|
for i in `seq 1 10`
|
||||||
|
do
|
||||||
|
show-temp
|
||||||
|
done
|
23
ds18b20.c
23
ds18b20.c
@ -27,14 +27,14 @@ int init_DS18B20(void)
|
|||||||
unsigned int result;
|
unsigned int result;
|
||||||
DQ_OUT;
|
DQ_OUT;
|
||||||
DQ_L;
|
DQ_L;
|
||||||
udelay(480); //480~960
|
udelay(480);
|
||||||
DQ_H;
|
DQ_H;
|
||||||
udelay(15); //15-60
|
|
||||||
DQ_IN;
|
DQ_IN;
|
||||||
udelay(60);//60-240
|
udelay(65);
|
||||||
result = DQ_V;
|
result = DQ_V;
|
||||||
udelay(405);
|
udelay(240);
|
||||||
printk("ds18b20 init result %d", result);
|
printk("ds18b20 init result %d,%d", result, DQ_V);
|
||||||
|
udelay(180);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ unsigned char read_char(void)
|
|||||||
udelay(2);
|
udelay(2);
|
||||||
dat >>= 1;
|
dat >>= 1;
|
||||||
DQ_IN;
|
DQ_IN;
|
||||||
udelay(15);
|
udelay(12);
|
||||||
if (DQ_V)
|
if (DQ_V)
|
||||||
dat |= 0x80;
|
dat |= 0x80;
|
||||||
udelay(50);
|
udelay(50);
|
||||||
@ -103,6 +103,14 @@ int initDs18b20(unsigned int gpioNum)
|
|||||||
/*读取数据*/
|
/*读取数据*/
|
||||||
void readDs18b20Data(unsigned char *value)
|
void readDs18b20Data(unsigned char *value)
|
||||||
{
|
{
|
||||||
|
if (sizeof(&value) > 1){
|
||||||
|
value[0] = 0xff;
|
||||||
|
value[1] = 0xff;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (init_DS18B20())
|
if (init_DS18B20())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -119,12 +127,9 @@ void readDs18b20Data(unsigned char *value)
|
|||||||
write_char(0xCC);
|
write_char(0xCC);
|
||||||
write_char(0xBE);
|
write_char(0xBE);
|
||||||
|
|
||||||
if (sizeof(&value) > 1)
|
|
||||||
{
|
|
||||||
value[0] = read_char();
|
value[0] = read_char();
|
||||||
value[1] = read_char();
|
value[1] = read_char();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void freeDs18b20(void)
|
void freeDs18b20(void)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user