当前位置: 首页 > wzjs >正文

做寂网站品牌营销推广方案

做寂网站,品牌营销推广方案,颍东网站建设,建设银行益阳市分行桃江支行网站目录 一、代码流程 二、模块.c代码 三、模块.h代码 四、主函数代码 一、代码流程 1.模块复位:主机发送开始通信时序,从机做出响应(需检测是否有响应) 2.MCU读取1Bit数据 3.MCU读取1Byte数据 4.MCU读取8Byte数据组成完整Dat…

目录

一、代码流程

二、模块.c代码

三、模块.h代码

四、主函数代码


一、代码流程

1.模块复位:主机发送开始通信时序,从机做出响应(需检测是否有响应)

2.MCU读取1Bit数据

3.MCU读取1Byte数据

4.MCU读取8Byte数据组成完整Data,每读一次Data前都要开始通信流程

二、模块.c代码

#include "dht11.h"/********************等待从机响应:返回0表示初始化成功*************************/
uint8_t DHT11_Reset(void)
{RCC_APB2PeriphClockCmd(DHT11_CLK, ENABLE);GPIO_InitTypeDef GPIO_InitStruct;                    //主机控制引脚GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;GPIO_InitStruct.GPIO_Pin = DHT11_PIN;GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(DHT11_PORT, &GPIO_InitStruct);GPIO_ResetBits(DHT11_PORT, DHT11_PIN);               //主机发出开始通信的信号Delay_ms(20);GPIO_SetBits(DHT11_PORT, DHT11_PIN);Delay_us(13);GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;   //主机释放引脚控制权,转为输入模式监听引脚电平GPIO_InitStruct.GPIO_Pin = DHT11_PIN;GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init(DHT11_PORT, &GPIO_InitStruct);  uint8_t time = 0;while( (GPIO_ReadInputDataBit(DHT11_PORT, DHT11_PIN) == 0) && time < 100 )    //检测响应低电平是否正常{Delay_us(1);time++;}if(time >= 100){return 1; }else{time = 0;  }while( (GPIO_ReadInputDataBit(DHT11_PORT, DHT11_PIN) == 1) && time < 100)    //检测响应高电平是否正常{Delay_us(1);time++;}if(time >= 100){return 1;}else{time = 0;  } return 0;
}/**************************读1Bit*************************************/
uint8_t MCU_Read_Bit(void)
{ while( GPIO_ReadInputDataBit(DHT11_PORT, DHT11_PIN) == 1 );    //检测低电平到来while( GPIO_ReadInputDataBit(DHT11_PORT, DHT11_PIN) == 0 );    //检测高电平到来Delay_us(35);if( GPIO_ReadInputDataBit(DHT11_PORT, DHT11_PIN) == 1 )        //直接读取35us后的数据{return 1;}else{return  0;  }
}/**************************读1Byte****************************************/
uint8_t MCU_Read_Byte(void)
{uint8_t tool = 0x80;uint8_t Byte = 0;for(tool = 0x80; tool != 0; tool >>=1 )                      //DHT11数据高位先行,故从高位到低位读取数据{if( MCU_Read_Bit() == 1 )Byte |= tool;elseByte &= ~tool;}return Byte;
}/*****************读数据:返回0表示读取数据正确***********************/
uint8_t MCU_Read_Data(uint8_t* humidity, uint8_t* temperature)
{uint8_t Data[5] = {0};uint8_t i = 0;if( DHT11_Reset() == 0 )                                         //每次读数据前都要重新开始通信时序,不然只会有一次数据显示{for( i = 0; i < 5; i++){Data[i] = MCU_Read_Byte();                                   //将数据存入数组}if( (Data[0] + Data[1] + Data[2] + Data[3]) == Data[4] )       //如果校验位正确{*humidity = Data[0];                                         //读出数据*temperature = Data[2];return 0;                                                    //返回0表示读数据正确}      }return 1;                                                        //返回1表示读数据存在错误
}

三、模块.h代码

#ifndef __DHT11_H
#define __DHT11_H#include "stm32f10x.h"                  // Device header
#include "delay.h"
#include "serial.h"#define DHT11_CLK      RCC_APB2Periph_GPIOB
#define DHT11_PORT     GPIOB
#define DHT11_PIN      GPIO_Pin_14uint8_t DHT11_Reset(void);
uint8_t MCU_Read_Bit(void);
uint8_t MCU_Read_Byte(void);
uint8_t MCU_Read_Data(uint8_t* humidity, uint8_t* temperature);#endif

四、主函数代码

#include "stm32f10x.h"                  // Device header
#include "Delay.h"
#include "OLED.h"
#include "DHT11.h"int main(void)
{OLED_Init();	uint8_t test = 1;      //接收DHT11初始化是否成功的返回值uint8_t humidity = 0, temperature = 0; while (1){test = MCU_Read_Data(&humidity, &temperature);if(test == 0){OLED_ShowNum(1, 1, humidity, 2);OLED_ShowNum(2, 1, temperature, 2);  Delay_ms(500);      }OLED_ShowHexNum(3, 1, test, 1);}
}

http://www.dtcms.com/wzjs/169560.html

相关文章:

  • 怎么制作有效网站武汉seo哪家好
  • 山东济南seo整站优化费用百度网络优化推广公司
  • 企业网站案例展示推广系统
  • 网站建设完成的时间石家庄网站seo外包
  • 长沙房价一览表网站制作优化
  • 做hmtl的基本网站重庆seo网页优化
  • 嘉兴外贸网站制作武汉网站seo德升
  • 人人开发网站东莞网络推广
  • 南京网站建设有限公司seo是什么意思怎么解决
  • 将网站做成logo怎么做英文seo推广
  • 西安做网站xamokjseo中文意思
  • 网站开发研究前景公司seo是什么级别
  • 网站建设协议合同范本星链友店
  • 专门做旅游的网站有哪些网站排名推广推荐
  • 个人买卖网站怎么做短网址在线生成
  • 怎么建设自己网站关键词排名点击
  • 用单页做网站 文章直接写上去 百度收录关键词吗东莞网站建设市场
  • 鹰潭网站设计小程序排名优化
  • wordpress 更多文章杭州网站seo公司
  • 2015年手机网站需要主机 空间网络营销的特点举例说明
  • php网站建设模板网络游戏营销策略
  • 买好域名之后怎么做网站在线分析网站
  • 做网站运维成都网络营销公司哪家好
  • 企业网站建凤凰网全国疫情实时动态
  • 政府网站建设 问题bing搜索国内版
  • 南宁市建设工程质量安全协会网站推广平台怎么找客源
  • 动力无限做网站怎么样网站排名软件优化
  • 网站如何做分享搭建一个网站
  • 两学一做11月答题网站二级域名网址查询
  • 网站建设的网东莞公司seo优化