STM32使用IIC总线通讯协议在OLED屏幕上显示字符串、汉字、单总线获取DHT11模块温湿度并通过IIC显示到屏幕(软件IIC)

参考:基于stm32软件IIC的oled显示温湿度
作者:ZPZ DayUp
发布时间: 2021-07-25 20:52:43
网址:https://blog.csdn.net/m0_56197680/article/details/119077076?spm=1001.2014.3001.5501

目录

  • 软件模拟IIC时序(起始、停止、应答、发送、清屏、显示)在oled上显示字符串和汉字
    • oled.c代码
    • oled.h文件
    • oledfont.h字库头文件
  • DHT11温湿度模块
    • 供电电压:3.3 - 5.5V直流电
    • 与MCU接线
    • 数据格式
    • 温湿度传感器时序
  • 软件IIC显示温湿度
    • DHT11.c
    • DHT11.h
    • main.c
    • 显示效果

软件模拟IIC时序(起始、停止、应答、发送、清屏、显示)在oled上显示字符串和汉字

oled.c代码

#include "stm32f10x.h"
#include "oled.h"
#include "oledfont.h"
#include "delay.h"		//系统定时器static void OLED_GPIO_Init(void)		
{GPIO_InitTypeDef   	oled_GPIOstruct;		//oled管脚初始化RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );//PB0 ->SCL    PB1 ->SDA		oled_GPIOstruct.GPIO_Mode = GPIO_Mode_Out_OD;	//开漏输出oled_GPIOstruct.GPIO_Pin =GPIO_Pin_0 | GPIO_Pin_1 ; oled_GPIOstruct.GPIO_Speed = GPIO_Speed_50MHz;GPIO_Init( GPIOB, &oled_GPIOstruct);OLED_SCLK_Set();//头文件宏定义OLED_SDIN_Set();// 时钟线和数据线全部拉高 处于空闲状态
}//模拟IIC起始信号
static void OLED_IIC_Start(void)
{OLED_SCLK_Set();OLED_SDIN_Set();		delay_us(1);OLED_SDIN_ReSet();	//数据线拉低,产生下降沿delay_us(1);OLED_SCLK_ReSet();	//时钟线再数据线产生下降沿之后保持一段时间高电平后将其拉低,起始信号模拟完毕delay_us(1);
}//IIC模拟停止信号
static void OLED_IIC_Stop(void)
{OLED_SDIN_ReSet();OLED_SCLK_ReSet();delay_us(1);OLED_SCLK_Set();	//时钟线先拉高delay_us(1);OLED_SDIN_Set();	//数据线拉高,产生上升沿,至此停止信号模拟完毕delay_us(1);
}//IIC模拟读取从机应答信号
static unsigned char IIC_Wait_Ack(void)
{unsigned char Ask;OLED_SCLK_ReSet();		//时钟线拉低delay_us(1);OLED_SDIN_Set();		//数据线拉高delay_us(1);OLED_SCLK_Set();		//时钟线拉高//应答信号,在时钟线拉高之前产生下降沿并在时钟线拉高的情况下确保为低电平if(OLED_READ_SDIN())	//读取数据线电平为高电平{ack = IIC_NO_Ask;	//对应的应答信号为非应答信号}else{ack = IIC_Ask;		//对应信号为应答信号}OLED_SCLK_ReSet();		//接收完应答信号,时钟线拉低delay_us(1);return ack;
}//IIC写入(发送)一个字节byte  时钟高电平期间数据要保持稳定,时钟低电平时数据才可以改变
static void Write_IIC_Byte(unsigned char IIC_Byte)
{unsigned char i=0;for(i=0;i<8;i++)	         //从高到低循环写入{OLED_SCLK_ReSet();		//拉低时钟线,让后面数据可以改变delay_us(1);if(IIC_Byte & 0x80)		//1000 0000 读取第八位OLED_SDIN_Set();	//最高位为1,把数据线置高(通过高低电平传输数据)elseOLED_SDIN_ReSet(); 	//最高位为0,把数据线拉低IIC_Byte <<= 1; 		//数据左移1位,次高位变成最高位delay_us(1);OLED_SCLK_Set();		//传输并确认一位数据之后,时钟线拉高,读取这一位数据delay_us(1);}OLED_SCLK_ReSet();		//8位数据全部读完之后时钟线拉低		delay_us(1);while(IIC_Wait_Ack());	//等待应答信号通过!	
}//IIC写命令
static void Write_IIC_Command(unsigned char IIC_Command)
{OLED_IIC_Start();			//起始信号		Write_IIC_Byte(0x78);		//第一次发送从机地址Write_IIC_Byte(0x00);		//第二次发送命令地址(写入命令)Write_IIC_Byte(IIC_Command);//写入指定命令	OLED_IIC_Stop();			//发送停止信号
}//IIC写数据
static void Write_IIC_Data(unsigned char IIC_Data)
{OLED_IIC_Start();				Write_IIC_Byte(0x78);		//第一次发送从机地址Write_IIC_Byte(0x40);		//第二次发送数据地址(写入数据)Write_IIC_Byte(IIC_Data);	//写入指定数据	OLED_IIC_Stop();			//发送停止信号
}//对OLED写入一个字节
void OLED_Write_Byte(unsigned char dat,unsigned char cmd)
{if(cmd){Write_IIC_Data(dat);	//写数据}else{Write_IIC_Command(dat);//写命令}
}//设置OLED起点坐标
void SetPoint(unsigned char x,unsigned char y)
{	//x:列 //y:页 起始页的地址0-7OLED_Write_Byte(0xb0+y,OLED_CMD);		//写入页地址    写命令 起始页地址0xb0OLED_Write_Byte((x&0xf0>>4),OLED_CMD);	//列地址高四位  写命令OLED_Write_Byte(x&0x0f|0x10,OLED_CMD);	//列地址低四位  写命令
}
//开启屏幕显示
void OLED_Display()
{OLED_Write_Byte(0x8D,OLED_CMD);	//设置电荷泵OLED_Write_Byte(0xAF,OLED_CMD);//开启屏幕OLED_Write_Byte(0x14,OLED_CMD);//开启电荷泵
}
//关闭屏幕显示
void OLED_OFF()
{OLED_Write_Byte(0x8D,OLED_CMD);	//设置电荷泵OLED_Write_Byte(0xAE,OLED_CMD);//关闭屏幕OLED_Write_Byte(0x10,OLED_CMD);//关闭电荷泵
}
//清屏操作
void OLED_Clear()
{unsigned char i,n;for(i=0;i<8;i++)//总共有8页{OLED_Write_Byte(0xb0+i,OLED_CMD);//从0-7页依次写入	OLED_Write_Byte(0x00,OLED_CMD);	//列低地址	OLED_Write_Byte(0x10,OLED_CMD);	//列高地址		for(n=0;n<128;n++){OLED_Write_Byte(0,OLED_Data);//往128*64个像素点全部写入数据0	}}
}
//OLED显示字符函数
void OLED_Showcharactor(unsigned char x,unsigned char y,unsigned char chr)
{	//传入参数 x,y分别表示列和页  chr表示字符unsigned char c=0,i=0;c = chr - ' ';		//这里结合字库以及ASCII码可以知道 获取字符的偏移量	 if(x>MAX_Column)	//列超过最大长度 就从下两页的第0列开始{x = 0;		y = y+2;	  	//字符8x16大小,故页要一次性加两行}if(SIZE == 16)		//字符大小如果为16 = 8*16{OLED_SetPoint(x,y);	//设置OLED起点坐标	for(i=0;i<8;i++)OLED_Write_Byte(F8X16[c*16+i],OLED_Data);//找出字符C的数组位数,先把第一列画完OLED_SetPoint(x,y+1);for(i=8;i<16;i++)//先显示8个 再显示8个OLED_Write_Byte(F8X16[c*16+i],OLED_Data);}else				// 6*8{OLED_SetPoint(x,y);for(i=0;i<6;i++)OLED_Write_Byte(F6x8[c][i],OLED_Data);}
}//OLED显示字符串函数
void OLED_ShowString(unsigned char x,unsigned char y,unsigned char *chr)
{unsigned char j = 0;while(chr[j]!='\0')	//循环遍历字符串 判断是不是最后一个字符{OLED_Showcharactor(x,y,chr[j]);	//调用之前的显示单个字符函数	x+=8;//列数+8  一个字符占8			if(x>=128){x=0;//第一列显示y+=2;//换页}j++;}
}
//计算m^n次方函数
unsigned int OLED_Pow(unsigned char m,unsigned char n)
{unsigned int result = 1;while(n--)result*=m;return result;
}
//OLED显示数字函数
void OLED_ShowNum(unsigned char x,unsigned char y,unsigned int num,unsigned char len,unsigned char size)
{//传入参数 x,y 列和页;  num 对应数字;  len 数字长数;  size 字体大小unsigned char t,temp;unsigned char enshow = 0;	//是否为第一个数是否为0的标志for(t=0;t<len;t++){temp = (num/OLED_Pow(10,len-t-1))%10;	//从高到低依次获取数据if(enshow==0&&t<(len-1))//enshow:是否为第一个数;t<(len-1):判断是否为最后一个数{	if(temp==0)	//该数为0	{	OLED_Showcharactor(x+(size/2)*t,y,' ');//显示 0 ;x+(size2/2)*t根据字体大小偏移的列数(8)continue;	//跳出当前循环,避免重复显示}else enshow=1;}OLED_Showcharactor(x+(size/2)*t,y,temp+'0');//显示一个位;x+(size2/2)*t根据字体大小偏移的列数(8)}
}//OLED显示汉字函数
void OLED_ShowChinese(unsigned char x,unsigned char y,unsigned char no)
{//参数 x,y 列和页;	no 代表某个汉字在汉字库中位于第几个unsigned char t,adder=0;OLED_SetPoint(x,y);for(t=0;t<16;t++){					   //一个字是两个16位OLED_Write_Byte(Hzk[2*no][t],OLED_Data);//画 no在数组位置的第一页16列的点adder+=1;//数组地址+1	}OLED_SetPoint(x,y+1);//画第二页,下半部分for(t=0;t<16;t++){                      //一个字是两个16位OLED_Write_Byte(Hzk[2*no+1][t],OLED_Data);//画 no在数组位置的第二页16列的点adder+=1;		}
}void OLED_Init(void)///复制过来直接用
{OLED_GPIO_Init();	delay_ms(200);	OLED_Write_Byte(0xAE,OLED_CMD);	OLED_Write_Byte(0x00,OLED_CMD);	OLED_Write_Byte(0x10,OLED_CMD);	OLED_Write_Byte(0x40,OLED_CMD);	OLED_Write_Byte(0xB0,OLED_CMD);	OLED_Write_Byte(0x81,OLED_CMD); 	OLED_Write_Byte(0xFF,OLED_CMD);OLED_Write_Byte(0xA1,OLED_CMD);	OLED_Write_Byte(0xA6,OLED_CMD);	OLED_Write_Byte(0xA8,OLED_CMD);	OLED_Write_Byte(0x3F,OLED_CMD);	OLED_Write_Byte(0xC8,OLED_CMD);	OLED_Write_Byte(0xD3,OLED_CMD);	OLED_Write_Byte(0x00,OLED_CMD);	OLED_Write_Byte(0xD5,OLED_CMD);	OLED_Write_Byte(0x80,OLED_CMD);	OLED_Write_Byte(0xD9,OLED_CMD);	OLED_Write_Byte(0xF1,OLED_CMD);	OLED_Write_Byte(0xDA,OLED_CMD);	OLED_Write_Byte(0x12,OLED_CMD);	OLED_Write_Byte(0xDB,OLED_CMD);	OLED_Write_Byte(0x40,OLED_CMD);OLED_Write_Byte(0x8D,OLED_CMD);OLED_Write_Byte(0x14,OLED_CMD);OLED_Write_Byte(0xAF,OLED_CMD);OLED_Clear();       OLED_SetPoint(0,0); 	 
}

oled.h文件

#ifndef _OLED_H_
#define _OLED_H_
#include "stm32f10x.h"//防止头文件重复编译 包含#define OLED_SCLK_Set()      GPIO_SetBits(GPIOB,GPIO_Pin_0)		
#define OLED_SCLK_ReSet()  	 GPIO_ResetBits(GPIOB, GPIO_Pin_0) 
#define OLED_SDIN_Set()		 GPIO_SetBits(GPIOB,GPIO_Pin_1)	 
#define OLED_SDIN_ReSet()    GPIO_ResetBits(GPIOB,GPIO_Pin_1)	 
#define OLED_READ_SDIN()     GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1)#define IIC_Ask     0		
#define IIC_NO_Ask  1  #define OLED_CMD	0		
#define OLED_Data   1		
#define MAX_Column  128	
#define SIZE		16		static void OLED_GPIO_Init(void);		
static void OLED_IIC_Start(void);
static void OLED_IIC_Stop(void);
static unsigned char IIC_Wait_Ack(void);
static void Write_IIC_Byte(unsigned char IIC_Byte);
static void Write_IIC_Command(unsigned char IIC_Command);
static void Write_IIC_Data(unsigned char IIC_Data);
void OLED_Write_Byte(unsigned char dat,unsigned char cmd);
void OLED_SetPoint(unsigned char x,unsigned char y);
void OLED_Display(void);			
void OLED_OFF(void)	;					
void OLED_Clear(void);
void OLED_Fill(void);
void OLED_Showcharactor(unsigned char x,unsigned char y,unsigned char chr);
void OLED_Init(void);
void OLED_ShowString(unsigned char x,unsigned char y,unsigned char *chr);
unsigned int OLED_Pow(unsigned char m,unsigned char n);
void OLED_ShowNum(unsigned char x,unsigned char y,unsigned int num,unsigned char len,unsigned char size);
void OLED_ShowChinese(unsigned char x,unsigned char y,unsigned char no);
#endif

oledfont.h字库头文件

#ifndef __OLEDFONT_H
#define __OLEDFONT_H 	   
//常用ASCII表
//偏移量32
//ASCII字符集
//偏移量32
//大小:12*6
/************************************6*8的点阵************************************/
const unsigned char  F6x8[][6] =		
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00,// sp
0x00, 0x00, 0x00, 0x2f, 0x00, 0x00,// !
0x00, 0x00, 0x07, 0x00, 0x07, 0x00,// "
0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14,// #
0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12,// $
0x00, 0x62, 0x64, 0x08, 0x13, 0x23,// %
0x00, 0x36, 0x49, 0x55, 0x22, 0x50,// &
0x00, 0x00, 0x05, 0x03, 0x00, 0x00,// '
0x00, 0x00, 0x1c, 0x22, 0x41, 0x00,// (
0x00, 0x00, 0x41, 0x22, 0x1c, 0x00,// )
0x00, 0x14, 0x08, 0x3E, 0x08, 0x14,// *
0x00, 0x08, 0x08, 0x3E, 0x08, 0x08,// +
0x00, 0x00, 0x00, 0xA0, 0x60, 0x00,// ,
0x00, 0x08, 0x08, 0x08, 0x08, 0x08,// -
0x00, 0x00, 0x60, 0x60, 0x00, 0x00,// .
0x00, 0x20, 0x10, 0x08, 0x04, 0x02,// /
0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
0x00, 0x00, 0x42, 0x7F, 0x40, 0x00,// 1
0x00, 0x42, 0x61, 0x51, 0x49, 0x46,// 2
0x00, 0x21, 0x41, 0x45, 0x4B, 0x31,// 3
0x00, 0x18, 0x14, 0x12, 0x7F, 0x10,// 4
0x00, 0x27, 0x45, 0x45, 0x45, 0x39,// 5
0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
0x00, 0x01, 0x71, 0x09, 0x05, 0x03,// 7
0x00, 0x36, 0x49, 0x49, 0x49, 0x36,// 8
0x00, 0x06, 0x49, 0x49, 0x29, 0x1E,// 9
0x00, 0x00, 0x36, 0x36, 0x00, 0x00,// :
0x00, 0x00, 0x56, 0x36, 0x00, 0x00,// ;
0x00, 0x08, 0x14, 0x22, 0x41, 0x00,// <
0x00, 0x14, 0x14, 0x14, 0x14, 0x14,// =
0x00, 0x00, 0x41, 0x22, 0x14, 0x08,// >
0x00, 0x02, 0x01, 0x51, 0x09, 0x06,// ?
0x00, 0x32, 0x49, 0x59, 0x51, 0x3E,// @
0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C,// A
0x00, 0x7F, 0x49, 0x49, 0x49, 0x36,// B
0x00, 0x3E, 0x41, 0x41, 0x41, 0x22,// C
0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C,// D
0x00, 0x7F, 0x49, 0x49, 0x49, 0x41,// E
0x00, 0x7F, 0x09, 0x09, 0x09, 0x01,// F
0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A,// G
0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F,// H
0x00, 0x00, 0x41, 0x7F, 0x41, 0x00,// I
0x00, 0x20, 0x40, 0x41, 0x3F, 0x01,// J
0x00, 0x7F, 0x08, 0x14, 0x22, 0x41,// K
0x00, 0x7F, 0x40, 0x40, 0x40, 0x40,// L
0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F,// M
0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F,// N
0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E,// O
0x00, 0x7F, 0x09, 0x09, 0x09, 0x06,// P
0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
0x00, 0x7F, 0x09, 0x19, 0x29, 0x46,// R
0x00, 0x46, 0x49, 0x49, 0x49, 0x31,// S
0x00, 0x01, 0x01, 0x7F, 0x01, 0x01,// T
0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F,// U
0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F,// V
0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F,// W
0x00, 0x63, 0x14, 0x08, 0x14, 0x63,// X
0x00, 0x07, 0x08, 0x70, 0x08, 0x07,// Y
0x00, 0x61, 0x51, 0x49, 0x45, 0x43,// Z
0x00, 0x00, 0x7F, 0x41, 0x41, 0x00,// [
0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55,// 55
0x00, 0x00, 0x41, 0x41, 0x7F, 0x00,// ]
0x00, 0x04, 0x02, 0x01, 0x02, 0x04,// ^
0x00, 0x40, 0x40, 0x40, 0x40, 0x40,// _
0x00, 0x00, 0x01, 0x02, 0x04, 0x00,// '
0x00, 0x20, 0x54, 0x54, 0x54, 0x78,// a
0x00, 0x7F, 0x48, 0x44, 0x44, 0x38,// b
0x00, 0x38, 0x44, 0x44, 0x44, 0x20,// c
0x00, 0x38, 0x44, 0x44, 0x48, 0x7F,// d
0x00, 0x38, 0x54, 0x54, 0x54, 0x18,// e
0x00, 0x08, 0x7E, 0x09, 0x01, 0x02,// f
0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C,// g
0x00, 0x7F, 0x08, 0x04, 0x04, 0x78,// h
0x00, 0x00, 0x44, 0x7D, 0x40, 0x00,// i
0x00, 0x40, 0x80, 0x84, 0x7D, 0x00,// j
0x00, 0x7F, 0x10, 0x28, 0x44, 0x00,// k
0x00, 0x00, 0x41, 0x7F, 0x40, 0x00,// l
0x00, 0x7C, 0x04, 0x18, 0x04, 0x78,// m
0x00, 0x7C, 0x08, 0x04, 0x04, 0x78,// n
0x00, 0x38, 0x44, 0x44, 0x44, 0x38,// o
0x00, 0xFC, 0x24, 0x24, 0x24, 0x18,// p
0x00, 0x18, 0x24, 0x24, 0x18, 0xFC,// q
0x00, 0x7C, 0x08, 0x04, 0x04, 0x08,// r
0x00, 0x48, 0x54, 0x54, 0x54, 0x20,// s
0x00, 0x04, 0x3F, 0x44, 0x40, 0x20,// t
0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C,// u
0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C,// v
0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C,// w
0x00, 0x44, 0x28, 0x10, 0x28, 0x44,// x
0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C,// y
0x00, 0x44, 0x64, 0x54, 0x4C, 0x44,// z
0x14, 0x14, 0x14, 0x14, 0x14, 0x14,// horiz lines
};
/****************************************8*16的点阵************************************/
const unsigned char  F8X16[]=	  
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 00x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//! 10x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//" 20x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//# 30x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$ 40xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//% 50x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//& 60x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//' 70x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//( 80x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//) 90x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//* 100x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+ 110x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//, 120x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//- 130x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//. 140x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,/// 150x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//0 160x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//1 170x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//2 180x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//3 190x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//4 200x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//5 210x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//6 220x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//7 230x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//8 240x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//9 250x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//: 260x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//; 270x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//< 280x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//= 290x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//> 300x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//? 310xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@ 320x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A 330x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B 340xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C 350x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D 360x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E 370x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F 380xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G 390x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H 400x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I 410x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J 420x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K 430x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L 440x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M 450x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N 460xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O 470x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P 480xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q 490x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R 500x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S 510x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T 520x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U 530x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V 540xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W 550x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X 560x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y 570x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z 580x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[ 590x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\ 600x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//] 610x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^ 620x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_ 630x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//` 640x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a 650x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b 660x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c 670x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d 680x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e 690x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f 700x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g 710x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h 720x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i 730x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j 740x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k 750x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l 760x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m 770x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n 780x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o 790x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p 800x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q 810x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r 820x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s 830x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t 840x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u 850x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v 860x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w 870x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x 880x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y 890x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z 900x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{ 910x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//| 920x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//} 930x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~ 94
};
const unsigned char  Hzk[][32]={{0x10,0x10,0x10,0xFF,0x10,0x90,0x08,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x08,0x00},
{0x04,0x44,0x82,0x7F,0x01,0x80,0x80,0x40,0x43,0x2C,0x10,0x28,0x46,0x81,0x80,0x00},/*"技",0*/{0x40,0x44,0x54,0x65,0xC6,0x64,0x54,0x44,0x00,0xFC,0x44,0x44,0xC4,0x42,0x40,0x00},
{0x20,0x12,0x4A,0x82,0x7F,0x02,0x0A,0x92,0x60,0x1F,0x00,0x00,0xFF,0x00,0x00,0x00},/*"新",1*/{0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00},
{0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00},/*"电",2*/{0x80,0x82,0x82,0x82,0x82,0x82,0x82,0xE2,0xA2,0x92,0x8A,0x86,0x82,0x80,0x80,0x00},
{0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"子",3*/{0x24,0x24,0xA4,0xFE,0xA3,0x22,0x00,0x22,0xCC,0x00,0x00,0xFF,0x00,0x00,0x00,0x00},
{0x08,0x06,0x01,0xFF,0x00,0x01,0x04,0x04,0x04,0x04,0x04,0xFF,0x02,0x02,0x02,0x00},/*"科",4*/{0x10,0x10,0x10,0xFF,0x10,0x90,0x08,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x08,0x00},
{0x04,0x44,0x82,0x7F,0x01,0x80,0x80,0x40,0x43,0x2C,0x10,0x28,0x46,0x81,0x80,0x00},/*"技",5*/{0x00,0x00,0x00,0x10,0x20,0x60,0x00,0xFC,0x04,0x40,0xA0,0x98,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x01,0x41,0x49,0x49,0x29,0x25,0x25,0x24,0x3F,0x01,0x00,0x00,0x00},/*"当",6*/{0x00,0x20,0x20,0xA0,0xA0,0xA4,0xA8,0x20,0x20,0x98,0x16,0xF0,0x10,0x10,0x10,0x00},
{0x00,0x00,0x00,0x1F,0x0A,0x2A,0x7F,0x00,0x00,0x0F,0x20,0x6F,0x30,0x00,0x00,0x00},/*"前",7*/{0x00,0x00,0x40,0x08,0x18,0x00,0x08,0xF8,0xA8,0x68,0x68,0x74,0x18,0x00,0x00,0x00},
{0x00,0x00,0x30,0x0E,0x22,0x20,0x3E,0x22,0x1E,0x12,0x2E,0x22,0x1F,0x12,0x00,0x00},/*"温",8*/{0x00,0x00,0x00,0x00,0xF0,0x90,0xB0,0xF0,0x56,0xD8,0x28,0x48,0x00,0x00,0x00,0x00},
{0x00,0x20,0x10,0x0C,0x43,0x40,0x40,0x2D,0x13,0x1E,0x22,0x60,0x40,0x40,0x40,0x00},/*"度",9*/{0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x31,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*":",10*/{0x00,0x0C,0x12,0x0C,0x00,0xC0,0x70,0x10,0x08,0x08,0x08,0x08,0x10,0x30,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x0F,0x18,0x30,0x20,0x20,0x20,0x20,0x30,0x1C,0x00,0x00},/*"℃",11*/{0x00,0x00,0x40,0x08,0x08,0x08,0xF8,0xA8,0xA8,0x58,0x48,0x7C,0x08,0x00,0x00,0x00},
{0x00,0x00,0x38,0x06,0x20,0x20,0x2C,0x3D,0x23,0x21,0x3F,0x24,0x23,0x20,0x20,0x00},/*"湿",12*/{0x00,0xF0,0xF8,0x08,0x88,0xF8,0xF0,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x00},
{0x00,0x00,0x00,0x21,0x18,0x0C,0x02,0x01,0x00,0x1E,0x3F,0x21,0x21,0x1E,0x1E,0x00},/*"%",13*/{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",14*/{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x10,0x30,0x30,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*".",15*/};#endif

DHT11温湿度模块

在这里插入图片描述

供电电压:3.3 - 5.5V直流电

输出为单总线数字信号
温度测量范围0-50度(精度正负2度,分辨率1度)
湿度测量范围为20-90%RH(精度为正负5%,分辨率1%)

与MCU接线

在这里插入图片描述

数据格式

采用单总线双向串行通信协议,每次采集都要由单片机发起开始信号,然后DHT11会向单片机发送响应并开始传输40位数据帧,高位在前。 数据格式40帧(40bit)

  • 湿度整数部分+湿度小数部分 8bit + 8bit
  • 温度整数部分+温度小数部分 8bit + 8bit
  • 校验位部分 8bit

数据校验
湿度和温度的整数小数部分全部加起来判断是否与校验位部分相等,若相等,则取出数据;否之,数据重新获取湿度小数部分和温度小数部分单片机都默认为0,即校验位只会判断两者的整数部分和

例如
湿度 0101 0011 + 0000 0000
温度 0011 0010 + 0000 0000
校验位 1000 0101

此时湿度和温度的整数部分之和恰好等于校验位的,所以这组数据符合要求。

温湿度传感器时序


在这里插入图片描述

主机:单片机
从机:传感器

  • 总线空闲状态高电平

  • 主机将总线拉低,要求大于18ms,等待DHT11响应 (主机发送起始信号)

  • 从机(DHT11模块)接收主机起始信号后,等待主机起始信号结束

  • DHT11发送80us的低电平响应信号

  • 主机发送起始信号结束后,延时20-40us后读取DHT11的响应信号

  • 主机发送完开始信号,可以切换到输入模式或者接上拉电阻置高电平

在这里插入图片描述

软件IIC显示温湿度

DHT11.c

#include "stm32f10x.h"
#include "DHT11.h"
#include "delay.h"
#include "stdio.h"uint16_t Rxbuff[5];/*单总线,双向串行输出协议,故配置对应端口输入输出*/
void DHT11_GPIO_Init(void)
{GPIO_InitTypeDef  GPIO_InitStructure;//PB11 ->DHT11模块数据输出口	RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB,  ENABLE);GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_Out_PP;GPIO_InitStructure.GPIO_Pin  =  GPIO_Pin_11;GPIO_InitStructure.GPIO_Speed =  GPIO_Speed_50MHz;GPIO_Init(GPIOB, &GPIO_InitStructure);GPIO_SetBits(GPIOB,  GPIO_Pin_11);}void DHT11_GPIO_Init1(void)
{GPIO_InitTypeDef  GPIO_InitStructure;//PB11->DHT11模块数据输入口RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB,  ENABLE);GPIO_InitStructure.GPIO_Mode =  GPIO_Mode_IPD;//下拉输入GPIO_InitStructure.GPIO_Pin  =  GPIO_Pin_11;GPIO_InitStructure.GPIO_Speed =  GPIO_Speed_50MHz;GPIO_Init(GPIOB, &GPIO_InitStructure);GPIO_SetBits(GPIOB,  GPIO_Pin_11);}
//温湿度模块响应信号
static uint8_t DHT11_Back()
{uint8_t i =200;while(read_data && i--);   //等待低电平的到来i= 200;					//低电平延迟一会(80us)while(!read_data && i--);  //等待高电平的到来return 0;
}//起始信号
void DHT11_Start(void)
{data0;//置低delay_ms(20);//主机拉低总线超过18ms	data1;//置高delay_us(10);DHT11_GPIO_Init1();//此时单片机由输出转成输入模式,等待模块相应while(DHT11_Back());
}//DHT11模块读取数据函数
void DHT11_ReceptionBuff()
{uint8_t y=1;uint16_t i;uint8_t x;for(x=0;x<5;x++)//模块一共发送5个字节{i=0;for(y=1;y<9;y++)//每个字节8位{while(read_data)//接收低电平{__nop();//空操作			 }delay_us(40);while(!read_data)//接收高电平{__nop();			 }i= i<<1;delay_us(30);//看上面的时序,高电平持续26-28us内代表0  超过则为1,所以这里选择30us分界线if(read_data)//判断是否为1{i |=1;			 }while(read_data);//等待低电平 进行下一次循环			}	Rxbuff[x] =i;//检验在后面main函数进行的}
}void DHT11_UpdateData()
{DHT11_GPIO_Init();DHT11_Start();DHT11_ReceptionBuff();
}

DHT11.h

#ifndef _DHT11_H_
#define _DHT11_H_
#include "stm32f10x.h"#define data1 GPIO_SetBits(GPIOB,  GPIO_Pin_11)			
#define data0 GPIO_ResetBits(GPIOB,  GPIO_Pin_11)		
#define read_data GPIO_ReadInputDataBit(GPIOB,  GPIO_Pin_11) void DHT11_GPIO_Init_IN(void);		
void DHT11_GPIO_Init_OUT(void);		
void DHT11_Start(void);
void DHT11_ReceptionBuff(void);
void DHT11_UpdataData(void);
extern uint16_t Rxbuff[5];
#endif

main.c

#include "stm32f10x.h"
#include "main.h"
#include "oled.h"
#include "delay.h"
#include "sys.h"
#include "DHT11.h" 
int  main()
{initSysTick();delay_ms(1000);OLED_Init();//oled初始化OLED_Clear();//oled清屏	delay_ms(1000);//让OLED显示下列一些字  在字库头文件里(字模软件生成)OLED_ShowChinese(0,2,6);		//当   都显示在第二页	OLED_ShowChinese(16,2,7);		//前OLED_ShowChinese(32,2,8);		//温OLED_ShowChinese(48,2,9);		//度OLED_ShowChinese(66,2,10);		//:OLED_ShowChinese(90,2,15);		//.OLED_ShowChinese(112,2,11);		//℃//这种都来自于字库文件 oledfont.hOLED_ShowChinese(0,5,6);		//当OLED_ShowChinese(16,5,7);		//前OLED_ShowChinese(32,5,12);		//湿OLED_ShowChinese(48,5,9);		//度OLED_ShowChinese(66,5,10);		//:OLED_ShowChinese(90,5,15);		//.OLED_ShowChinese(112,5,13);		//%while(1){uint16_t i;uint8_t  Tempture ;uint8_t  Wet ;uint8_t  xiaoshu ;		DHT11_UpdataData();//DHT11模块更新数据i = Rxbuff[0] + Rxbuff[1] + Rxbuff[2] + Rxbuff[3];if(Rxbuff[4]==i)		//校验成功	{Tempture = Rxbuff[2];		//温度整数Wet = Rxbuff[0];			//湿度整数xiaoshu = Rxbuff[3];		//温度小数部分(教程湿度小数部分没处理)OLED_ShowNum(74,2,Tempture/10,3,3);OLED_ShowNum(82,2,Tempture%10,3,3);OLED_ShowNum(98,2,xiaoshu,3,3);OLED_ShowNum(88,5,Wet/10,3,3);OLED_ShowNum(98,5,xiaoshu%10,3,3);}delay_ms(2000);}

显示效果

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/265325.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

w ndows7端口在哪里,win7电脑遇到端口被占用的情况该如何查看并将其关闭

Windows7操作系统的酷炫和强大已经深受用户们的喜欢了&#xff0c;这里根大家分享的是教你查看win7电脑端口是否被占用的技巧&#xff0c;端口是我们在进行远程或者打印机等都会遇到的&#xff0c;但是有很多用户会遇到端口被占用的情况&#xff0c;遇到这样的问题首先就要找出…

STM32F103五分钟入门系列(十三)独立看门狗IWDG

参考&#xff1a;STM32F103五分钟入门系列&#xff08;十三&#xff09;独立看门狗IWDG 作者&#xff1a;自信且爱笑‘ 发布时间&#xff1a;2021-07-31 19:50:28 网址&#xff1a;https://blog.csdn.net/Curnane0_0/article/details/119269391?utm_sourceapp&app_version…

android自动软键盘,Android自定义软键盘

MyKeyboardAndroid自定义键盘的使用实现步骤第一步&#xff1a;1、新建一个xml文件夹放在res目录下面&#xff0c;然后新建xml文件:money_keyboard.xml2、然后在XML文件中添加按钮布局&#xff0c;这个布局就是键盘的样子了android:horizontalGap"1dp"android:keyWid…

Bootstrap使用-1

目录 结构&#xff1a;1. 视图函数2. 模板3. 登陆4. 怎样发生的添加模板基础模板提供的block定制基础模板结构&#xff1a; $ tree -I "__pycache*|*.pyc|*.xlsx" -FCL 3 . |-- templates/ | -- h1.html -- test-boostracp.py 1. 视图函数 test-boostracp.py from …

段错误、内存溢出、内存泄漏(区别)、堆溢出、栈溢出

参考&#xff1a;内存泄漏、内存溢出、段错误、堆溢出、栈溢出 作者&#xff1a;焦木白 发布时间&#xff1a;2019-10-22 网址&#xff1a;https://blog.csdn.net/jiaomubai/article/details/102680705?spm1001.2014.3001.5501 目录段错误内存溢出内存泄漏栈溢出堆溢出段错误 …

C语言中指针的地址和内容

参考&#xff1a;C语言中指针的地址和内容 作者&#xff1a;wallying 发布时间&#xff1a;2018-10-18 09:47:54 网址&#xff1a;https://blog.csdn.net/qq_36631580/article/details/89375140?spm1001.2014.3001.5502 #include <stdio.h>//一般用"地址"表示…

android运行过程简书,android 启动过程(一)

1、由init.rc调用 app_main.cpp的main方法&#xff0c;启动zygote进程3、调用AndroidRuntime.cpp 的start方法传递ZygoteInit类路径5、AndroidRuntime.cpp的start方法主要启动java虚拟机跟注册虚拟机&#xff0c;调用ZygoteInit的main方法6、ZygoteInit的main方法主要 把zygote…

回调函数 —— 借助中间通用函数(形参里有函数指针,实现函数注册)调用不同的回调函数 (多态/分层)

回调函数传参&#xff1a;函数指针做函数参数&#xff08;回调函数&#xff09; 目录背景回调函数是实现函数分层且单向依赖的好办法&#xff0c;使用函数指针运行struct结构体回调函数代码更清晰简单理解回调函数Demo其他回调函数博文背景 这是我在实际工作中遇到的问题&…

ESP8266等模块

模块讲解学习视频可参照&#xff1a;https://space.bilibili.com/323745961?spm_id_from333.788.b_765f7570696e666f.1 作者&#xff1a;叁议电子 目录ESP8266 WIFI模块介绍电脑操作ESP8266单片机上网ESP8266 WIFI模块介绍 电脑操作ESP8266 单片机上网

html5在线音乐列表播放器,HTML5列表音乐播放器SMusic

插件描述&#xff1a;一款基于HTML5、Css3的列表式音乐播放器&#xff0c;包含列表&#xff0c;音量&#xff0c;进度&#xff0c;时间&#xff0c;歌词展示以及模式等功能&#xff0c;不依赖任何库SMusic使用方法这是一款基于HTML5以及CSS3的列表式音乐播放器&#xff0c;增加…

unzipping/Users/xq/.gradle/wrapper /dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9/gradle-3.3-all.zi

unzipping/Users/xq/.gradle/wrapper /dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9/gradle-3.3-all.zip to /Users/xq/.gradle/wrapper/dists/gradle-3.3-all/55gk2rcmfc6p2dg9u9ohc3hw9 可能是下载时网络原因造成文件缺失 解决方法&#xff1a; cd /Users/xq/.gradle/w…

WIFI小车APP

对应这篇文章&#xff1a;433M射频遥控灯、震动感应灯、WIFI避障小车 目录代码概要activity_contrl.xmlContrlActivity.javaNetUtils.java详细工程代码下载代码概要 activity_contrl.xml <RelativeLayout xmlns:android"http://schemas.android.com/apk/res/android&qu…

[Web App]必胜客宅急送产品设计思路介绍[转]

O2O模式是餐饮业在移动消费趋势下主动拥抱互联网的方向&#xff0c;迎合餐饮消费者从以往经验判断为主转变为依靠移动设备、LBS、社交网络进行立体决策的过程。App成为联系消费者和餐饮业的重要纽带&#xff0c;承载着在O2O双向流程的闭环中加深消费者对品牌的认同和感情认知的…

使用Raphael实现html中绘图

2019独角兽企业重金招聘Python工程师标准>>> 首先&#xff1a;下载Raphael的javascript库&#xff1a;http://raphaeljs.com/。或者在html页面<head></head>&#xff1a;如下 <script src"http://www.zfanw.com/blog/raphael.js"></…

vivo手机刷机鸿蒙,捡到vivo手机如何刷机

捡到手机&#xff0c;首先建议归还给失主&#xff01;然后如果需要刷机的话&#xff0c;建议可以清除账户密码&#xff1a;可以尝试在手机关机状态同时按住音量上键以及电源键3到4秒手机出现vivo手机标志后&#xff0c;放开按键进入recovery模式&#xff0c;先选择wipe data/fa…

详解ROM和RAM

参考&#xff1a;详解ROM和RAM 作者&#xff1a;嵌入式实验楼 网址&#xff1a;https://mp.weixin.qq.com/s/FhUxMLeAxkhWe5m-gV_hMw 目录1、只读存储器&#xff1a;ROM2、随机访问存储器&#xff1a;RAM内存是计算系统最重要的元素&#xff0c;因为没有它&#xff0c;计算机就…

深入理解STM32内存管理

更多干货推荐可以去牛客网看看&#xff0c;他们现在的IT题库内容很丰富&#xff0c;属于国内做的很好的了&#xff0c;而且是课程刷题面经求职讨论区分享&#xff0c;一站式求职学习网站&#xff0c;最最最重要的里面的资源全部免费&#xff01;&#xff01;&#xff01;点击进…

html 手写字效果,canvas画布实现手写签名效果的示例代码

最近项目中涉及到移动端手写签名的功能需求&#xff0c;将实现代码记录于此&#xff0c;供小伙伴们参考指摘哦~HTML代码&#xff1a;手写区清除确定CSS样式&#xff1a;.mSign_signMark_box{padding: 15px 15px 26px 15px;}.mSign_signMark_footer{max-width:640px;margin:0 au…

FTP云盘

参考&#xff1a;FTP云盘项目 作者&#xff1a;糯米啊啊 发布时间&#xff1a; 2021-08-19 10:34:05 网址&#xff1a;https://blog.csdn.net/weixin_43732386?spm1001.2014.3001.5509 参考&#xff1a;自制FTP云盘项目 作者&#xff1a;不说话的小脑斧 发布时间&#xff1a; …

html transform属性,css3 transform属性详解

CSS3变形是一些效果的集合&#xff0c;比如平移translate() 、旋转rotate()、缩放scare()和倾斜skew()效果&#xff0c;每个效果都被称作为变形函数(Transform Function),它们可以操控元素发生旋转、缩放、和平移等变化。CSS3的2D transform函数包括了translate()、scale()、ro…