-
大小: 41KB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2021-05-20
- 語言: 其他
- 標(biāo)簽: DHT11驅(qū)動??jz2440??
資源簡介
基于jz2440Linux3.4.2的驅(qū)動 QT做的GUI顯示系統(tǒng)首先進(jìn)行系統(tǒng)初始化,然后讀取傳感器數(shù)據(jù),對數(shù)據(jù)進(jìn)行相應(yīng)處理,得到歷史最高值,在進(jìn)行數(shù)據(jù)的保存操作,其次進(jìn)行計時處理,最后是顯示處理,每0.1S刷新一次界面。從讀取數(shù)據(jù)到顯示處理是一個循環(huán)的過程,進(jìn)行顯示處理判斷后,來回反復(fù)地進(jìn)行讀取功能處理。

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#define?DEVICE_NAME?“dht11“
static?char?DHT11_read_byte?(?void?)
{
char?DHT11_byte?;
unsigned?char?i?;
unsigned?char?temp?;
DHT11_byte?=?0?;
for?(?i?=?0?;?i?8?;?i?++?)
{
temp?=?0?;
while?(?!?(s3c2410_gpio_getpin?(?S3C2410_GPF(2)?)?)?)
{
temp?++?;
if?(?temp?>?12?)
return?1?;
udelay?(?5?)?;
}
temp?=?0?;
while?(?s3c2410_gpio_getpin?(?S3C2410_GPF(2)?)?)
{
temp?++?;
if?(?temp?>?20?)
return?1?;
udelay?(?5?)?;
}
if?(?temp?>?6?)
{
DHT11_byte?<<=?1?;
DHT11_byte?|=?1?;
}?
else
{
DHT11_byte?<<=?1?;
DHT11_byte?|=?0?;
}
}
return?DHT11_byte?;
}
static?ssize_t?DHT11_read?(?struct?file*?filp?char?__user*?buf?size_t?count?loff_t*?f_pos?)
{
unsigned?char?DataTemp;
unsigned?char?i;
unsigned?char?err;
char?tempBuf[5];
// loff_t?pos?=?*f_pos?;
err?=?0?;
s3c2410_gpio_cfgpin?(?S3C2410_GPF(2)??S3C2410_GPIO_OUTPUT?);
s3c2410_gpio_setpin?(?S3C2410_GPF(2)??0?);
msleep?(?18?);
// mdelay?(?18?);
s3c2410_gpio_setpin?(?S3C2410_GPF(2)??1?);
udelay?(?40?);
s3c2410_gpio_cfgpin?(?S3C2410_GPF(2)??S3C2410_GPIO_INPUT?);
if?(?!err?)
{
DataTemp?=?10?;
while?(?!(?s3c2410_gpio_getpin?(?S3C2410_GPF(2)?)?)?&&?DataTemp?)
{
DataTemp?--;
udelay?(?10?);
}
if?(?!DataTemp?)
{
err?=?1;
count?=?-EFAULT;
}
}
if?(?!err?)
{
DataTemp?=?10?;
while?(?(?s3c2410_gpio_getpin?(?S3C2410_GPF(2)?)?)?&&?DataTemp?)
{
DataTemp?--;
udelay?(?10?);
}
if?(?!DataTemp?)
{
err?=?1;
count?=?-EFAULT;
}
}
if?(?!err?)
{
for?(?i?=?0;?i?5;?i?++?)
{
tempBuf[i]?=?DHT11_read_byte?()?;
}
DataTemp?=?0?;
for?(?i?=?0;?i?4;?i?++?)
{
DataTemp?+=?tempBuf[i]?;
}
if?(?DataTemp?!=?tempBuf[4]?)
{
count?=?-EFAULT;
}
// if?(?count?>?(?5?-?pos?)?)
// {
// count?=?5?-?pos?;
// }
if?(?count?>?5?)
{
count?=?5?;
}
//? pos?+=?count;
// if?(?copy_to_user?(?buf??tempBuf?+?*f_pos??count?)?)
if?(?copy_to_user?(?buf??tempBuf??count?)?)
{
count?=?-EFAULT?;
}
// *f_pos?=?pos;
}
s3c2410_gpio_cfgpin?(?S3C2410_GPF(2)??S3C2410_GPIO_OUTPUT?);
s3c2410_gpio_setpin?(?S3C2410_GPF(2)??1?);
return?count;
}
static?struct?file_operations?dev_fops?=?{
.owner?=?THIS_MODULE
.read?=?DHT11_read
};
static?struct?miscdevice?misc?=?{
.minor?=?MISC_DYNAMIC_MINOR
.name?=?DEVICE_NAME
.fops?=?&dev_fops
};
static?int?__init?DHT11_init_module?(?void?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3425??2018-03-08?20:04??dht11?_test\dht11.c
?????文件???????3765??2011-06-22?15:49??dht11?_test\dht11.ko
?????文件???????8086??2011-06-09?21:39??dht11?_test\dht11_test
?????文件????????757??2018-03-08?20:12??dht11?_test\dht11_test.c
?????文件????????178??2018-03-08?17:52??dht11?_test\Makefile
????I.A....???????282??2018-03-09?19:19??test最終\main.cpp
????I.A....??????2352??2018-03-09?19:19??test最終\main.o
????I.A....?????39806??2018-03-09?19:19??test最終\Makefile
????I.A....??????2533??2018-03-09?19:19??test最終\moc_widget.cpp
????I.A....??????6460??2018-03-09?19:19??test最終\moc_widget.o
????I.A....?????55889??2018-03-09?19:19??test最終\test
????I.A....???????408??2018-03-09?19:19??test最終\test.pro
????I.A....?????23828??2018-03-09?19:19??test最終\test.pro.user
????I.A....??????5640??2018-03-09?19:19??test最終\ui_widget.h
????I.A....??????2014??2018-03-09?19:19??test最終\widget.cpp
????I.A....???????350??2018-03-09?19:19??test最終\widget.h
????I.A....?????16504??2018-03-09?19:19??test最終\widget.o
????I.A....??????4903??2018-03-09?19:19??test最終\widget.ui
?????目錄??????????0??2018-03-11?11:18??dht11?_test
????I..D...?????????0??2018-03-11?11:18??test最終
-----------?---------??----------?-----??----
???????????????177180????????????????????20
評論
共有 條評論