.off tooling sample是什么的配置

稳稳的幸福,微微一笑,留下一缕阳光!
android gradle tools 3.X 配置的一些gradle配置
转载:前言2017 年google 后,Android studio 版本更新至3.0,更新中,连带着com.android.tools.build:gradle 工具也升级到了3.0.0,在3.0.0中使用了最新的Gralde 4.0 里程碑版本作为gradle 的编译版本,该版本gradle编译速度有所加速,更加欣喜的是,完全支持Java8。当然,对于Kotlin的支持,在这个版本也有所体现,Kotlin插件默认是安装的。在com.android.tools.build:gradle 3.0 以下版本依赖在gradle 中的声明写法compile fileTree(dir: 'libs', include: ['*.jar'])1但在3.0后的写法为implementation fileTree(dir: 'libs', include: ['*.jar'])
api fileTree(dir: 'libs', include: ['*.jar'])123在3.0版本中,compile 指令被标注为过时方法,而新增了两个依赖指令,一个是implement 和api,这两个都可以进行依赖添加,但是有什么区别呢?api 指令完全等同于compile指令,没区别,你将所有的compile改成api,完全没有错。implement指令这个指令的特点就是,对于使用了该命令编译的依赖,对该项目有依赖的项目将无法访问到使用该命令编译的依赖中的任何程序,也就是将该依赖隐藏在内部,而不对外部公开。文不如图用api指令编译,Glide依赖对app Module 是可见的用implement指令编译依赖对app Module 是不可见的建议在Google IO 相关话题的中提到了一个建议,就是依赖首先应该设置为implement的,如果没有错,那就用implement,如果有错,那么使用api指令,这样会使编译速度有所增快。参考资料需要科学上网最近发现Android Studio 3.0.0以上已经默认添加google()作为google的远程仓库了。遇到问题的时候,我还是喜欢先去分析问题的出现,在更新之前是没有问题的,那么就是新版本的AS有问题,AS有问题,我一般都会先检查三个地方。 1、根目录的build.gradle,检查构建工具的版本,是否是正常的dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
// NOTE: Do not place your applicati they belong
// in the individual module build.gradle files
}1234562、gradle/wrapper/gradle-wrapper.properties里面gradle的版本distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip13、sdk版本,一般检查module下面的build.gradle文件,检查里面的sdk是否不存在,如果是,请下载。compileSdkVersion 25
buildToolsVersion localBuildToolsVersion
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
defaultConfig {
applicationId "com.voctex"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
}12345678910111213141516然后发现这一套下来,居然不管用。。。AS还老是提示我添加google的远程仓库,没办法,就添加看看吧,结果还是一样的报错,代码如下buildscript {
repositories {
url 'https://maven.google.com/'
name 'Google'
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
// NOTE: Do not place your applicati they belong
// in the individual module build.gradle files
12345678910111213141516这个AS提示我添加的东西居然还是搞不定?这就让我对AS有点无语了,然后上网搜了一下,发现要改成google()才可以,这。。。 具体代码如下:buildscript {
repositories {
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
allprojects {
repositories {
task clean(type: Delete) {
delete rootProject.buildDir
}你可能经常在build.gradle文件中看到,这样的字眼,annotationProcessor、android-apt、Provided,它们到底有什么作用?下面就一起来看看吧1、什么是APT?随着一些如ButterKnife,dagger等的开源注解框架的流行,APT的概念也越来越被熟知。annotationProcessor和android-apt的功能是一样的,它们是替代关系,在认识它们之前,先来看看APT。APT(Annotation Processing Tool)是一种处理注释的工具,它对源代码文件进行检测找出其中的Annotation,根据注解自动生成代码。 Annotation处理器在处理Annotation时可以根据源文件中的Annotation生成额外的源文件和其它的文件(文件具体内容由Annotation处理器的编写者决定),APT还会编译生成的源文件和原来的源文件,将它们一起生成class文件。APT的处理要素  注解处理器(AbstractProcess)+代码处理(javaPoet)+处理器注册(AutoService)+apt   使用APT来处理annotation的流程  1. 定义注解(如@automain)   2. 定义注解处理器,自定义需要生成代码   3.使用处理器   4.APT自动完成如下工作。2、annotationProcessorannotationProcessor是APT工具中的一种,他是google开发的内置框架,不需要引入,可以直接在build.gradle文件中使用,如下dependencies {
annotationProcessor project(':xx')
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}12343、android-aptandroid-apt是由一位开发者自己开发的apt框架,源代码托管在,随着Android Gradle 插件 2.2 版本的发布,Android Gradle 插件提供了名为 annotationProcessor 的功能来完全代替 android-apt ,自此android-apt 作者在官网发表声明最新的Android Gradle插件现在已经支持annotationProcessor,并警告和或阻止android-apt ,并推荐大家使用 Android 官方插件annotationProcessor。但是很多项目目前还是使用android-apt,如果想替换为annotationProcessor,那就要知道android-apt是如何使用的。下面就来介绍一下3.1、添加android-apt到Project下的build.gradle中
buildscript {
repositories {
mavenCentral()
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
12345678910111213143.2、在Module中build.gradle的配置通常在使用的时候,使用apt声明注解用到的库文件。项目依赖可能分为多个部分。例如Dagger有两个组件Dagger-compiler和dagger。dagger-commpiler仅用于编译时,运行时必需使用dagger。
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
dependencies {
apt 'com.squareup.dagger:dagger-compiler:1.1.0'
compile 'com.squareup.dagger:dagger:1.1.0'
}123456789基本使用就是上面这两点,想用annotationProcessor替代android-apt。删除和替换相应部分即可文档翻译4、Provided 和annotationProcessor区别annotationProcessor只在编译的时候执行依赖的库,但是库最终不打包到apk中,编译库中的代码没有直接使用的意义,也没有提供开放的api调用,最终的目的是得到编译库中生成的文件,供我们调用。ProvidedProvided 虽然也是编译时执行,最终不会打包到apk中,但是跟apt/annotationProcessor有着根本的不同。A 、B、C都是Library。
A依赖了C,B也依赖了C
App需要同时使用A和B
那么其中A(或者B)可以修改与C的依赖关系为Provided1234A这个Library实际上还是要用到C的,只不过它知道B那里也有一个C,自己再带一个就显得多余了,等app开始运行的时候,A就可以通过B得到C,也就是两人公用这个C。所以自己就在和B汇合之前,假设自己有C。如果运行的时候没有C,肯定就要崩溃了。总结一下,Provided是间接的得到了依赖的Library,运行的时候必须要保证这个Library的存在,否则就会崩溃,起到了避免依赖重复资源的作用。5、使用APT的简单项目——自定义注解5.1、新增一个java Library Module 名为apt-lib, 编写注解类:@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface AutoCreate {
}123455.2、新增一个java Library Module 名为apt-process,编写类来处理注解。以后使用上面的@AutoCreate,就会根据下面这个类生成指定的java文件@AutoService(Processor.class)
public class TestProcess extends AbstractProcessor {
public Set&String& getSupportedAnnotationTypes() {
return Collections.singleton(AutoCreat.class.getCanonicalName());
public boolean process(Set&? extends TypeElement& annotations, RoundEnvironment roundEnv) {
MethodSpec main = MethodSpec.methodBuilder("main")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.returns(void.class)
.addParameter(String[].class, "args")
.addStatement("$T.out.println($S)", System.class, "Hello, JavaPoet!")
TypeSpec helloWorld = TypeSpec.classBuilder("HelloWorld")
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.addMethod(main)
JavaFile javaFile = JavaFile.builder("com.songwenju.aptproject", helloWorld)
javaFile.writeTo(processingEnv.getFiler());
} catch (IOException e) {
e.printStackTrace();
return false;
}1234567891011121314151617181920212223242526272829303132335.2.1、需要使用的libdependencies {
compile project(':apt-lib')
compile 'com.squareup:javapoet:1.8.0'
compile 'com.google.auto.service:auto-service:1.0-rc2'
}12345至此一个简单的自定义注解类,就完成了,只是生成了一个HelloWorld.java文件,里面只有一个main()函数5.3、自定义注解类的使用使用的话,更简单。在java文件中使用如下:@AutoCreat
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
1234567891011配置build.gradle文件dependencies {
compile project(":apt-lib")
annotationProcessor project(':apt-process')
123456demo下载:参考:
没有更多推荐了,Maven变量及常见插件配置详解
一、变量-自定义变量及内置变量
1.自定义变量
&properties&
&project.build.name&tools&/project.build.name&
&project.build.sourceEncoding&UTF-8&/project.build.sourceEncoding&
&/properties&
2.内置变量
${basedir} 项目根目录
${project.build.directory} 构建目录,缺省为target
${project.build.outputDirectory} 构建过程输出目录,缺省为target/classes
${project.build.finalName} 产出物名称,缺省为${project.artifactId}-${project.version}
${project.packaging} 打包类型,缺省为jar
${project.xxx} 当前pom文件的任意节点的内容
二、常见插件配置
1.编译插件
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-compiler-plugin&/artifactId&
&configuration&
&source&1.6&/source&
&target&1.6&/target&
&encoding&${project.build.sourceEncoding}&/encoding&
&/configuration&
source: 源代码编译版本;
target: 目标平台编译版本;
encoding: 字符集编码
2.设置资源文件的编码方式
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-resources-plugin&/artifactId&
&version&2.4.3&/version&
&executions&
&execution&
&phase&compile&/phase&
&/execution&
&/executions&
&configuration&
&encoding&${project.build.sourceEncoding}&/encoding&
&/configuration&
xml、properties文件都是资源文件,编码的时候遇到中文总要进行转码!用什么编码?UTF-8,那就记得强制 &encoding&${project.build.sourceEncoding}&/encoding& 3.自动拷贝jar包到target目录
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-dependency-plugin&/artifactId&
&version&2.6&/version&
&executions&
&execution&
&id&copy-dependencies&/id&
&phase&compile&/phase&
&goal&copy-dependencies&/goal&
&configuration&
&!-- ${project.build.directory}为Maven内置变量,缺省为target --&
&outputDirectory&${project.build.directory}/lib&/outputDirectory&
&!-- 表示是否不包含间接依赖的包 --&
&excludeTransitive&false&/excludeTransitive&
&!-- 表示复制的jar文件去掉版本信息 --&
&stripVersion&true&/stripVersion&
&/configuration&
&/execution&
&/executions&
关于maven-dependency-plugin:用得最多的几个操作:copy, copy-dependencies和它们对应的unpack, unpack-dependencies
描述:copy 和 unpack操作是由要拷某个包,这个包需要具体指定要拷哪个包,与当前工程的依赖没有关系。这两者区别-是否解压
copy-dependencies和unpack-dependencies,但是它是用来拷当前工程的依赖包的。这两者区别-是否解压
参考链接:
4.生成源代码jar包
&artifactId&maven-source-plugin&/artifactId&
&version&2.1&/version&
&configuration&
&!-- &finalName&${project.build.name}&/finalName& --&
&attach&true&/attach&
&encoding&${project.build.sourceEncoding}&/encoding&
&/configuration&
&executions&
&execution&
&phase&compile&/phase&
&goal&jar&/goal&
&/execution&
&/executions&
5.将项目打成jar包
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-jar-plugin&/artifactId&
&version&2.4&/version&
&configuration&
&manifest&
&!-- 告知 maven-jar-plugin添加一个 Class-Path元素到 MANIFEST.MF文件,以及在Class-Path元素中包括所有依赖项 --&
&addClasspath&true&/addClasspath&
&!-- 所有的依赖项应该位于 lib文件夹 --&
&classpathPrefix&lib/&/classpathPrefix&
&!-- 当用户使用 lib命令执行JAR文件时,使用该元素定义将要执行的类名 --&
&mainClass&com.zhengtian.tools.service.phone.MobilePhoneTool&/mainClass&
&/manifest&
&/archive&
&/configuration&
在将项目打成jar包时,有时会需要将项目打成可以直接运行的jar包,因此就需要将项目依赖的jar包也打入jar包中,此时需要在Eclipse上安装例外一个插件,用来打可执行jar包,详情见链接
更多maven配置详见:
关于maven-assembly-plugin的使用
“assembly”是把一组文件、目录、依赖元素组装成一个归档文件
参考链接:
&artifactId&maven-assembly-plugin&/artifactId&
&version&2.4.1&/version&
&executions&
&execution&
&id&make-zip&/id&
&!-- 绑定到package生命周期阶段上 --&
&phase&package&/phase&
&!-- 绑定到package生命周期阶段上 --&
&goal&single&/goal&
&configuration&
&descriptors& &!--描述文件路径--&
&descriptor&src/assembly/assembly.xml&/descriptor&
&/descriptors&
&/configuration&
&/execution&
&/executions&
assembly.xml配置
&assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"&
&id&distribution&/id&
&format&zip&/format&
&/formats&
&fileSets&
&directory&${project.basedir}\src\main\resources&/directory&
&outputDirectory&\&/outputDirectory&
&/fileSet&
&directory&${project.basedir}\src\bin&/directory&
&outputDirectory&\bin&/outputDirectory&
&/fileSet&
&/fileSets&
&dependencySets&
&dependencySet&
&useProjectArtifact&true&/useProjectArtifact&
&outputDirectory&lib&/outputDirectory&
&!-- 将scope为runtime的依赖包打包到lib目录下。 --&
&scope&runtime&/scope&
&/dependencySet&
&/dependencySets&
&/assembly&
没有更多推荐了,查看: 5837|回复: 4
无法定位链接器!请检查 tools\link.ini 中的配置是否正确。
阅读权限70
签到天数:1 天结帖率: (8/10)
**********************
*****************************
**********************************
正在进行名称连接...
正在统计需要编译的子程序
正在编译...
正在生成主程序入口代码
程序代码编译成功
等待用户输入欲编译到的文件名
正在进行名称连接...
开始静态链接...
无法定位链接器!请检查 tools\link.ini 中的配置是否正确。
静态连接失败
什么鬼?5.7出了这个 我安装在D盘
https://pan.baidu.com/s/1eQ9xo7g
易语言静态链接器
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
揭阳精易科技有限公司申明:我公司所有的培训课程版权归精易所有,任何人以任何方式翻录、盗版、破解本站培训课程,我们必将通过法律途径解决!
公司简介:揭阳市揭东区精易科技有限公司致力于易语言教学培训/易语言学习交流社区的建设与软件开发,多年来为中小企业编写过许许多多各式软件,并把多年积累的开发经验逐步录制成视频课程供学员学习,让学员全面系统化学习易语言编程,少走弯路,减少对相关技术的研究与摸索时间,从而加快了学习进度!
防范网络诈骗,远离网络犯罪
违法和不良信息举报电话,QQ: ,邮箱:@b.qq.com
Powered by
X3.2 揭阳市揭东区精易科技有限公司
粤公网安备 25后使用快捷导航没有帐号?
请完成以下验证码
查看: 1273|回复: 0
使用 MCUXpresso Config Tools工具配置FRDM-KW41Z的GPIO驱动DHT22温湿度传感器
在线时间569 小时
TA的帖子TA的资源
一粒金砂(中级), 积分 84, 距离下一级还需 116 积分
一粒金砂(中级), 积分 84, 距离下一级还需 116 积分
本帖最后由 dql2016 于
21:58 编辑
DHT22是已校准的数字温湿度传感器,用于检测环境温湿度,采用DHT22(AM2302),标准单总线接口。
相比DHT11,拥有更高的精度和更大的量程。
分辨率:0.1°C
精度:±0.5℃
检测范围:-40°C ~ 80°C
分辨率:0.1%RH
精度:±2%RH (25°C)
检测范围:0%RH ~ 99.9%RH
工作电压 :3.3V ~ 5.5 V
推荐存储环境:
温度:10°C ~40°C
湿度:60%RH以下
气象站、湿度调节器和测试及检测设备等
【接口说明】
以接入MCU为例:
VCC:接3.3V ~ 5.5V
GND:接GND
DOUT:接MCU.IO
选择KW41Z的PTC19(对应FRDM-KW41Z板卡的D2)来驱动DHT22,需要把它配置为输入、输出模式;
step1:配置时钟;
22.png (129.36 KB, 下载次数: 3)
21:42 上传
step2:配置PTC19为输出;
11.png (191.53 KB, 下载次数: 3)
21:42 上传
step3:生成工程Keil MDK;
33.png (229.11 KB, 下载次数: 2)
21:42 上传
step4:DHT22驱动代码网上很多,这里只需要做几个接口就行了,分别是设置GPIO输入输出方向,输出时输出高低电平,读取IO值;
现在DHT22.h文件定义下端口:
//choose a gpio pin to drive dht22
//in FRDM-KW41Z board is Arduino UNO R3's D2
#define DHT22_FGPIO FGPIOC&&
#define DHT22_GPIO&&GPIOC& && && && && && && && &
#define DHT22_Port&&PORTC& && && && && && && && && && && && &&&
#define DHT22_Pin& &19U 复制代码
然后在DHT22.c编写接口函数:
//Set GPIO Direction
void DHT22_IO_IN(void)
{
& && && &/* Input pin configuration */
& && && &gpio_pin_config_t inconfig =
& && && &{
& && && && && &&&kGPIO_DigitalInput,
& && && && && &&&0,
& && && &};
& &/* Input pin PORT configuration */
&&port_pin_config_t config =
& && &&&{
& && && && && & kPORT_PullUp,
& && && && && & kPORT_FastSlewRate,
& && && && && & kPORT_PassiveFilterDisable,& && && && && && && && &
& && && && && & kPORT_LowDriveStrength,
& && && && && & kPORT_MuxAsGpio,
&&};
& && && &
PORT_SetPinConfig(DHT22_Port, DHT22_Pin, &config);//config as pull-up& && && && && && && && && && && && && && && && && && && &
FGPIO_PinInit(DHT22_FGPIO, DHT22_Pin, &inconfig);//config as input& && &&&
}
//Set GPIO Direction
void&&DHT22_IO_OUT(void)
{
& && && && && & /* Output pin configuration */
& && && &gpio_pin_config_t outconfig =
& && && &{
& && && && && &&&kGPIO_DigitalOutput,
& && && && && &&&0,
& && && &};
& && && & GPIO_PinInit(DHT22_GPIO, DHT22_Pin, &outconfig);//config as output
}
//output 1 or 0
#define& && &&&DHT22_DQ_OUT_0&&GPIO_WritePinOutput(DHT22_GPIO, DHT22_Pin, 0)
#define& && &&&DHT22_DQ_OUT_1&&GPIO_WritePinOutput(DHT22_GPIO, DHT22_Pin, 1)
//read 1 or 0
#define& && &&&DHT22_DQ_IN& &&&FGPIO_ReadPinInput(DHT22_FGPIO,DHT22_Pin)
复制代码
DHT22.c文件如下,采用接口形式很容易移植到其它MCU:
#include &DHT22.h&
//follow are 4 gpio interface
//Set GPIO Direction
void DHT22_IO_IN(void)
{
& && && &/* Input pin configuration */
& && && &gpio_pin_config_t inconfig =
& && && &{
& && && && && &&&kGPIO_DigitalInput,
& && && && && &&&0,
& && && &};
& &/* Input pin PORT configuration */
&&port_pin_config_t config =
& && &&&{
& && && && && & kPORT_PullUp,
& && && && && & kPORT_FastSlewRate,
& && && && && & kPORT_PassiveFilterDisable,& && && && && && && && &
& && && && && & kPORT_LowDriveStrength,
& && && && && & kPORT_MuxAsGpio,
&&};
& && && &
PORT_SetPinConfig(DHT22_Port, DHT22_Pin, &config);//config as pull-up& && && && && && && && && && && && && && && && && && && &
FGPIO_PinInit(DHT22_FGPIO, DHT22_Pin, &inconfig);//config as input& && &&&
}
//Set GPIO Direction
void&&DHT22_IO_OUT(void)
{
& && && && && & /* Output pin configuration */
& && && &gpio_pin_config_t outconfig =
& && && &{
& && && && && &&&kGPIO_DigitalOutput,
& && && && && &&&0,
& && && &};
& && && & GPIO_PinInit(DHT22_GPIO, DHT22_Pin, &outconfig);//config as output
}
//output 1 or 0
#define& && &&&DHT22_DQ_OUT_0&&GPIO_WritePinOutput(DHT22_GPIO, DHT22_Pin, 0)
#define& && &&&DHT22_DQ_OUT_1&&GPIO_WritePinOutput(DHT22_GPIO, DHT22_Pin, 1)
//read 1 or 0
#define& && &&&DHT22_DQ_IN& &&&FGPIO_ReadPinInput(DHT22_FGPIO,DHT22_Pin)
//4 gpio interface end
//2 delay interface begin
static void delay_ms(unsigned long xms)
{
& && &&&volatile uint32_t i = 0;
& && &&&while(xms--)
&&{
& & for (i = 0; i & 100; ++i)
& & {
& && &__asm(&nop&); /* delay */
& & }
&&}
}
static void delay_us(unsigned long xus)
{
& && &&&volatile uint32_t i = 0;
& && &&&while(xus--)
&&{
& & for (i = 0; i & 3; ++i)
& & {
& && &__asm(&nop&); /* delay */
& & }
&&}
}
//2 delay interface end
//Reset DHT22
void DHT22_Rst(void)& && && &&&
{& && && && && &&&
& && && && && & DHT22_IO_OUT();& && && &//SET OUTPUT
& & DHT22_DQ_OUT_0;& && && &//GPIOA.0=0
& & delay_ms(30);& && && && &//Pull down Least 800us
& & DHT22_DQ_OUT_1;& && && &//GPIOA.0=1
& && && && && & delay_us(30);& && && && & //Pull up 20~40us
}
u8 DHT22_Check(void)& && && && &
{& &
& && &&&u8 retry=0;
& && &&&DHT22_IO_IN();//SET INPUT& && && &
& & while (DHT22_DQ_IN&&retry&100)//DHT22 Pull down 40~80us
& && &&&{
& && && && && & retry++;
& && && && && & delay_us(1);
& && &&&};& && && &
& && &&&if(retry&=100)
& && &&&{
& && && && && & return 1;& && &&&
& && &&&}
& && &&&else
& && && && && & retry=0;
& & while (!DHT22_DQ_IN&&retry&100)//DHT22 Pull up 40~80us
& && &&&{
& && && && && & retry++;
& && && && && & delay_us(1);
& && &&&};
& && &&&if(retry&=100)
&&{
& && && && && & return 1;//chack error& && &&&
& && && && && && && && && && &&&
&&}& && &&&
& && &&&return 0;
}
u8 DHT22_Read_Bit(void)& && && && && && && && &&&
{
& && && &u8 retry=0;
& && &&&while(DHT22_DQ_IN&&retry&100)//wait become Low level
& && &&&{
& && && && && & retry++;
& && && && && & delay_us(1);
& && &&&}
& && &&&retry=0;
& && &&&while(!DHT22_DQ_IN&&retry&100)//wait become High level
& && &&&{
& && && && && & retry++;
& && && && && & delay_us(1);
& && &&&}
& && &&&delay_us(40);//wait 40us
& && &&&if(DHT22_DQ_IN)
& && && && && & return 1;
& && &&&else
& && && && && & return 0;& && && && && && &
u8 DHT22_Read_Byte(void)& &
{& && &&&
& & u8 i,
& & dat=0;
& && &&&for (i=0;i&8;i++)
& && &&&{
& && && && && && & dat&&=1;
& && && && &dat|=DHT22_Read_Bit();
& & }& && && && && && && && && && && && && && && && && &
u8 DHT22_Read_Data(float *temperature,float *humidity)& &
{& && &&&
& && && &u8 buf[5];
& && &&&u8
& && &&&u8
& && &&&*humidity=0;
& && &&&*temperature=0;
& && &&&DHT22_Rst();
& && &&&if(DHT22_Check()==0)
& && &&&{
& && && && && & for(i=0;i&5;i++)
& && && && && & {
& && && && && && && && &buf[i]=DHT22_Read_Byte();
& && && && && & }
& && && && && & sum = buf[0]+buf[1]+buf[2]+buf[3];
& && && && && & if(sum == buf[4])
& && && && && & {
& && && && && && && && &*humidity=(float)((buf[0]&&8)+buf[1])/10;
& && && && && && && && &*temperature=(float)((buf[2]&&8)+buf[3])/10;
& && && && && & }
& && && && && & else
& && && && && & {
& && && && && && && && &*humidity=(float)((buf[0]&&8)+buf[1])/10;
& && && && && && && && &*temperature=(float)((buf[2]&&8)+buf[3])/10;
& && && && && & }
& && &&&}
& && &&&else
& && &&&{
& && && && && & return 1;
& && &&&}
& && &&&return 0;& && && && &
}
& && && &
u8 DHT22_Init(void)
{& && && &
& && && && && && && && && && && &
& && &&&DHT22_IO_OUT();
& && && && &
& && &&&DHT22_Rst();&&
& && &&&return DHT22_Check();
}
主函数测试代码如下:
/**
* This is template for main module created by MCUXpresso Project Generator. Enjoy!
#include &board.h&
#include &pin_mux.h&
#include &clock_config.h&
//user code begin
#include &fsl_gpio.h&
#include &fsl_port.h&
#include &DHT22.h&
float temperature = 0;& && && && &&&
float humidity = 0;
static void mydelay_ms(unsigned long xms)& && &&&
{& && &&&
& && && & volatile uint32_t i = 0;
& && &&&while(xms--)
& && &&&{
& & for (i = 0; i & 4000; ++i)
& & {
& && &&&__asm(&nop&); /* delay */
& & }
& && &&&}
}
//user code end
* [url=home.php?mod=space&uid=159083]@brief[/url] Application entry point.
*/
int main(void) {
&&/* Init board hardware. */
&&BOARD_InitBootPins();
&&BOARD_InitBootClocks();
&&BOARD_InitDebugConsole();
&&/* Add your code here */
& && &&&
//user code begin& && &&&
& && && &while(DHT22_Init());//init DHT22
& && && &printf(&Hell EEworld!\r\n&);
& && && &DbgConsole_Printf(&Hell FRDM-KW41Z!\r\n&);& && &&&
& && && &
//user code end& && &&&
&&for(;;) { /* Infinite loop to avoid leaving the main function */
& & __asm(&NOP&); /* something to use as a breakpoint stop while looping */
//user code begin& && && && && &
& && && && && & mydelay_ms(500);
& && && && && &
& && && && && & DHT22_Read_Data(&temperature,&humidity);& && &&&
& && && && && & printf(&temperature = %.2f& & humidity = %.2f%%\r\n&,temperature,humidity);
& && && && && &
//user code end& && && && && &
&&}
}
复制代码
精度还是不错的:
IMG_658.jpg (533.93 KB, 下载次数: 2)
21:58 上传
IMG_206.jpg (2.33 MB, 下载次数: 3)
21:53 上传
搜狗截图55.png (295.89 KB, 下载次数: 2)
21:53 上传
DHT22数据手册:
(865.45 KB, 下载次数: 0, 售价: 1 枚芯币)
21:55 上传
点击文件名下载附件
售价: 1 枚芯币 &
工程源码:
(10.89 MB, 下载次数: 35, 售价: 1 枚芯币)
21:54 上传
点击文件名下载附件
售价: 1 枚芯币 &
EEWORLD 官方微信
Powered by}

我要回帖

更多关于 soft tooling 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信