资源简介
自己编写的基于linux在mini2440开发板上运行的温湿度传感器驱动代码,可以正常使用码,包括已经编译好的文件和测试程序
代码片段和文件信息
#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(0) ) ) )
{
temp ++ ;
if ( temp > 12 )
return 1 ;
udelay ( 5 ) ;
}
temp = 0 ;
while ( s3c2410_gpio_getpin ( S3C2410_GPF(0) ) )
{
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(0) S3C2410_GPIO_OUTPUT );
s3c2410_gpio_setpin ( S3C2410_GPF(0) 0 );
msleep ( 18 );
// mdelay ( 18 );
s3c2410_gpio_setpin ( S3C2410_GPF(0) 1 );
udelay ( 40 );
s3c2410_gpio_cfgpin ( S3C2410_GPF(0) S3C2410_GPIO_INPUT );
if ( !err )
{
DataTemp = 10 ;
while ( !( s3c2410_gpio_getpin ( S3C2410_GPF(0) ) ) && DataTemp )
{
DataTemp --;
udelay ( 10 );
}
if ( !DataTemp )
{
err = 1;
count = -EFAULT;
}
}
if ( !err )
{
DataTemp = 10 ;
while ( ( s3c2410_gpio_getpin ( S3C2410_GPF(0) ) ) && 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(0) S3C2410_GPIO_OUTPUT );
s3c2410_gpio_setpin ( S3C2410_GPF(0) 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
相关资源
- uboot到linux logo显示不间断 补丁
- UNIX/LINUX编程实践教程的源码
- Linux任务管理器
- linux应用层的华容道游戏源代码
- ubuntu9.10 可加载内核模块和字符设备驱
- MP3文件ID3v2ID3v2APEv2标签读取
- 操作系统实验——虚存管理实验
- linux下的发包工具sendip
- 尚观培训linux许巍关于c 的笔记和讲义
- 尚观培训linux董亮老师关于数据结构的
- linux 线程池源码 c 版
- linux C 电梯程序练习
- linux下用多进程同步方法解决生产者
- Linux 操作系统实验(全)
- Linux From Scratch 中文手册
- linux 网络实验 ftp程序
- Linux命令大全离线版&在线版
- 操作系统共享内存实验
- dos 下运行Linux 命令--gnu_utils
- linux 0.12内核源代码
- linux简易shell C实现
- linux实验报告及心得体会
- 基于GTK的Linux环境下的简易任务管理器
- linux扫雷游戏代码
- CAN Linux驱动代码
- Linux系统教材
- intel 82579LM 网卡驱动Linux系统版 v1.9.
- SA1110处理器掌上电脑液晶显示器设计
- 基于Linux的串口服务器设计
- Windows下访问LINUX的利器-SSH
评论
共有 条评论