文章目录
- 一.补充
- 二. 二级菜单代码
简介:首先在我的51 I2C里面有OLED详细讲解,本期代码从51OLED基础上移植过来的,可以先看完那篇文章,在看这个,然后按键我是用的定时器扫描不会堵塞程序,可以翻开我的文章有单独的定时器按键扫描,DHT11文章也有,我的菜单从一级界面点进去二级界面,二级界面开启的内容,退出到一级界面后,会保留二级界面开启的功能并且再一次从一级界面进入二级界面后,页面保留之前开启部分的页面,然后功能之间互不影响,标志位有点多,看完肯定对标志位运用更加熟悉,看完以后开发三级四级也是很简单,思路不堵塞。
一.补充
这里补充OLED颜色反转,怎么取模
二. 二级菜单代码
main.c
#include "stm32f10x.h" // Device header
#include "OLED.h"
#include "Key.h"
#include "LED.h"
#include "Motor.h"
#include "Timer.h"
#include "Delay.h"
#include "Dht11.h"
#include "OLEDShow.h"
int32_t Beep_time=0;//蜂鸣器定时器标志位
uint8_t flag =1;//显示哪页OLED标志位,一级OLED按键可以向上向下移动
uint8_t uuflag=0;//多级菜单标志位,决定几级菜单
int8_t Speed;//电机速度值
uint8_t fsflag=0;//风扇打开或者关闭标志位
uint8_t fsclose=0;//风扇打开或者关闭决定转速标志位
uint8_t LEDGreenflag=0;//绿灯开关标志位
uint8_t LEDRedflag=0;//红灯开关标志位
uint8_t LLflag =0;//记录绿灯开关标志位
uint8_t PPflag =0;//记录红灯开关标志位
uint8_t tuichudata=0;//从一级点进去二级实现红绿灯功能再退出再进入,保留之前的OLED页面
uint8_t fstuichudata=0;//从一级点进去二级实现风扇功能再退出再进入,保留之前的OLED页面
uint8_t T_flag =0;//DHT11模块是否启用标志位
/*
主界面一级界面
按键零作用:向下选择
按键一作用:向上选择
按键二作用:确定
选择颜色灯二级界面
初始界面--> *红灯:关
绿灯:关
按键零作用:开关绿灯--->对红灯不影响
按键一作用:开关红灯--->对绿灯不影响
按键三作用:退出,保留灯的状态和使用的页面
温湿度二级界面
初始界面-->温湿度显示数据
按键三作用:退出
风扇开关选择二级界面
初始界面-->风扇:关,转速0
按键零作用:打开风扇或者关闭风扇
按键一作用:进行以20数值增加风扇转速,如果风扇处于关闭状态,则按键一按下还是0
按键二作用:进行以20数值减少风扇转速,如果风扇处于关闭状态,则按键一按下还是0
按键三作用:退出和使用的页面
*/
void Key_Show1(void)//一级界面
{
if(uuflag ==0)
{
switch(KeyFlag)//按键短按,按下即可开始实现功能,不用松手
{
case KEY0_PRES://1,按键0,向下
{
++flag;
if(flag == 1)
{
Oled_clear();
Oledshow1();//光标选中选择灯颜色
}
if(flag == 2)
{
Oled_clear();
Oledshow2();//光标选中查看温度
}
if(flag == 3)
{
Oled_clear();
Oledshow3();//光标选中风扇开关选择
}
if(flag ==4)
{
Oled_clear();
Oledshow1();//光标选中选择灯颜色
flag =1;
}
KeyFlag = 0;//注意按键标志清零,防止程序跑飞
}
break;
case KEY1_PRES://2,按键1,向上
{
--flag;
if(flag == 0)
{
Oled_clear();
Oledshow3();//光标选中风扇开关选择
flag =3;
}
if(flag == 1)
{
Oled_clear();
Oledshow1();//光标选中选择灯颜色
}
if(flag == 2)
{
Oled_clear();
Oledshow2();//光标选中查看温度
}
if(flag == 3)
{
Oled_clear();
Oledshow3();//光标选中风扇开关选择
}
if(flag ==4)
{
Oled_clear();
Oledshow1();//光标选中选择灯颜色
flag =1;
}
KeyFlag = 0;//注意按键标志清零,防止程序跑飞
}
break;
case KEY2_PRES: //3,按键2,确定
{
if(flag == 1)//颜色灯,二级界面从这里标志位确定更新新的界面,后续添加其他一级界面确定,flag=其他等等
{
if(tuichudata == 0)//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
{
Oled_clear();
Oledshow4();//红灯关和绿灯关
}
if(tuichudata == 1)
{
Oled_clear();
Oledshow6();
}
if(tuichudata == 2)
{
Oled_clear();
Oledshow8();
}
if(tuichudata == 3)
{
Oled_clear();
Oledshow15();
}
if(tuichudata == 4)
{
Oled_clear();
Oledshow17();
}
if(tuichudata == 5)
{
Oled_clear();
Oledshow5();
}
if(tuichudata == 6)
{
Oled_clear();
Oledshow14();
}
if(tuichudata == 7)
{
Oled_clear();
Oledshow16();
}
uuflag=1;//颜色灯标志位
}
if(flag == 2)//查看温度,二级界面从这里标志位确定更新新的界面,后续添加其他一级界面确定,flag=其他等等
{
Oled_clear();
Oledshow13();//温湿度模块显示数据
T_flag = 1; //温湿度标志位,让按键二确认之后置1,以便在主函数循环里面2s检测一次DHT11模块,因为按键按下松开后只能检测一次
uuflag=2;//温湿度标志位
}
if(flag == 3)//风扇开关选择,二级界面从这里标志位确定更新新的界面,后续添加其他一级界面确定,flag=其他等等
{
if(fstuichudata ==0)//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
{
Oled_clear();
Oledshow9();//风扇关和转速数值
fsclose =2;//风扇关着
}
if(fstuichudata ==1)
{
Oled_clear();
Oledshow10();//风扇开,初始转速100
fsclose =1;//风扇开着
}
if(fstuichudata ==3)
{
Oled_clear();
Oledshow11();//风扇开转速
Oled_8_16A(48,2,Speed/100%10);
Oled_8_16A(56,2,Speed/10%10);
Oled_8_16A(64,2,Speed/1%10);
fsclose =1;//风扇开着
}
if(fstuichudata ==4)
{
Oled_clear();
Oledshow12();//风扇关转速0
fsclose =2;//风扇关着
}
if(fstuichudata ==5)//
{
Oled_clear();
Oledshow11();//风扇开转速
Oled_8_16A(48,2,Speed/100%10);
Oled_8_16A(56,2,Speed/10%10);
Oled_8_16A(64,2,Speed/1%10);
fsclose =1;//风扇开着
}
if(fstuichudata ==6)
{
Oled_clear();
Oledshow12();//风扇关转速0
fsclose =2;//风扇开着
}
uuflag=3;//风扇开关标志位
}
KeyFlag = 0;//注意按键标志清零,防止程序跑飞
}
break;
}
}
}
void Key_show2(void)//二级界面
{
if(uuflag == 1)//选择灯颜色二级界面功能,后续可添加其他二级界面,用uuflag=其他判断
{
switch(KeyFlag)
{
case KEY0_PRES://1,按键0,开绿灯
{
if(LEDGreenflag==0 & PPflag==0)//绿灯开 | 红灯关
{
// 红灯:关
//*绿灯:开(颜色反转)
Oledshow6();
LED_Green=0;
++LEDGreenflag;
LLflag=1;//绿灯开
tuichudata = 1;//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
}
else if(LEDGreenflag==1 & PPflag==0)//绿灯关 | 红灯关
{
// 红灯:关
//*绿灯:关(颜色反转)
Oledshow8();
LED_Green =1;//绿灯关
LEDGreenflag =0;
LLflag=0;//绿灯关
tuichudata = 2;//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
}
if(LEDGreenflag==0 & PPflag==1)//绿灯开 | 红灯开
{
// 红灯:开
//*绿灯:开(颜色反转)
Oledshow15();
LED_Green=0;
LEDGreenflag=1;
LLflag=1;//绿灯开
tuichudata = 3;//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
}
else if(LEDGreenflag==1 & PPflag==1)//绿灯关 | 红灯开
{
// 红灯:开
//*绿灯:关(颜色反转)
Oledshow17();
LED_Green =1;
LEDGreenflag =0;
LLflag=0;//绿灯关
tuichudata = 4;//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
}
KeyFlag = 0;//注意按键标志清零,防止程序跑飞
}
break;
case KEY1_PRES://2,按键1//开红灯
{
if(LEDRedflag ==0 & LLflag==0)//红灯开 | 绿灯关
{
//*红灯:开(颜色反转)
// 绿灯:关
Oledshow5();
LED_Red = 0;
++LEDRedflag;
PPflag=1;//红灯开
tuichudata = 5;//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
}
else if(LEDRedflag ==1 & LLflag==0)//红灯关 | 绿灯关
{
//*红灯:关(颜色反转)
// 绿灯:关
Oledshow7();
LED_Red = 1;
LEDRedflag=0;
PPflag=0;//红灯关
tuichudata = 0;//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
}
if(LEDRedflag ==0 & LLflag==1)//红灯开 | 绿灯开
{
//*红灯:开(颜色反转)
// 绿灯:开
Oledshow14();
LED_Red = 0;
LEDRedflag=1;
PPflag=1;//红灯开
tuichudata = 6;//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
}
else if(LEDRedflag ==1 & LLflag==1)//红灯关 | 绿灯开
{
//*红灯:关(颜色反转)
// 绿灯:开
Oledshow16();
LED_Red = 1;
LEDRedflag=0;
PPflag=0;//红灯关
tuichudata = 7;//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
}
KeyFlag = 0;//注意按键标志清零,防止程序跑飞
}
break;
case KEY3_PRES://4,按键三,退出
{
Oled_clear();
Oledshow1();//一级界面
flag = 1;
uuflag =0;
KeyFlag = 0;//注意按键标志清零,防止程序跑飞
}
break;
}
}
if(uuflag == 2)//查看温度二级界面功能,后续可添加其他二级界面,用uuflag=其他判断
{
switch(KeyFlag)
{
case KEY3_PRES://4,按键三,退出
{
Oled_clear();
Oledshow18();//一级界面
flag = 1;
uuflag =0;
T_flag = 0;//温湿度模块退出检测
KeyFlag = 0;//注意按键标志清零,防止程序跑飞
}
break;
}
}
if(uuflag == 3)//风扇开关选择二级界面功能,后续可添加其他二级界面,用uuflag=其他判断
{
switch(KeyFlag)
{
case KEY0_PRES://1,按键0,风扇:开 转速:100
{
if(fsflag ==0)
{
Oled_clear();
Oledshow10();//风扇开,初始转速100
Motor_SetSpeed(100);
++fsflag;
fsclose =1;//风扇开着
fstuichudata = 1 ;//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
}
else if(fsflag ==1)//这里不能用if否则上面的fsflag会立马进入这个条件
{
Oled_clear();
Oledshow9();//风扇关,初始转速0
Motor_SetSpeed(0);
fsflag =0;
fsclose =2;//风扇关着
fstuichudata =0 ;//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
}
KeyFlag = 0;//注意按键标志清零,防止程序跑飞
}
break;
case KEY1_PRES://2,按键1,风扇:开 转速增加,每次增加20
{
if(fsclose ==1)//如果第一行的风扇开着,这里就可以不断调节转速
{
Oled_clear();
Oledshow11();//风扇开转速
fsflag =1;//让点按键一的时候增加风扇转速,如果点按键零可以直接关掉风扇
Speed +=20;
if(Speed > 100)
{
Speed = 20;
}
Motor_SetSpeed(Speed);
Oled_8_16A(48,2,Speed/100%10);
Oled_8_16A(56,2,Speed/10%10);
Oled_8_16A(64,2,Speed/1%10);
fstuichudata =3;//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
}
else if(fsclose ==2)//如果第一行的风扇关着,这里就调节转速则无反应
{
Oled_clear();
Oledshow12();//风扇关转速0
Motor_SetSpeed(0);
fstuichudata = 4;//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
}
KeyFlag = 0;//注意按键标志清零,防止程序跑飞
}
break;
case KEY2_PRES://3,按键2风扇:开 转速减少,每次减少20
{
if(fsclose ==1)//如果第一行的风扇开着,这里就可以不断调节转速
{
Oled_clear();
Oledshow11();//风扇开转速
fsflag =1;//让点按键一的时候增加风扇转速,如果点按键零可以直接关掉风扇
Speed -=20;
if(Speed < 20)
{
Speed = 100;
}
Motor_SetSpeed(Speed);
Oled_8_16A(48,2,Speed/100%10);
Oled_8_16A(56,2,Speed/10%10);
Oled_8_16A(64,2,Speed/1%10);
fstuichudata =5;//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
}
else if(fsclose ==2)//如果第一行的风扇关着,这里就调节转速则无反应
{
Oled_clear();
Oledshow12();//风扇关转速0
Motor_SetSpeed(0);
fstuichudata =6;//从一级界面点进去二级界面之后再一次退出出来,然后第二次点进去的二级界面保留之前二级页面的状态
}
KeyFlag = 0;//注意按键标志清零,防止程序跑飞
}
break;
case KEY3_PRES://4,按键3,退出
{
Oled_clear();
Oledshow3();//一级界面
flag = 3;
uuflag =0;
KeyFlag = 0;//注意按键标志清零,防止程序跑飞
}
break;
}
}
}
int main(void)
{
Timer_Init();//1ms
LED_Init();
OLED_Init();
Motor_Init();
Key_Init();
Oled_clear();
Oledshow1();
while(1)
{
Key_Show1();//一级界面
Key_show2();//二级界面
if(T_flag == 1)
{
if(Temp_time >= 2000)//2s检测一次,温湿度
{
if(DHT_Read()== 1)
{
//湿度数据整数部分
Oled_8_16(48,0,datas[0]/10);//十位
Oled_8_16(56,0,datas[0]%10);//个位
//湿度符号.
Oled_8_16(64,0,13);
//湿度数据小数部分
Oled_8_16(72,0,datas[1]/10);
Oled_8_16(80,0,datas[1]%10);
//温度数据整数部分
Oled_8_16(48,2,datas[2]/10);
Oled_8_16(56,2,datas[2]%10);
//温度符号.
Oled_8_16(64,2,13);
//温度数据小数部分
Oled_8_16(72,2,datas[3]/10);
Oled_8_16(80,2,datas[3]%10);
}
}
}
if(BEEP_TIME>=500)//500ms响一次蜂鸣器,不受按键影响,这里必须写大于,因为OLED按的某个时刻有可能计数值大于500
{
Beep =!Beep;
BEEP_TIME =0;
}
}
}
OLED.c
#include "stm32f10x.h"
#include "Dht11.h"
#include "OLED_Font.h"
/*引脚配置*/
#define OLED_W_SCL(x) GPIO_WriteBit(GPIOB, GPIO_Pin_12, (BitAction)(x))
#define OLED_W_SDA(x) GPIO_WriteBit(GPIOB, GPIO_Pin_13, (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_12;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
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-PAGE7
OLED_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是右上部分,所以想取左下部分就+8
adder++;
}
}
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是左下部分,所以想取右下部分就+8
adder++;
}
}
/*
功能:显示数字,英文,字符
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 header
void OLED_Init(void);
void Oled_clear(void);// 清屏函数
void OLED_WriteCommand(uint8_t Command);
void OLED_WriteData(uint8_t Data);
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
OLED_Font.c
#include "stm32f10x.h" // Device header
/*-------------------------此处添加所要加入的中文字库--------------------------*/
const 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,
};
/*-------------------------此处添加所要加入的英文符号数字字库--------------------------*/
const unsigned char F8_16[]=
{
//字模提取app—参数设置:其他选项,纵向取模,字节倒序,保留,任何时候都加0
//文字输入区输入字,任何ctrl+回车生成
0x00,0x00,0xF0,0xF8,0x08,0x68,0xF8,0xF0,0x00,0x00,0x07,0x0F,0x0B,0x08,0x0F,0x07,//数字0,0
0x00,0x20,0x20,0x30,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x0F,0x00,0x00,//数字1,1
0x00,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
};
/*-------------------------此处添加所要加入的英文符号数字字库,颜色反转--------------------------*/
const 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
};
OLED_Font.h
#ifndef __OLED_FONT_H
#define __OLED_FONT_H
#include "stm32f10x.h" // Device header
extern const unsigned char F16_16[];
extern const unsigned char F8_16[];
extern const unsigned char F8_16A[];
#endif
OLEDShow.c
#include "stm32f10x.h" // Device header
#include "OLED.h"
//初始一级界面
//*选择颜色灯(颜色反转)
// 查看温度
// 风扇开关选择
void Oledshow1()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,0,10);//字符*
//选
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);
//灯
Oled_8_16_L(40,0,2);
Oled_8_16_R(48,0,2);
//颜
Oled_8_16_L(56,0,3);
Oled_8_16_R(64,0,3);
//色
Oled_8_16_L(72,0,4);
Oled_8_16_R(80,0,4);
//查
Oled_8_16_L(8,2,26);
Oled_8_16_R(16,2,26);
//看
Oled_8_16_L(24,2,27);
Oled_8_16_R(32,2,27);
//温
Oled_8_16_L(40,2,28);
Oled_8_16_R(48,2,28);
//度
Oled_8_16_L(56,2,29);
Oled_8_16_R(64,2,29);
//风
Oled_8_16_L(8,4,30);
Oled_8_16_R(16,4,30);
//扇
Oled_8_16_L(24,4,31);
Oled_8_16_R(32,4,31);
//开
Oled_8_16_L(40,4,32);
Oled_8_16_R(48,4,32);
//关
Oled_8_16_L(56,4,33);
Oled_8_16_R(64,4,33);
//选
Oled_8_16_L(72,4,34);
Oled_8_16_R(80,4,34);
//择
Oled_8_16_L(88,4,35);
Oled_8_16_R(96,4,35);
}
//初始一级界面
// 选择颜色灯
//*查看温度(颜色反转)
// 风扇开关选择
void Oledshow2()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,2,10);//字符*
//选
Oled_8_16_L(8,0,21);
Oled_8_16_R(16,0,21);
//择
Oled_8_16_L(24,0,22);
Oled_8_16_R(32,0,22);
//灯
Oled_8_16_L(40,0,23);
Oled_8_16_R(48,0,23);
//颜
Oled_8_16_L(56,0,24);
Oled_8_16_R(64,0,24);
//色
Oled_8_16_L(72,0,25);
Oled_8_16_R(80,0,25);
//查
Oled_8_16_L(8,2,5);
Oled_8_16_R(16,2,5);
//看
Oled_8_16_L(24,2,6);
Oled_8_16_R(32,2,6);
//温
Oled_8_16_L(40,2,7);
Oled_8_16_R(48,2,7);
//度
Oled_8_16_L(56,2,8);
Oled_8_16_R(64,2,8);
//风
Oled_8_16_L(8,4,30);
Oled_8_16_R(16,4,30);
//扇
Oled_8_16_L(24,4,31);
Oled_8_16_R(32,4,31);
//开
Oled_8_16_L(40,4,32);
Oled_8_16_R(48,4,32);
//关
Oled_8_16_L(56,4,33);
Oled_8_16_R(64,4,33);
//选
Oled_8_16_L(72,4,34);
Oled_8_16_R(80,4,34);
//择
Oled_8_16_L(88,4,35);
Oled_8_16_R(96,4,35);
}
//初始一级界面
// 选择颜色灯
// 查看温度
//*风扇开关选择(颜色反转)
void Oledshow3()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,4,10);//字符*
//选
Oled_8_16_L(8,0,21);
Oled_8_16_R(16,0,21);
//择
Oled_8_16_L(24,0,22);
Oled_8_16_R(32,0,22);
//灯
Oled_8_16_L(40,0,23);
Oled_8_16_R(48,0,23);
//颜
Oled_8_16_L(56,0,24);
Oled_8_16_R(64,0,24);
//色
Oled_8_16_L(72,0,25);
Oled_8_16_R(80,0,25);
//查
Oled_8_16_L(8,2,26);
Oled_8_16_R(16,2,26);
//看
Oled_8_16_L(24,2,27);
Oled_8_16_R(32,2,27);
//温
Oled_8_16_L(40,2,28);
Oled_8_16_R(48,2,28);
//度
Oled_8_16_L(56,2,29);
Oled_8_16_R(64,2,29);
//风
Oled_8_16_L(8,4,9);
Oled_8_16_R(16,4,9);
//扇
Oled_8_16_L(24,4,10);
Oled_8_16_R(32,4,10);
//开
Oled_8_16_L(40,4,11);
Oled_8_16_R(48,4,11);
//关
Oled_8_16_L(56,4,12);
Oled_8_16_R(64,4,12);
//选
Oled_8_16_L(72,4,13);
Oled_8_16_R(80,4,13);
//择
Oled_8_16_L(88,4,14);
Oled_8_16_R(96,4,14);
//OLED_WriteCommand(0x2F);//开启滚动
}
//选择灯颜色二级界面
//*红灯:关(颜色反转)
// 绿灯:关
void Oledshow4()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,0,10);//字符*
//红
Oled_8_16_L(8,0,15);
Oled_8_16_R(16,0,15);
//灯
Oled_8_16_L(24,0,16);
Oled_8_16_R(32,0,16);
//字符:
Oled_8_16A(40,0,10);
//关
Oled_8_16_L(48,0,17);
Oled_8_16_R(56,0,17);
//绿
Oled_8_16_L(8,2,40);
Oled_8_16_R(16,2,40);
//灯
Oled_8_16_L(24,2,41);
Oled_8_16_R(32,2,41);
//字符:
Oled_8_16(40,2,11);
//关
Oled_8_16_L(48,2,38);
Oled_8_16_R(56,2,38);
}
//选择灯颜色二级界面
//*红灯:开(颜色反转)
// 绿灯:关
void Oledshow5()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,2,12);//全黑,把原来的第二行的*覆盖掉
Oled_8_16(0,0,10);//字符*
//红
Oled_8_16_L(8,0,15);
Oled_8_16_R(16,0,15);
//灯
Oled_8_16_L(24,0,16);
Oled_8_16_R(32,0,16);
//字符:
Oled_8_16A(40,0,10);
//开
Oled_8_16_L(48,0,18);
Oled_8_16_R(56,0,18);
//绿
Oled_8_16_L(8,2,40);
Oled_8_16_R(16,2,40);
//灯
Oled_8_16_L(24,2,41);
Oled_8_16_R(32,2,41);
//字符:
Oled_8_16(40,2,11);
//关
Oled_8_16_L(48,2,38);
Oled_8_16_R(56,2,38);
}
//选择灯颜色二级界面
// 红灯:关
//*绿灯:开(颜色反转)
void Oledshow6()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,0,12);//全黑,把原来的第一行的*覆盖掉
Oled_8_16(0,2,10);//字符*
//红
Oled_8_16_L(8,0,36);
Oled_8_16_R(16,0,36);
//灯
Oled_8_16_L(24,0,37);
Oled_8_16_R(32,0,37);
//字符:
Oled_8_16(40,0,11);
//关
Oled_8_16_L(48,0,38);
Oled_8_16_R(56,0,38);
//绿
Oled_8_16_L(8,2,19);
Oled_8_16_R(16,2,19);
//灯
Oled_8_16_L(24,2,20);
Oled_8_16_R(32,2,20);
//字符:
Oled_8_16A(40,2,10);
//开
Oled_8_16_L(48,2,18);
Oled_8_16_R(56,2,18);
}
//选择灯颜色二级界面
//*红灯:关(颜色反转)
// 绿灯:关
void Oledshow7()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,2,12);//全黑,把原来的第一行的*覆盖掉
Oled_8_16(0,0,10);//字符*
//红
Oled_8_16_L(8,0,15);
Oled_8_16_R(16,0,15);
//灯
Oled_8_16_L(24,0,16);
Oled_8_16_R(32,0,16);
//字符:
Oled_8_16A(40,0,10);
//关
Oled_8_16_L(48,0,17);
Oled_8_16_R(56,0,17);
//绿
Oled_8_16_L(8,2,40);
Oled_8_16_R(16,2,40);
//灯
Oled_8_16_L(24,2,41);
Oled_8_16_R(32,2,41);
//字符:
Oled_8_16(40,2,11);
//关
Oled_8_16_L(48,2,38);
Oled_8_16_R(56,2,38);
}
//选择灯颜色二级界面
// 红灯:关
//*绿灯:关(颜色反转)
void Oledshow8()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,0,12);//全黑,把原来的第一行的*覆盖掉
Oled_8_16(0,2,10);//字符*
//红
Oled_8_16_L(8,0,36);
Oled_8_16_R(16,0,36);
//灯
Oled_8_16_L(24,0,37);
Oled_8_16_R(32,0,37);
//字符:
Oled_8_16(40,0,11);
//关
Oled_8_16_L(48,0,38);
Oled_8_16_R(56,0,38);
//绿
Oled_8_16_L(8,2,19);
Oled_8_16_R(16,2,19);
//灯
Oled_8_16_L(24,2,20);
Oled_8_16_R(32,2,20);
//字符:
Oled_8_16A(40,2,10);
//关
Oled_8_16_L(48,2,17);
Oled_8_16_R(56,2,17);
}
//风扇开关选择二级界面
//*风扇:关(颜色反转)
// 转速:0
void Oledshow9()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,0,10);//字符*
//风
Oled_8_16_L(8,0,42);
Oled_8_16_R(16,0,42);
//扇
Oled_8_16_L(24,0,43);
Oled_8_16_R(32,0,43);
//字符:
Oled_8_16A(40,0,10);
//关
Oled_8_16_L(48,0,17);
Oled_8_16_R(56,0,17);
//转
Oled_8_16_L(8,2,48);
Oled_8_16_R(16,2,48);
//速
Oled_8_16_L(24,2,49);
Oled_8_16_R(32,2,49);
//字符:
Oled_8_16(40,2,11);
//速度数字0
Oled_8_16(48,2,0);
}
//风扇开关选择二级界面
//*风扇:开(颜色反转)
// 转速:100
void Oledshow10()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,0,10);//字符*
//风
Oled_8_16_L(8,0,42);
Oled_8_16_R(16,0,42);
//扇
Oled_8_16_L(24,0,43);
Oled_8_16_R(32,0,43);
//字符:
Oled_8_16A(40,0,10);
//开
Oled_8_16_L(48,0,18);
Oled_8_16_R(56,0,18);
//转
Oled_8_16_L(8,2,48);
Oled_8_16_R(16,2,48);
//速
Oled_8_16_L(24,2,49);
Oled_8_16_R(32,2,49);
//字符:
Oled_8_16(40,2,11);
//速度数字100
Oled_8_16(48,2,1);
Oled_8_16(56,2,0);
Oled_8_16(64,2,0);
}
//风扇开关选择二级界面
// 风扇:开
//*转速:0-100(颜色反转)
void Oledshow11()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,2,10);//字符*
//风
Oled_8_16_L(8,0,46);
Oled_8_16_R(16,0,46);
//扇
Oled_8_16_L(24,0,47);
Oled_8_16_R(32,0,47);
//字符:
Oled_8_16(40,0,11);
//开
Oled_8_16_L(48,0,32);
Oled_8_16_R(56,0,32);
//转
Oled_8_16_L(8,2,44);
Oled_8_16_R(16,2,44);
//速
Oled_8_16_L(24,2,45);
Oled_8_16_R(32,2,45);
//字符:
Oled_8_16A(40,2,10);
}
//风扇开关选择二级界面
// 风扇:开
//*转速:0(颜色反转)
void Oledshow12()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,2,10);//字符*
//风
Oled_8_16_L(8,0,46);
Oled_8_16_R(16,0,46);
//扇
Oled_8_16_L(24,0,47);
Oled_8_16_R(32,0,47);
//字符:
Oled_8_16(40,0,11);
//开
Oled_8_16_L(48,0,33);
Oled_8_16_R(56,0,33);
//转
Oled_8_16_L(8,2,44);
Oled_8_16_R(16,2,44);
//速
Oled_8_16_L(24,2,45);
Oled_8_16_R(32,2,45);
//字符:
Oled_8_16A(40,2,10);
Oled_8_16A(48,2,0);
}
void Oledshow13()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
//湿
Oled_8_16_L(8,0,50);
Oled_8_16_R(16,0,50);
//度
Oled_8_16_L(24,0,51);
Oled_8_16_R(32,0,51);
//字符:
Oled_8_16(40,0,11);
//温
Oled_8_16_L(8,2,52);
Oled_8_16_R(16,2,52);
//度
Oled_8_16_L(24,2,53);
Oled_8_16_R(32,2,53);
//字符:
Oled_8_16(40,2,11);
}
//选择灯颜色二级界面
//*红灯:开(颜色反转)
// 绿灯:开
void Oledshow14()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,2,12);//全黑,把原来的第二行的*覆盖掉
Oled_8_16(0,0,10);//字符*
//红
Oled_8_16_L(8,0,15);
Oled_8_16_R(16,0,15);
//灯
Oled_8_16_L(24,0,16);
Oled_8_16_R(32,0,16);
//字符:
Oled_8_16A(40,0,10);
//开
Oled_8_16_L(48,0,18);
Oled_8_16_R(56,0,18);
//绿
Oled_8_16_L(8,2,40);
Oled_8_16_R(16,2,40);
//灯
Oled_8_16_L(24,2,41);
Oled_8_16_R(32,2,41);
//字符:
Oled_8_16(40,2,11);
//开
Oled_8_16_L(48,2,39);
Oled_8_16_R(56,2,39);
}
//选择灯颜色二级界面
// 红灯:开
//*绿灯:开(颜色反转)
void Oledshow15()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,0,12);//全黑,把原来的第一行的*覆盖掉
Oled_8_16(0,2,10);//字符*
//红
Oled_8_16_L(8,0,36);
Oled_8_16_R(16,0,36);
//灯
Oled_8_16_L(24,0,37);
Oled_8_16_R(32,0,37);
//字符:
Oled_8_16(40,0,11);
//开
Oled_8_16_L(48,0,39);
Oled_8_16_R(56,0,39);
//绿
Oled_8_16_L(8,2,19);
Oled_8_16_R(16,2,19);
//灯
Oled_8_16_L(24,2,20);
Oled_8_16_R(32,2,20);
//字符:
Oled_8_16A(40,2,10);
//开
Oled_8_16_L(48,2,18);
Oled_8_16_R(56,2,18);
}
//选择灯颜色二级界面
//*红灯:关(颜色反转)
// 绿灯:开
void Oledshow16()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,2,12);//全黑,把原来的第二行的*覆盖掉
Oled_8_16(0,0,10);//字符*
//红
Oled_8_16_L(8,0,15);
Oled_8_16_R(16,0,15);
//灯
Oled_8_16_L(24,0,16);
Oled_8_16_R(32,0,16);
//字符:
Oled_8_16A(40,0,10);
//关
Oled_8_16_L(48,0,17);
Oled_8_16_R(56,0,17);
//绿
Oled_8_16_L(8,2,40);
Oled_8_16_R(16,2,40);
//灯
Oled_8_16_L(24,2,41);
Oled_8_16_R(32,2,41);
//字符:
Oled_8_16(40,2,11);
//开
Oled_8_16_L(48,2,39);
Oled_8_16_R(56,2,39);
}
//选择灯颜色二级界面
// 红灯:开
//*绿灯:关(颜色反转)
void Oledshow17()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,0,12);//全黑,把原来的第一行的*覆盖掉
Oled_8_16(0,2,10);//字符*
//红
Oled_8_16_L(8,0,36);
Oled_8_16_R(16,0,36);
//灯
Oled_8_16_L(24,0,37);
Oled_8_16_R(32,0,37);
//字符:
Oled_8_16(40,0,11);
//开
Oled_8_16_L(48,0,39);
Oled_8_16_R(56,0,39);
//绿
Oled_8_16_L(8,2,19);
Oled_8_16_R(16,2,19);
//灯
Oled_8_16_L(24,2,20);
Oled_8_16_R(32,2,20);
//字符:
Oled_8_16A(40,2,10);
//关
Oled_8_16_L(48,2,17);
Oled_8_16_R(56,2,17);
}
//初始一级界面
// 选择颜色灯
//*查看温度(颜色反转)
// 风扇开关选择
void Oledshow18()//展示需要的效果
{
OLED_WriteCommand(0x2E);//关闭滚动
OLED_WriteCommand(0x26);//向右滚动
OLED_WriteCommand(0x00);//A:固定指令0
OLED_WriteCommand(0x00);//B:起始页0
OLED_WriteCommand(0x07);//C:刷新帧
OLED_WriteCommand(0x07);//D:结束页
OLED_WriteCommand(0x00);//虚拟字节
OLED_WriteCommand(0xFF);//虚拟字节
Oled_8_16(0,2,10);//字符*
//选
Oled_8_16_L(8,0,21);
Oled_8_16_R(16,0,21);
//择
Oled_8_16_L(24,0,22);
Oled_8_16_R(32,0,22);
//灯
Oled_8_16_L(40,0,23);
Oled_8_16_R(48,0,23);
//颜
Oled_8_16_L(56,0,24);
Oled_8_16_R(64,0,24);
//色
Oled_8_16_L(72,0,25);
Oled_8_16_R(80,0,25);
//查
Oled_8_16_L(8,2,5);
Oled_8_16_R(16,2,5);
//看
Oled_8_16_L(24,2,6);
Oled_8_16_R(32,2,6);
//温
Oled_8_16_L(40,2,7);
Oled_8_16_R(48,2,7);
//度
Oled_8_16_L(56,2,8);
Oled_8_16_R(64,2,8);
//风
Oled_8_16_L(8,4,30);
Oled_8_16_R(16,4,30);
//扇
Oled_8_16_L(24,4,31);
Oled_8_16_R(32,4,31);
//开
Oled_8_16_L(40,4,32);
Oled_8_16_R(48,4,32);
//关
Oled_8_16_L(56,4,33);
Oled_8_16_R(64,4,33);
//选
Oled_8_16_L(72,4,34);
Oled_8_16_R(80,4,34);
//择
Oled_8_16_L(88,4,35);
Oled_8_16_R(96,4,35);
}
OLEDShow.h
#ifndef __OLEDSHOW_H
#define __OLEDSHOW_H
void Oledshow1(void);
void Oledshow2(void);
void Oledshow3(void);
void Oledshow4(void);
void Oledshow5(void);
void Oledshow6(void);
void Oledshow7(void);
void Oledshow8(void);
void Oledshow9(void);
void Oledshow10(void);
void Oledshow11(void);
void Oledshow12(void);
void Oledshow13(void);
void Oledshow14(void);
void Oledshow15(void);
void Oledshow16(void);
void Oledshow17(void);
void Oledshow18(void);
#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)); //等待计数到0
SysTick->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 header
void Delay_us(uint32_t us);
void Delay_ms(uint32_t ms);
void Delay_s(uint32_t s);
#endif
Key.c
#include "stm32f10x.h" // Device header
#include "Key.h"
uint8_t KeyFlag = 0; //按键标志
typedef enum//按键状态
{
KEY_CHECK =0,//检测
KEY_CONFIRM = 1,//确认
KEY_RELEASE = 2//释放
}KEY_STATE;
KEY_STATE KeyState = KEY_CHECK; //初始化按键状态为检测状态,KeyState是变量,KEY_CHECK是数值,初始化为0
void Key_Init()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IPU;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_6;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE,&GPIO_InitStruct);
}
uint8_t Key_Scan(void)
{
static uint8_t KeyFlag = 0; //按键标志
switch(KeyState)//按键状态KeyState为0,1,2其中一个
{
case KEY_CHECK://按键状态:0
if(!KEY)//如果按键值为0,说明按键被按下,切换状态,if是为1才能进入,按键按下了变为0,反转为1才进入
{
KeyState = KEY_CONFIRM;//按键状态从0切换为1
}
break;
case KEY_CONFIRM://按键状态:1
if(!KEY)//判断当前按键值是否为0,确认是否按下
{
KeyState = KEY_RELEASE;//按键状态从1切换为2
if(0 == Key0)//KEY0被按下
{
KeyFlag = KEY0_PRES;//KEY0_PRES=1,KeyFlag=1
}
if(0 == Key1)//KEY1被按下
{
KeyFlag = KEY1_PRES;//KEY1_PRES=2,KeyFlag=2
}
if(0 == Key2)//KEY2被按下
{
KeyFlag = KEY2_PRES;//KEY2_PRES=3,KeyFlag=3
}
if(0 == Key3)//KEY3被按下
{
KeyFlag = KEY3_PRES;//KEY3_PRES=3,KeyFlag=4
}
}
else//按键没有被按下,返回上一状态
{
KeyState = KEY_CHECK;
}
break;
case KEY_RELEASE://按键状态:2
if(KEY)//当前按键值为1,说明按键已经释放,切换到开始状态
{
KeyState = KEY_CHECK;//按键状态从2切换为0,以便下一次使用
return KeyFlag;//释放以后才把按键数值返回
}
break;
}
return 0;
}
Key.h
#ifndef __KEY_H
#define __KEY_H
#include "stm32f10x.h" // Device header
#include "sys.h"
#define Key0 PEin(4)
#define Key1 PEin(3)
#define Key2 PEin(2)
#define Key3 PEin(6)
#define KEY ((Key0) && (Key1) && (Key2)&& (Key3))//两个条件都为真时结果才为真,否则为假,我们按键只能按一个,无法同时按,人手速度没有这么快,所以始终无论哪个按键按下KEY都是0
#define KEY0_PRES 1
#define KEY1_PRES 2
#define KEY2_PRES 3
#define KEY3_PRES 4
extern uint8_t KeyFlag; //按键标志
void Key_Init(void);
uint8_t Key_Scan(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
LED.c
#include "stm32f10x.h" // Device header
#include "LED.h"
void LED_Init(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_5;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStruct);
GPIO_SetBits(GPIOB,GPIO_Pin_5);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_12;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOC,&GPIO_InitStruct);
GPIO_SetBits(GPIOC,GPIO_Pin_12);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_5;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE,&GPIO_InitStruct);
GPIO_SetBits(GPIOE,GPIO_Pin_5);
}
LED.h
#ifndef __LED_H
#define __LED_H
#include "sys.h"
void LED_Init(void);
#define LED_Red PBout(5)
#define LED_Green PEout(5)
#define Beep PCout(12)
#endif
Motor.c
#include "stm32f10x.h" // Device header
#include "PWM.h"
//IN1和IN2分别接PA4和PA5,然后P4和P5就是用作普通引脚输出高低电平。
void Motor_Init(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
PWM_Init();
}
void Motor_SetSpeed(int8_t Speed)
{
if (Speed >= 0)
{
GPIO_SetBits(GPIOA, GPIO_Pin_4);
GPIO_ResetBits(GPIOA, GPIO_Pin_5);
PWM_SetCompare3(Speed);
}
else
{
GPIO_ResetBits(GPIOA, GPIO_Pin_4);
GPIO_SetBits(GPIOA, GPIO_Pin_5);
PWM_SetCompare3(-Speed);
}
}
Motor.h
#ifndef __MOTOR_H
#define __MOTOR_H
#include "stm32f10x.h" // Device header
void Motor_Init(void);
void Motor_SetSpeed(int8_t Speed);
#endif
PWM.c
#include "stm32f10x.h" // Device header
//ENA接PA2,因为PA2是TIM2_CH3,用于输出PWM,
void PWM_Init(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
TIM_InternalClockConfig(TIM2);
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_Period = 100 - 1; //ARR
TIM_TimeBaseInitStructure.TIM_Prescaler = 36 - 1; //PSC
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseInitStructure);
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0; //CCR
TIM_OC3Init(TIM2, &TIM_OCInitStructure);
TIM_Cmd(TIM2, ENABLE);
}
void PWM_SetCompare3(uint16_t Compare)
{
TIM_SetCompare3(TIM2, Compare);
}
PWM.h
#ifndef __PWM_H
#define __PWM_H
#include "stm32f10x.h" // Device header
void PWM_Init(void);
void PWM_SetCompare3(uint16_t Compare);
#endif
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_7;
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_7;
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);//主机拉高20us
DHT11_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,低电平就是数字0
dhtin ? (buffer|=0x01) : (buffer&= ~0x01);//三目运算符,如果dhtin为1,则执行buffer|=0x01,否则buffer&= ~0x01
while(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(7)
#define dhtin PAin(7)
extern char datas[5];
void DHT11_Init_In(void);
void DHT11_Init_Out(void);
uint8_t DHT_Read(void);
#endif
Timer.c
#include "stm32f10x.h" // Device header
#include "LED.h"
#include "Key.h"
volatile uint32_t global_times = 0;
volatile uint32_t BEEP_TIME = 0;
volatile uint32_t Temp_time=0;
void Timer_Init(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_Period = 1000 - 1;
TIM_TimeBaseInitStructure.TIM_Prescaler = 72 - 1;
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseInitStructure);
TIM_ClearFlag(TIM4, TIM_FLAG_Update);
TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_Init(&NVIC_InitStructure);
TIM_Cmd(TIM4, ENABLE);
}
void TIM4_IRQHandler(void)
{
if (TIM_GetITStatus(TIM4, TIM_IT_Update) == SET)//1ms
{
global_times++;
BEEP_TIME ++;
Temp_time ++;
if(global_times ==20)//20ms进入检测按键一次
{
KeyFlag =Key_Scan();
global_times=0;
}
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
}
}
Timer.h
#ifndef __TIMER_H
#define __TIMER_H
#include "stm32f10x.h" // Device header
extern volatile uint32_t global_times;
extern volatile uint32_t BEEP_TIME;
extern volatile uint32_t Temp_time;
void Timer_Init(void);
#endif