一、下载资料包
链接:0.96寸SPI_OLED模块配套资料包
下载解压之后打开文件夹中的Demo,然后选择相应的板子Demo,用Keil编译
将程序烧录到开发板并运行
?二、修改程序显示学号和姓名
找到姓名的中文点阵
显示函数
void TEST_MainPage(void)
{
GUI_ShowCHinese(28,20,16,"刘蒙",1);//中文姓名
GUI_ShowString(4,48,"631907060512",16,1);//数字详细
delay_ms(1500);
delay_ms(1500);
}
main函数
int main(void)
{
delay_init(); //延时函数初始化
OLED_Init(); //初始化OLED
OLED_Clear(0); //清屏(全黑)
while(1)
{
TEST_MainPage(); //界面显示
}
}
结果如下
温湿度显示
在之前温湿度代码中添加OLED代码
修改main.c文件
#include "delay.h"
#include "usart.h"
#include "bsp_i2c.h"
#include "sys.h"
#include "oled.h"
#include "gui.h"
#include "test.h"
int main(void)
{
delay_init(); //延时函数初始化
uart_init(115200);
IIC_Init();
NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
OLED_Init(); //初始化OLED
OLED_Clear(0);
while(1)
{
//printf("温度湿度显示");
read_AHT20_once();
OLED_Clear(0);
delay_ms(1500);
}
}
修改bsp_i2c.c文件中的read_AHT20函数如下:
void read_AHT20(void)
{
uint8_t i;
for(i=0; i<6; i++)
{
readByte[i]=0;
}
//-------------
I2C_Start();
I2C_WriteByte(0x71);
ack_status = Receive_ACK();
readByte[0]= I2C_ReadByte();
Send_ACK();
readByte[1]= I2C_ReadByte();
Send_ACK();
readByte[2]= I2C_ReadByte();
Send_ACK();
readByte[3]= I2C_ReadByte();
Send_ACK();
readByte[4]= I2C_ReadByte();
Send_ACK();
readByte[5]= I2C_ReadByte();
SendNot_Ack();
//Send_ACK();
I2C_Stop();
//--------------
if( (readByte[0] & 0x68) == 0x08 )
{
H1 = readByte[1];
H1 = (H1<<8) | readByte[2];
H1 = (H1<<8) | readByte[3];
H1 = H1>>4;
H1 = (H1*1000)/1024/1024;
T1 = readByte[3];
T1 = T1 & 0x0000000F;
T1 = (T1<<8) | readByte[4];
T1 = (T1<<8) | readByte[5];
T1 = (T1*2000)/1024/1024 - 500;
AHT20_OutData[0] = (H1>>8) & 0x000000FF;
AHT20_OutData[1] = H1 & 0x000000FF;
AHT20_OutData[2] = (T1>>8) & 0x000000FF;
AHT20_OutData[3] = T1 & 0x000000FF;
}
else
{
AHT20_OutData[0] = 0xFF;
AHT20_OutData[1] = 0xFF;
AHT20_OutData[2] = 0xFF;
AHT20_OutData[3] = 0xFF;
printf("lyy");
}
printf("\r\n");
printf("温度:%d%d.%d",T1/100,(T1/10)%10,T1%10);
printf("湿度:%d%d.%d",H1/100,(H1/10)%10,H1%10);
printf("\r\n");
t=T1/10;
t1=T1%10;
a=(float)(t+t1*0.1);
h=H1/10;
h1=H1%10;
b=(float)(h+h1*0.1);
sprintf(strTemp,"%.1f",a); //调用Sprintf函数把DHT11的温度数据格式化到字符串数组变量strTemp中
sprintf(strHumi,"%.1f",b); //调用Sprintf函数把DHT11的湿度数据格式化到字符串数组变量strHumi中
//printf(strTemp);
//printf("/r/n");
GUI_ShowCHinese(16,00,16,"温湿度显示",1);
GUI_ShowCHinese(16,20,16,"温度",1);
GUI_ShowString(53,20,strTemp,16,1);
GUI_ShowCHinese(16,38,16,"湿度",1);
GUI_ShowString(53,38,strHumi,16,1);
delay_ms(1500);
delay_ms(1500);
delay_ms(1500);
delay_ms(1500);
}
?点阵
"温",0x00,0x00,0x23,0xF8,0x12,0x08,0x12,0x08,0x83,0xF8,0x42,0x08,0x42,0x08,0x13,0xF8,
0x10,0x00,0x27,0xFC,0xE4,0xA4,0x24,0xA4,0x24,0xA4,0x24,0xA4,0x2F,0xFE,0x00,0x00,/*"温",0*/
"度",0x01,0x00,0x00,0x80,0x3F,0xFE,0x22,0x20,0x22,0x20,0x3F,0xFC,0x22,0x20,0x22,0x20,
0x23,0xE0,0x20,0x00,0x2F,0xF0,0x24,0x10,0x42,0x20,0x41,0xC0,0x86,0x30,0x38,0x0E,/*"度",0*/
"湿",0x00,0x00,0x27,0xF8,0x14,0x08,0x14,0x08,0x87,0xF8,0x44,0x08,0x44,0x08,0x17,0xF8,
0x11,0x20,0x21,0x20,0xE9,0x24,0x25,0x28,0x23,0x30,0x21,0x20,0x2F,0xFE,0x00,0x00,/*"湿",0*/
"显",0x00,0x00,0x1F,0xF0,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,0x10,0x10,0x1F,0xF0,
0x04,0x40,0x44,0x44,0x24,0x44,0x14,0x48,0x14,0x50,0x04,0x40,0xFF,0xFE,0x00,0x00,/*"显",0*/
"示",0x00,0x00,0x3F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFE,0x01,0x00,
0x01,0x00,0x11,0x10,0x11,0x08,0x21,0x04,0x41,0x02,0x81,0x02,0x05,0x00,0x02,0x00,/*"示",0*/
效果如下
实现滑动显示
水平方向滚动
OLED_WR_Byte(0x2E,OLED_CMD); //关闭滚动
OLED_WR_Byte(0x26,OLED_CMD); //水平向左或者右滚动 26/27
OLED_WR_Byte(0x00,OLED_CMD); //虚拟字节
OLED_WR_Byte(0x00,OLED_CMD); //起始页 0
OLED_WR_Byte(0x07,OLED_CMD); //滚动时间间隔
OLED_WR_Byte(0x07,OLED_CMD); //终止页 7
OLED_WR_Byte(0x00,OLED_CMD); //虚拟字节
OLED_WR_Byte(0xFF,OLED_CMD); //虚拟字节
OLED_WR_Byte(0x2F,OLED_CMD); //开启滚动
垂直方向滚动
OLED_WR_Byte(0x2e,OLED_CMD); //关闭滚动
OLED_WR_Byte(0x29,OLED_CMD); //水平垂直和水平滚动左右 29/2a
OLED_WR_Byte(0x00,OLED_CMD); //虚拟字节
OLED_WR_Byte(0x00,OLED_CMD); //起始页 0
OLED_WR_Byte(0x07,OLED_CMD); //滚动时间间隔
OLED_WR_Byte(0x07,OLED_CMD); //终止页 1
OLED_WR_Byte(0x01,OLED_CMD); //垂直滚动偏移量
OLED_WR_Byte(0x2F,OLED_CMD); //开启滚动
?字模
{0x04,0x10,0x24,0x08,0x44,0x06,0x84,0x01,0x64,0x82,0x9C,0x4C,0x40,0x20,0x30,0x18},
{0x0F,0x06,0xC8,0x01,0x08,0x06,0x08,0x18,0x28,0x20,0x18,0x40,0x00,0x80,0x00,0x00},/*"欢",0*/
{0x40,0x00,0x40,0x40,0x42,0x20,0xCC,0x1F,0x00,0x20,0x00,0x40,0xFC,0x4F,0x04,0x44},
{0x02,0x42,0x00,0x40,0xFC,0x7F,0x04,0x42,0x04,0x44,0xFC,0x43,0x00,0x40,0x00,0x00},/*"迎",1*/
{0x00,0x21,0x08,0x21,0x08,0x11,0x28,0x11,0xC8,0x09,0x08,0x05,0x08,0x03,0xFF,0xFF},
{0x08,0x03,0x08,0x05,0x88,0x09,0x68,0x11,0x08,0x11,0x08,0x21,0x00,0x21,0x00,0x00},/*"来",2*/
{0x42,0x40,0x62,0xC4,0x52,0x44,0x4A,0x44,0xC6,0x7F,0x42,0x24,0x52,0x24,0x62,0x24},
{0xC2,0x20,0x00,0x00,0xF8,0x0F,0x00,0x40,0x00,0x80,0xFF,0x7F,0x00,0x00,0x00,0x00},/*"到",3*/
{0x10,0x40,0x10,0x40,0x14,0x50,0xD4,0x57,0x54,0x55,0x54,0x55,0x54,0x55,0xFC,0x7F},
{0x52,0x55,0x52,0x55,0x52,0x55,0xD3,0x57,0x12,0x50,0x10,0x40,0x10,0x40,0x00,0x00},/*"重",4*/
{0x00,0x40,0x00,0x30,0xFC,0x0F,0x04,0x80,0x84,0x40,0x84,0x20,0x84,0x18,0x85,0x06},
{0xF6,0x01,0x84,0x06,0x84,0x18,0x84,0x20,0x84,0x40,0x84,0x80,0x04,0x80,0x00,0x00},/*"庆",5*/
{0x08,0x80,0x08,0x81,0x88,0x40,0x68,0x40,0x08,0x21,0x08,0x22,0x09,0x14,0x0E,0x08},
{0x08,0x14,0x08,0x22,0x88,0x41,0x28,0x40,0x48,0x80,0x88,0x81,0x08,0x80,0x00,0x00},/*"交",6*/
{0x40,0x80,0x42,0x40,0xCC,0x3F,0x00,0x40,0x00,0x80,0xE2,0xFF,0x22,0x89,0x2A,0x89},
{0x2A,0x89,0xF2,0xBF,0x2A,0x89,0x26,0xA9,0x22,0xC9,0xE0,0xBF,0x00,0x80,0x00,0x00},/*"通",7*/
{0x20,0x80,0x20,0x80,0x20,0x40,0x20,0x20,0x20,0x10,0x20,0x0C,0x20,0x03,0xFF,0x00},
{0x20,0x03,0x20,0x0C,0x20,0x10,0x20,0x20,0x20,0x40,0x20,0x80,0x20,0x80,0x00,0x00},/*"大",8*/
{0x40,0x04,0x30,0x04,0x11,0x04,0x96,0x04,0x90,0x04,0x90,0x44,0x91,0x84,0x96,0x7E},
{0x90,0x06,0x90,0x05,0x98,0x04,0x14,0x04,0x13,0x04,0x50,0x04,0x30,0x04,0x00,0x00},/*"学",9*/
显示结果
?
三、参考文章
?stm32+(4SPI)OLED显示数据_机智的橙子的博客-CSDN博客 0.96寸OLED在STM32f103上实现滚动显示长字符_Harriet的博客-CSDN博客_oled滚动显示
|