文章目录
- 一.温湿度原理
- 1.1 时序图
- 二.代码
一.温湿度原理
1.1 时序图
(1).下图一是DHT11总的时序图。
(2).图二对应图一的左边黑色部分,图三对应图一的绿色部分,图四的左部分图对应图一的红色部分,图四的右部分对应图一的黄色部分。
(3).首先图二部分是单片机向DHT11发送我要开始的信号,此时单片机IO口处于输出模式,输出低电平至少18MS,之后释放主机总线(高电平),时间是为图五的第二行,之后把单片机IO口设置为输入模式,在图三中,83us拉低和87us拉高是DHT11对单片机的响应时间,也就是回应它我收到了,这时候可以用whille循环卡着,之后87us的高电平过去以后,变成了在图三开始发送数据位置(低电平),也就是图四的54us的位置,54us是准备发送数据,54us一旦过去就变成了高电平,高电平持续时间的多少决定了DHT11发送给单片机的数据0还是1,23us-27us是数据0,68us-74us是数据1,那么我们可以延时30us,如果30us过后还是高电平就是数据1,如果变成了低电平就是数据0,这里要注意,延时30us后,如果是数据1,数据1延时时间还未到,所以可以用while循环卡着它的时间过去,具体看下面代码。
(2).
图一
图二
图三
图四
图五
二.代码
main.c
#include "stm32f10x.h"
#include "Delay.h"
#include "OLED.h"
#include "DHT11.h"int main(void)
{OLED_Init();Oled_clear();while (1){if(DHT_Read()==1){Oled_8_16(0,0,datas[0]/10);//HOled_8_16(8,0,datas[0]%10);Oled_8_16(16,0,13);//.Oled_8_16(24,0,datas[1]/10);Oled_8_16(32,0,datas[1]%10);Oled_8_16(0,2,datas[2]/10);//TOled_8_16(8,2,datas[2]%10);Oled_8_16(16,2,13);//.Oled_8_16(24,2,datas[3]/10);Oled_8_16(32,2,datas[3]%10);}Delay_ms(500);Delay_ms(500);Delay_ms(500);Delay_ms(500);Delay_ms(500);Delay_ms(500);Delay_ms(500);Delay_ms(500);}
}
DHT11.c
#include "stm32f10x.h" // Device header
#include "Dht11.h"
#include "Delay.h"char datas[5]; //数组分别代表,湿度,湿度小数,温度,温度小数,校验和void DHT11_Init_Out(void)
{RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);GPIO_InitTypeDef GPIO_InitStruct;GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;GPIO_InitStruct.GPIO_Pin=GPIO_Pin_4;GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOA,&GPIO_InitStruct);
}void DHT11_Init_In(void)
{RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);GPIO_InitTypeDef GPIO_InitStruct;GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IPU;GPIO_InitStruct.GPIO_Pin=GPIO_Pin_4;GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;GPIO_Init(GPIOA,&GPIO_InitStruct);
}//初始化模块(检测模块是否存在)每次传输数据都要初始化
uint8_t DHT_Start()
{DHT11_Init_Out();//输出模式//根据时序进行高低电平变化dhtout = 0;Delay_ms(20);dhtout=1;Delay_us(20);//主机拉高20usDHT11_Init_In();//输入状态if(!dhtin) //判断DHT有没有响应信号,dhtin =0的话则代表DHT发送了响应信号{while(!dhtin);//DHT正在发送响应信号,dhtin =0,等待变为高电平(dhtin =1)则退出循环while(dhtin);//dhtin =1,DHT处于高电平状态,等待变为低电平则退出循环,则代表开始传送数据return 1;//代表开始传送数据}return 0;//代表没有开始传送数据
}char DHT_Get_Data()
{uint8_t buffer=0;for(int i=0;i<8;i++){buffer<<=1;//一共八次,每次向左移1位while(!dhtin);//主机信号,等待低电平结束,无论是数据0还是1都是54us,不需要管,等待结束即可Delay_us(30);//30us后如果是高电平就是数字1,低电平就是数字0dhtin ? (buffer|=0x01) : (buffer&= ~0x01);//三目运算符,如果dhtin为1,则执行buffer|=0x01,否则buffer&= ~0x01while(dhtin);//30us后,因为高电平是68us-74us,高电平还有多的时间,需要等待高电平结束,如果是低电平,直接就跳过去了}return buffer;
}uint8_t DHT_Read(void)
{if(DHT_Start())//如果开始传输数据则,进入条件{datas[0]=DHT_Get_Data();datas[1]=DHT_Get_Data();datas[2]=DHT_Get_Data();datas[3]=DHT_Get_Data();datas[4]=DHT_Get_Data();Delay_us(60);//传感器释放总线时间 }if(datas[4]==(datas[0]+datas[1]+datas[2]+datas[3]))//校验和{return 1;}else{return 0;}}
DHT11.h
#ifndef __DHT11_H
#define __DHT11_H
#include "sys.h"
#define dhtout PAout(4)
#define dhtin PAin(4)extern char datas[5];
void DHT11_Init_In(void);
void DHT11_Init_Out(void);
uint8_t DHT_Read(void);#endif
sys.c
sys.h
#ifndef __SYS_H
#define __SYS_H
#include "stm32f10x.h"//位带操作,实现51类似的GPIO控制功能
//具体实现思想,参考<<CM3权威指南>>第五章(87页~92页).
//IO口操作宏定义
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
//IO口地址映射
#define GPIOA_ODR_Addr (GPIOA_BASE+12) //0x4001080C
#define GPIOB_ODR_Addr (GPIOB_BASE+12) //0x40010C0C
#define GPIOC_ODR_Addr (GPIOC_BASE+12) //0x4001100C
#define GPIOD_ODR_Addr (GPIOD_BASE+12) //0x4001140C
#define GPIOE_ODR_Addr (GPIOE_BASE+12) //0x4001180C
#define GPIOF_ODR_Addr (GPIOF_BASE+12) //0x40011A0C
#define GPIOG_ODR_Addr (GPIOG_BASE+12) //0x40011E0C #define GPIOA_IDR_Addr (GPIOA_BASE+8) //0x40010808
#define GPIOB_IDR_Addr (GPIOB_BASE+8) //0x40010C08
#define GPIOC_IDR_Addr (GPIOC_BASE+8) //0x40011008
#define GPIOD_IDR_Addr (GPIOD_BASE+8) //0x40011408
#define GPIOE_IDR_Addr (GPIOE_BASE+8) //0x40011808
#define GPIOF_IDR_Addr (GPIOF_BASE+8) //0x40011A08
#define GPIOG_IDR_Addr (GPIOG_BASE+8) //0x40011E08 //IO口操作,只对单一的IO口!
//确保n的值小于16!
#define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //输出
#define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //输入 #define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //输出
#define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //输入 #define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //输出
#define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //输入 #define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //输出
#define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //输入 #define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //输出
#define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //输入#define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //输出
#define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //输入#define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //输出
#define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //输入#endif
OLED.c
#include "stm32f10x.h"
#include "Dht11.h"/*-------------------------此处添加所要加入的中文字库--------------------------*/
unsigned char F16_16[]=
{
//字模提取app—参数设置:其他选项,纵向取模,字节倒序,保留,任何时候都加0
//文字输入区输入字,任何ctrl+回车生成
//修改图像:黑白反显图像
/*-- 文字: 选 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xBF,0xBF,0xBD,0x33,0xFF,0xAF,0xB1,0x37,0xB7,0x80,0x37,0xB7,0xB7,0xBF,0xFF,0xFF,//0
0xFF,0xBF,0xDF,0xE0,0xDF,0xAF,0xB3,0xBC,0xBF,0xBF,0xB0,0xAF,0xAF,0xA3,0xBF,0xFF,/*-- 文字: 择 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xEF,0xEF,0x00,0xEF,0xFF,0x7D,0x79,0xB5,0xAD,0x5D,0xAD,0xB5,0x79,0x7F,0x7F,0xFF,//1
0xBD,0x7D,0x80,0xFE,0xFF,0xEF,0xED,0xED,0xED,0x00,0xED,0xED,0xED,0xEF,0xFF,0xFF,/*-- 文字: 灯 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x7F,0x8F,0xFF,0x00,0xDF,0xEF,0xFB,0xFB,0xFB,0xFB,0x03,0xFB,0xFB,0xFB,0xFB,0xFF,//2
0x7F,0x9F,0xE7,0xF8,0xF7,0xCF,0xFF,0xFF,0xBF,0x7F,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,/*-- 文字: 颜 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xFF,0x1B,0xD3,0xCA,0x59,0x8B,0xD3,0xDB,0xFD,0x0D,0xE5,0x29,0xED,0x0D,0xFD,0xFF,//3
0xBF,0xC0,0x7F,0x76,0xBB,0xDD,0xEE,0xF7,0x7F,0xB0,0xCF,0xF0,0xEF,0xD0,0x3F,0xFF,/*-- 文字: 色 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xDF,0xEF,0x17,0xDB,0xD8,0xDB,0xDB,0x1B,0xDB,0xCB,0xD3,0xDF,0x1F,0xFF,0xFF,0xFF,//4
0xFF,0xFF,0xC0,0xBD,0xBD,0xBD,0xBD,0xBC,0xBD,0xBD,0xBD,0xBD,0xBC,0xBF,0x87,0xFF,/*-- 文字: 查 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xBF,0xBB,0xDB,0x5B,0x6B,0x73,0x7B,0x00,0x7B,0x73,0x6B,0x5B,0xDB,0xBB,0xBF,0xFF,//5
0xBF,0xBF,0xBF,0xA0,0xB5,0xB5,0xB5,0xB5,0xB5,0xB5,0xB5,0xA0,0xBF,0xBF,0xBF,0xFF,/*-- 文字: 看 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xDF,0xDD,0xD5,0xD5,0x55,0x95,0xC5,0xD1,0xD6,0xD6,0xD6,0xD6,0xD6,0xDF,0xDF,0xFF,//6
0xF7,0xFB,0xFD,0xFE,0x00,0xAA,0xAA,0xAA,0xAA,0xAA,0xAA,0x00,0xFF,0xFF,0xFF,0xFF,/*-- 文字: 温 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xEF,0x9F,0xFD,0x73,0xFF,0xFF,0x01,0x6D,0x6D,0x6D,0x6D,0x6D,0x01,0xFF,0xFF,0xFF,//7
0xFB,0xFB,0x81,0xFE,0xBF,0x81,0xBD,0xBD,0x81,0xBD,0x81,0xBD,0xBD,0x81,0xBF,0xFF,/*-- 文字: 度 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xFF,0xFF,0x03,0xDB,0xDB,0xDB,0x03,0xDA,0xD9,0xDB,0x03,0xDB,0xDB,0xDB,0xFB,0xFF,//8
0xBF,0xCF,0x70,0x7F,0x7B,0xB3,0xAA,0xDA,0xDA,0xDA,0xAA,0xB3,0x7F,0x7F,0x7F,0xFF,/*-- 文字: 风 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xFF,0xFF,0x01,0xFD,0xED,0xDD,0x3D,0xFD,0x3D,0xCD,0xFD,0x01,0xFF,0xFF,0xFF,0xFF,//9
0x7F,0x9F,0xE0,0xFF,0xDF,0xEF,0xF3,0xFC,0xF3,0xCF,0xFF,0xF0,0xCF,0xBF,0x07,0xFF,/*-- 文字: 扇 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xFF,0xFF,0x03,0xDB,0xDB,0xDB,0xDA,0xD9,0xDB,0xDB,0xDB,0xDB,0xDB,0xC3,0xFF,0xFF,//10
0xBF,0xCF,0xF0,0xDE,0xEA,0xB6,0x7E,0x80,0xFF,0xDE,0xEA,0xB6,0x7E,0x80,0xFF,0xFF,/*-- 文字: 开 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x7F,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7F,0xFF,//11
0xFF,0x7F,0xBF,0xCF,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,/*-- 文字: 关 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xFF,0xFF,0xEF,0xEE,0xE9,0xEF,0xEF,0x0F,0xEF,0xEF,0xEB,0xEC,0xEF,0xFF,0xFF,0xFF,//12
0x7E,0x7E,0xBE,0xBE,0xDE,0xEE,0xF2,0xFC,0xF2,0xEE,0xDE,0xBE,0xBE,0x7E,0x7E,0xFF,/*-- 文字: 选 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xBF,0xBF,0xBD,0x33,0xFF,0xAF,0xB1,0x37,0xB7,0x80,0x37,0xB7,0xB7,0xBF,0xFF,0xFF,//13
0xFF,0xBF,0xDF,0xE0,0xDF,0xAF,0xB3,0xBC,0xBF,0xBF,0xB0,0xAF,0xAF,0xA3,0xBF,0xFF,/*-- 文字: 择 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xEF,0xEF,0x00,0xEF,0xFF,0x7D,0x79,0xB5,0xAD,0x5D,0xAD,0xB5,0x79,0x7F,0x7F,0xFF,//14
0xBD,0x7D,0x80,0xFE,0xFF,0xEF,0xED,0xED,0xED,0x00,0xED,0xED,0xED,0xEF,0xFF,0xFF,/*-- 文字: 红 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xDF,0xCF,0x53,0x9C,0xDF,0xE7,0xFF,0xFB,0xFB,0xFB,0x03,0xFB,0xFB,0xFB,0xFF,0xFF,//15
0xDD,0x98,0xDD,0xED,0xED,0xED,0xBF,0xBF,0xBF,0xBF,0x80,0xBF,0xBF,0xBF,0xBF,0xFF,/*-- 文字: 灯 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x7F,0x8F,0xFF,0x00,0xDF,0xEF,0xFB,0xFB,0xFB,0xFB,0x03,0xFB,0xFB,0xFB,0xFB,0xFF,//16
0x7F,0x9F,0xE7,0xF8,0xF7,0xCF,0xFF,0xFF,0xBF,0x7F,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,/*-- 文字: 关 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xFF,0xFF,0xEF,0xEE,0xE9,0xEF,0xEF,0x0F,0xEF,0xEF,0xEB,0xEC,0xEF,0xFF,0xFF,0xFF,//17
0x7E,0x7E,0xBE,0xBE,0xDE,0xEE,0xF2,0xFC,0xF2,0xEE,0xDE,0xBE,0xBE,0x7E,0x7E,0xFF,/*-- 文字: 开 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x7F,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7D,0x7D,0x01,0x7D,0x7D,0x7D,0x7F,0xFF,//18
0xFF,0x7F,0xBF,0xCF,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,/*-- 文字: 绿 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xDF,0xCF,0x53,0x9C,0xCF,0xFF,0x7F,0x6D,0x6D,0x6D,0x6D,0x6D,0x01,0x7F,0x7F,0xFF,//19
0xDD,0x98,0xDD,0xED,0xED,0xFF,0xDD,0xEB,0xB7,0x7B,0x80,0xFB,0xF7,0xEB,0xDD,0xFF,/*-- 文字: 灯 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x7F,0x8F,0xFF,0x00,0xDF,0xEF,0xFB,0xFB,0xFB,0xFB,0x03,0xFB,0xFB,0xFB,0xFB,0xFF,//20
0x7F,0x9F,0xE7,0xF8,0xF7,0xCF,0xFF,0xFF,0xBF,0x7F,0x80,0xFF,0xFF,0xFF,0xFF,0xFF,//字模提取app—参数设置:其他选项,纵向取模,字节倒序,保留,任何时候都加0
//文字输入区输入字,任何ctrl+回车生成
/*-- 文字: 选 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x40,0x40,0x42,0xCC,0x00,0x50,0x4E,0xC8,0x48,0x7F,0xC8,0x48,0x48,0x40,0x00,0x00,//21
0x00,0x40,0x20,0x1F,0x20,0x50,0x4C,0x43,0x40,0x40,0x4F,0x50,0x50,0x5C,0x40,0x00,/*-- 文字: 择 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x10,0xFF,0x10,0x00,0x82,0x86,0x4A,0x52,0xA2,0x52,0x4A,0x86,0x80,0x80,0x00,//22
0x42,0x82,0x7F,0x01,0x00,0x10,0x12,0x12,0x12,0xFF,0x12,0x12,0x12,0x10,0x00,0x00,/*-- 文字: 灯 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x80,0x70,0x00,0xFF,0x20,0x10,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x00,//23
0x80,0x60,0x18,0x07,0x08,0x30,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,/*-- 文字: 颜 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0xE4,0x2C,0x35,0xA6,0x74,0x2C,0x24,0x02,0xF2,0x1A,0xD6,0x12,0xF2,0x02,0x00,//24
0x40,0x3F,0x80,0x89,0x44,0x22,0x11,0x08,0x80,0x4F,0x30,0x0F,0x10,0x2F,0xC0,0x00,/*-- 文字: 色 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x10,0xE8,0x24,0x27,0x24,0x24,0xE4,0x24,0x34,0x2C,0x20,0xE0,0x00,0x00,0x00,//25
0x00,0x00,0x3F,0x42,0x42,0x42,0x42,0x43,0x42,0x42,0x42,0x42,0x43,0x40,0x78,0x00,/*-- 文字: 查 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x40,0x44,0x24,0xA4,0x94,0x8C,0x84,0xFF,0x84,0x8C,0x94,0xA4,0x24,0x44,0x40,0x00,//26
0x40,0x40,0x40,0x5F,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x4A,0x5F,0x40,0x40,0x40,0x00,/*-- 文字: 看 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x22,0x2A,0x2A,0xAA,0x6A,0x3A,0x2E,0x29,0x29,0x29,0x29,0x29,0x20,0x20,0x00,//27
0x08,0x04,0x02,0x01,0xFF,0x55,0x55,0x55,0x55,0x55,0x55,0xFF,0x00,0x00,0x00,0x00,/*-- 文字: 温 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,//28
0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00,/*-- 文字: 度 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,//29
0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,/*-- 文字: 风 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0xFE,0x02,0x12,0x22,0xC2,0x02,0xC2,0x32,0x02,0xFE,0x00,0x00,0x00,0x00,//30
0x80,0x60,0x1F,0x00,0x20,0x10,0x0C,0x03,0x0C,0x30,0x00,0x0F,0x30,0x40,0xF8,0x00,/*-- 文字: 扇 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0xFC,0x24,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x24,0x24,0x3C,0x00,0x00,//31
0x40,0x30,0x0F,0x21,0x15,0x49,0x81,0x7F,0x00,0x21,0x15,0x49,0x81,0x7F,0x00,0x00,/*-- 文字: 开 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x80,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x80,0x00,//32
0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,/*-- 文字: 关 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x10,0x11,0x16,0x10,0x10,0xF0,0x10,0x10,0x14,0x13,0x10,0x00,0x00,0x00,//33
0x81,0x81,0x41,0x41,0x21,0x11,0x0D,0x03,0x0D,0x11,0x21,0x41,0x41,0x81,0x81,0x00,/*-- 文字: 选 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x40,0x40,0x42,0xCC,0x00,0x50,0x4E,0xC8,0x48,0x7F,0xC8,0x48,0x48,0x40,0x00,0x00,//34
0x00,0x40,0x20,0x1F,0x20,0x50,0x4C,0x43,0x40,0x40,0x4F,0x50,0x50,0x5C,0x40,0x00,/*-- 文字: 择 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x10,0xFF,0x10,0x00,0x82,0x86,0x4A,0x52,0xA2,0x52,0x4A,0x86,0x80,0x80,0x00,//35
0x42,0x82,0x7F,0x01,0x00,0x10,0x12,0x12,0x12,0xFF,0x12,0x12,0x12,0x10,0x00,0x00,/*-- 文字: 红 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x30,0xAC,0x63,0x20,0x18,0x00,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x00,0x00,//36
0x22,0x67,0x22,0x12,0x12,0x12,0x40,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x00,/*-- 文字: 灯 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x80,0x70,0x00,0xFF,0x20,0x10,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x00,//37
0x80,0x60,0x18,0x07,0x08,0x30,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,/*-- 文字: 关 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0x10,0x11,0x16,0x10,0x10,0xF0,0x10,0x10,0x14,0x13,0x10,0x00,0x00,0x00,//38
0x81,0x81,0x41,0x41,0x21,0x11,0x0D,0x03,0x0D,0x11,0x21,0x41,0x41,0x81,0x81,0x00,/*-- 文字: 开 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x80,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x80,0x00,//39
0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,/*-- 文字: 绿 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x20,0x30,0xAC,0x63,0x30,0x00,0x80,0x92,0x92,0x92,0x92,0x92,0xFE,0x80,0x80,0x00,//40
0x22,0x67,0x22,0x12,0x12,0x00,0x22,0x14,0x48,0x84,0x7F,0x04,0x08,0x14,0x22,0x00,/*-- 文字: 灯 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x80,0x70,0x00,0xFF,0x20,0x10,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x00,//41
0x80,0x60,0x18,0x07,0x08,0x30,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,//字模提取app—参数设置:其他选项,纵向取模,字节倒序,保留,任何时候都加0
//文字输入区输入字,任何ctrl+回车生成
//修改图像:黑白反显图像
/*-- 文字: 风 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xFF,0xFF,0x01,0xFD,0xED,0xDD,0x3D,0xFD,0x3D,0xCD,0xFD,0x01,0xFF,0xFF,0xFF,0xFF,//42
0x7F,0x9F,0xE0,0xFF,0xDF,0xEF,0xF3,0xFC,0xF3,0xCF,0xFF,0xF0,0xCF,0xBF,0x07,0xFF,/*-- 文字: 扇 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xFF,0xFF,0x03,0xDB,0xDB,0xDB,0xDA,0xD9,0xDB,0xDB,0xDB,0xDB,0xDB,0xC3,0xFF,0xFF,//43
0xBF,0xCF,0xF0,0xDE,0xEA,0xB6,0x7E,0x80,0xFF,0xDE,0xEA,0xB6,0x7E,0x80,0xFF,0xFF,/*-- 文字: 转 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x37,0x47,0x70,0x17,0x77,0x77,0xBF,0xB7,0xB7,0x17,0xA0,0xB7,0xB7,0xB7,0xBF,0xFF,//44
0xF7,0xE7,0xF7,0x00,0xFB,0xFB,0xFF,0xFD,0xF4,0xED,0xDD,0x2D,0xF5,0xF9,0xFF,0xFF,/*-- 文字: 速 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xBF,0xBF,0xBD,0x33,0xFF,0xFB,0x0B,0x6B,0x6B,0x00,0x6B,0x6B,0x0B,0xFB,0xFF,0xFF,//45
0xFF,0xBF,0xDF,0xE0,0xDF,0xB7,0xBB,0xBD,0xBE,0xA0,0xBE,0xBD,0xBB,0xB7,0xBF,0xFF,//字模提取app—参数设置:其他选项,纵向取模,字节倒序,保留,任何时候都加0
//文字输入区输入字,任何ctrl+回车生成
/*-- 文字: 风 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0xFE,0x02,0x12,0x22,0xC2,0x02,0xC2,0x32,0x02,0xFE,0x00,0x00,0x00,0x00,//46
0x80,0x60,0x1F,0x00,0x20,0x10,0x0C,0x03,0x0C,0x30,0x00,0x0F,0x30,0x40,0xF8,0x00,/*-- 文字: 扇 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0xFC,0x24,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x24,0x24,0x3C,0x00,0x00,//47
0x40,0x30,0x0F,0x21,0x15,0x49,0x81,0x7F,0x00,0x21,0x15,0x49,0x81,0x7F,0x00,0x00,/*-- 文字: 转 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0xC8,0xB8,0x8F,0xE8,0x88,0x88,0x40,0x48,0x48,0xE8,0x5F,0x48,0x48,0x48,0x40,0x00,//48
0x08,0x18,0x08,0xFF,0x04,0x04,0x00,0x02,0x0B,0x12,0x22,0xD2,0x0A,0x06,0x00,0x00,/*-- 文字: 速 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x40,0x40,0x42,0xCC,0x00,0x04,0xF4,0x94,0x94,0xFF,0x94,0x94,0xF4,0x04,0x00,0x00,//49
0x00,0x40,0x20,0x1F,0x20,0x48,0x44,0x42,0x41,0x5F,0x41,0x42,0x44,0x48,0x40,0x00,/*-- 文字: 湿 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x60,0x02,0x8C,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,//50
0x04,0x04,0x7E,0x01,0x44,0x48,0x50,0x7F,0x40,0x40,0x7F,0x50,0x48,0x44,0x40,0x00,/*-- 文字: 度 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,//51
0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,/*-- 文字: 温 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,//52
0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00,/*-- 文字: 度 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=16x16 --*/
0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,//53
0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,};
/*-------------------------此处添加所要加入的英文符号数字字库--------------------------*/
unsigned char F8_16[]=
{
//字模提取app—参数设置:其他选项,纵向取模,字节倒序,保留,任何时候都加0
//文字输入区输入字,任何ctrl+回车生成
0x00,0x00,0xF0,0xF8,0x08,0x68,0xF8,0xF0,0x00,0x00,0x07,0x0F,0x0B,0x08,0x0F,0x07,//数字0,00x00,0x20,0x20,0x30,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,//数字1,10x00,0x30,0x38,0x08,0x88,0xF8,0x70,0x00,0x00,0x0C,0x0E,0x0B,0x09,0x08,0x08,0x00,0x00,0x30,0x38,0x88,0x88,0xF8,0x70,0x00,0x00,0x06,0x0E,0x08,0x08,0x0F,0x07,0x00,0x00,0x00,0xF8,0xF8,0x00,0xE0,0xE0,0x00,0x00,0x03,0x03,0x02,0x02,0x0F,0x0F,0x02,0x00,0xF8,0xF8,0x88,0x88,0x88,0x08,0x00,0x00,0x08,0x08,0x08,0x0C,0x07,0x03,0x00,0x00,0xC0,0xE0,0x78,0x58,0xC8,0x80,0x00,0x00,0x07,0x0F,0x08,0x08,0x0F,0x07,0x00,0x00,0x08,0x08,0x88,0xE8,0x78,0x18,0x00,0x00,0x00,0x0E,0x0F,0x01,0x00,0x00,0x00,0x00,0x70,0xF8,0xC8,0x88,0xF8,0x70,0x00,0x00,0x07,0x0F,0x08,0x09,0x0F,0x07,0x00,0x00,0xF0,0xF8,0x08,0x08,0xF8,0xF0,0x00,0x00,0x00,0x09,0x0D,0x0F,0x03,0x01,0x00,//数字9,9/*-- 文字: * --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x80,0xA0,0xE0,0xC0,0xE0,0xA0,0x80,0x00,0x00,0x02,0x03,0x01,0x03,0x02,0x00,//10/*-- 文字: : --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x60,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x0C,0x00,0x00,//11/*-- 调入了一幅图像:这是您新建的图像,全黑 --*/
/*-- 宽度x高度=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//12/*-- 文字: . --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=8x16 --*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x0C,0x00,0x00,//13};/*-------------------------此处添加所要加入的英文符号数字字库,颜色反转--------------------------*/
unsigned char F8_16A[]=
{
//字模提取app—参数设置:其他选项,纵向取模,字节倒序,保留,任何时候都加0
//文字输入区输入字,任何ctrl+回车生成
//修改图像:黑白反显图像
/*-- 文字: 0 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xFF,0x0F,0x07,0xF7,0x97,0x07,0x0F,0xFF,0xFF,0xF8,0xF0,0xF4,0xF7,0xF0,0xF8,/*-- 文字: 1 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xDF,0xDF,0xCF,0x07,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0xF0,0xFF,0xFF,/*-- 文字: 2 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xCF,0xC7,0xF7,0x77,0x07,0x8F,0xFF,0xFF,0xF3,0xF1,0xF4,0xF6,0xF7,0xF7,0xFF,/*-- 文字: 3 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xCF,0xC7,0x77,0x77,0x07,0x8F,0xFF,0xFF,0xF9,0xF1,0xF7,0xF7,0xF0,0xF8,0xFF,/*-- 文字: 4 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xFF,0x07,0x07,0xFF,0x1F,0x1F,0xFF,0xFF,0xFC,0xFC,0xFD,0xFD,0xF0,0xF0,0xFD,/*-- 文字: 5 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0x07,0x07,0x77,0x77,0x77,0xF7,0xFF,0xFF,0xF7,0xF7,0xF7,0xF3,0xF8,0xFC,0xFF,/*-- 文字: 6 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0x3F,0x1F,0x87,0xA7,0x37,0x7F,0xFF,0xFF,0xF8,0xF0,0xF7,0xF7,0xF0,0xF8,0xFF,/*-- 文字: 7 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xF7,0xF7,0x77,0x17,0x87,0xE7,0xFF,0xFF,0xFF,0xF1,0xF0,0xFE,0xFF,0xFF,0xFF,/*-- 文字: 8 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0x8F,0x07,0x37,0x77,0x07,0x8F,0xFF,0xFF,0xF8,0xF0,0xF7,0xF6,0xF0,0xF8,0xFF,/*-- 文字: 9 --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0x0F,0x07,0xF7,0xF7,0x07,0x0F,0xFF,0xFF,0xFF,0xF6,0xF2,0xF0,0xFC,0xFE,0xFF,/*-- 文字: : --*/
/*-- Fixedsys12; 此字体下对应的点阵为:宽x高=8x16 --*/
0xFF,0xFF,0xFF,0x9F,0x9F,0x9F,0xFF,0xFF,0xFF,0xFF,0xFF,0xF3,0xF3,0xF3,0xFF,0xFF,//10};/*引脚配置*/
#define OLED_W_SCL(x) GPIO_WriteBit(GPIOB, GPIO_Pin_8, (BitAction)(x))
#define OLED_W_SDA(x) GPIO_WriteBit(GPIOB, GPIO_Pin_9, (BitAction)(x))/*引脚初始化*/
void OLED_I2C_Init(void)
{RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;GPIO_Init(GPIOB, &GPIO_InitStructure);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;GPIO_Init(GPIOB, &GPIO_InitStructure);OLED_W_SCL(1);OLED_W_SDA(1);
}/*** @brief I2C开始* @param 无* @retval 无*/
void OLED_I2C_Start(void)
{OLED_W_SDA(1);OLED_W_SCL(1);OLED_W_SDA(0);OLED_W_SCL(0);
}/*** @brief I2C停止* @param 无* @retval 无*/
void OLED_I2C_Stop(void)
{OLED_W_SDA(0);OLED_W_SCL(1);OLED_W_SDA(1);
}/*** @brief I2C发送一个字节* @param Byte 要发送的一个字节* @retval 无*/
void OLED_I2C_SendByte(uint8_t Byte)
{uint8_t i;for (i = 0; i < 8; i++){OLED_W_SDA(Byte & (0x80 >> i));OLED_W_SCL(1);OLED_W_SCL(0);}OLED_W_SCL(1); //额外的一个时钟,不处理应答信号OLED_W_SCL(0);
}/*** @brief OLED写命令* @param Command 要写入的命令* @retval 无*/
void OLED_WriteCommand(uint8_t Command)
{OLED_I2C_Start();OLED_I2C_SendByte(0x78); //从机地址OLED_I2C_SendByte(0x00); //写命令OLED_I2C_SendByte(Command); OLED_I2C_Stop();
}/*** @brief OLED写数据* @param Data 要写入的数据* @retval 无*/
void OLED_WriteData(uint8_t Data)
{OLED_I2C_Start();OLED_I2C_SendByte(0x78); //从机地址OLED_I2C_SendByte(0x40); //写数据OLED_I2C_SendByte(Data);OLED_I2C_Stop();
}//坐标函数
void Oled_setpos(unsigned char x,unsigned char y)//OLED设置坐标(列,行)
{OLED_WriteCommand(0xB0 + y);//"页地址"从0xB0开始(一共8页)OLED_WriteCommand(((x & 0xF0) >> 4) | 0x10);//高四位OLED_WriteCommand((x & 0x0f) );//低四位
}/*** @brief OLED清屏* @param 无* @retval 无*/
void Oled_clear()// 清屏函数
{int i,j;for(i=0;i<8;i++)//PAGE0-PAGE7都给0{OLED_WriteCommand(0xB0+i);//PAGE0-PAGE7OLED_WriteCommand(0x00);OLED_WriteCommand(0x10);for(j=0;j<128;j++){OLED_WriteData(0);}}
}/*** @brief OLED初始化* @param 无* @retval 无*/
void OLED_Init(void)
{uint32_t i, j;for (i = 0; i < 1000; i++) //上电延时{for (j = 0; j < 1000; j++);}OLED_I2C_Init(); //端口初始化OLED_WriteCommand(0xAE); //关闭显示OLED_WriteCommand(0xD5); //设置显示时钟分频比/振荡器频率OLED_WriteCommand(0x80);OLED_WriteCommand(0xA8); //设置多路复用率OLED_WriteCommand(0x3F);OLED_WriteCommand(0xD3); //设置显示偏移OLED_WriteCommand(0x00);OLED_WriteCommand(0x40); //设置显示开始行OLED_WriteCommand(0xA1); //设置左右方向,0xA1正常 0xA0左右反置OLED_WriteCommand(0xC8); //设置上下方向,0xC8正常 0xC0上下反置OLED_WriteCommand(0xDA); //设置COM引脚硬件配置OLED_WriteCommand(0x12);OLED_WriteCommand(0x81); //设置对比度控制OLED_WriteCommand(0xCF);OLED_WriteCommand(0xD9); //设置预充电周期OLED_WriteCommand(0xF1);OLED_WriteCommand(0xDB); //设置VCOMH取消选择级别OLED_WriteCommand(0x30);OLED_WriteCommand(0xA4); //设置整个显示打开/关闭OLED_WriteCommand(0xA6); //设置正常/倒转显示OLED_WriteCommand(0x8D); //设置充电泵OLED_WriteCommand(0x14);OLED_WriteCommand(0xAF); //开启显示Oled_clear(); //OLED清屏
}/*
功能:显示中文OLED一共可以显示8列中文,4行中文
每个中文每列隔开数值+8,从0开始
每个中文每行隔开数值+2,,从0开始例子1:第一行显示两个中文
//选
Oled_8_16_L(8,0,0);
Oled_8_16_R(16,0,0);
//择
Oled_8_16_L(24,0,1);
Oled_8_16_R(32,0,1);例子2:第二行显示两个中文
//选
Oled_8_16_L(8,2,0);
Oled_8_16_R(16,2,0);
//择
Oled_8_16_L(24,2,1);
Oled_8_16_R(32,2,1);*/void Oled_8_16_L(unsigned char x,unsigned char y,unsigned char N)//需要16*16点阵的左边
{unsigned char i;unsigned int adder=32*N; //16*16=256位,8位为一个字节,所以256/8=32个字节,一个汉字就是32字节,所以这里adder=32*N的意思就是N代表第几个汉字,比如第0个就是小,然后一开始就是数组从0开始Oled_setpos(x,y); //(列,行) for(i=0;i<8;i++) //汉字的左上部分{OLED_WriteData(F16_16[adder]); //当第一个汉字的时候,32*0=0,所以F16*16[adder]的adder从0开始,然后从0开始到7就是左上半部分adder++;}Oled_setpos(x,y+1); //(列,行+1) for(i=0;i<8;i++) //汉字的左下部分{OLED_WriteData(F16_16[adder+8]);//之后adder的8-15是右上部分,所以想取左下部分就+8adder++;}
}void Oled_8_16_R(unsigned char x,unsigned char y,unsigned char N)//需要16*16点阵的右边
{unsigned char i;unsigned int adder=32*N+8; //16*16=256位,8位为一个字节,所以256/8=32个字节,一个汉字就是32字节,所以这里adder=32*N的意思就是N代表第几个汉字,比如第0个就是小,然后一开始就是数组从8开始Oled_setpos(x,y); //(列,行) for(i=0;i<8;i++) //汉字的右上部分{OLED_WriteData(F16_16[adder]); //当第一个汉字的时候,32*0=0,所以F16*16[adder]的adder从8开始,然后从8开始到15就是右上半部分adder++;}Oled_setpos(x,y+1); //(列,行+1) for(i=0;i<8;i++) //汉字的右下部分{OLED_WriteData(F16_16[adder+8]);//之后adder的16-23是左下部分,所以想取右下部分就+8adder++;}
}/*
功能:显示数字,英文,字符OLED一共可以显示16列数字英文字符,4行数字英文字符
每个数字英文字符每列隔开数值+8,从0开始
每个数字英文字符每行隔开数值+2,,从0开始例子1:第一行显示一个字符Oled_8_16(0,0,11);例子2:第二行显示一个字符Oled_8_16(0,2,11);*/
void Oled_8_16(unsigned char x,unsigned char y,unsigned char N)
{unsigned char i;unsigned int adder=16*N;Oled_setpos(x,y); //(列,行) for(i=0;i<8;i++) {OLED_WriteData(F8_16[adder]); adder++;}Oled_setpos(x,y+1);for(i=0;i<8;i++) {OLED_WriteData(F8_16[adder]); adder++;}
}/*
功能://显示数字,英文,字符,颜色反转OLED一共可以显示16列数字英文字符,4行数字英文字符
每个数字英文字符每列隔开数值+8,从0开始
每个数字英文字符每行隔开数值+2,,从0开始例子1:第一行显示一个字符Oled_8_16A(0,0,11);例子2:第二行显示一个字符Oled_8_16A(0,2,11);*/
void Oled_8_16A(unsigned char x,unsigned char y,unsigned char N)
{unsigned char i;unsigned int adder=16*N;Oled_setpos(x,y); //(列,行) for(i=0;i<8;i++) {OLED_WriteData(F8_16A[adder]); adder++;}Oled_setpos(x,y+1);for(i=0;i<8;i++) {OLED_WriteData(F8_16A[adder]); adder++;}
}
OLED.h
#ifndef __OLED_H
#define __OLED_H
#include "stm32f10x.h" // Device headervoid OLED_Init(void);
void Oled_clear(void);// 清屏函数
void Oled_8_16_L(unsigned char x,unsigned char y,unsigned char N);//需要16*16点阵的左边
void Oled_8_16_R(unsigned char x,unsigned char y,unsigned char N);//需要16*16点阵的右边,显示中文
void Oled_8_16(unsigned char x,unsigned char y,unsigned char N);//显示数字
void Oled_8_16A(unsigned char x,unsigned char y,unsigned char N);//显示数字,颜色反转#endif
Delay.c
#include "stm32f10x.h"/*** @brief 微秒级延时* @param xus 延时时长,范围:0~233015* @retval 无*/
void Delay_us(uint32_t xus)
{SysTick->LOAD = 72 * xus; //设置定时器重装值SysTick->VAL = 0x00; //清空当前计数值SysTick->CTRL = 0x00000005; //设置时钟源为HCLK,启动定时器while(!(SysTick->CTRL & 0x00010000)); //等待计数到0SysTick->CTRL = 0x00000004; //关闭定时器
}/*** @brief 毫秒级延时* @param xms 延时时长,范围:0~4294967295* @retval 无*/
void Delay_ms(uint32_t xms)
{while(xms--){Delay_us(1000);}
}/*** @brief 秒级延时* @param xs 延时时长,范围:0~4294967295* @retval 无*/
void Delay_s(uint32_t xs)
{while(xs--){Delay_ms(1000);}
}
Delay.h
#ifndef __DELAY_H
#define __DELAY_H
#include "stm32f10x.h" // Device headervoid Delay_us(uint32_t us);
void Delay_ms(uint32_t ms);
void Delay_s(uint32_t s);#endif