基于SPI/IIC接口的OLED数据显示

一、STM32F103的IIC接口实现

1.任务要求

(1)显示自己的学号和姓名;
(2)显示AHT20的温度和湿度;
(3)上下或左右的滑动显示长字符,比如“Hello,欢迎来到重庆交通大学物联网205实训室!”或者歌词、诗词。(最好使用硬件刷屏模式)

2.代码提取

野火官网下载工程代码

3.打开工程

在这里插入图片描述

4.修改代码

(1)生成字模
生成一个16*16的字模
原理
在这里插入图片描述
在点阵库里把自己需要的找到,写出对应的数据
例如:
在这里插入图片描述
在这里插入图片描述

对应数据:
{0x20,0x01,0x20,0x11,0x20,0x11,0x27,0xD2,0xF5,0x52,0x25,0x54,0x25,0x58,0x25,0x70,0x25,0x58,0x25,0x54,0xF5,0x52,0x27,0xD2},
{0x20,0x11,0x20,0x11,0x20,0x01,0x00,0x00},/“莫”,0/
{0x00,0x21,0x20,0xC1,0x20,0x82,0x2E,0x84,0x2A,0xB8,0x2A,0xA0,0xAA,0xA0,0x6A,0xA0,0x2A,0xA0,0x2A,0xA0,0x2A,0xBE,0x2E,0x81},
{0x20,0x81,0x20,0xA1,0x00,0xC7,0x00,0x00},/“亮”,1/
(2)添加代码
打开文件
在这里插入图片描述
将自己需要的字符添加进去
在这里插入图片描述
这样就OK了。

二、温湿度显示

1.相关函数

/*****************************************************************************
							显示温湿度
******************************************************************************/
void Temp_Hum(float temp, float hum)
{
	char data1[4],data2[4];
	sprintf(data1, "%.1f", temp);
	
	GUI_DrawLine(0, 10, WIDTH-1, 10,1);
	GUI_DrawLine(WIDTH/2-1,11,WIDTH/2-1,HEIGHT-1,1);
	GUI_DrawLine(WIDTH/2-1,10+(HEIGHT-10)/2-1,WIDTH-1,10+(HEIGHT-10)/2-1,1);
	GUI_ShowString(0,1,"2020-12-20",8,1);
	GUI_ShowString(78,1,"Sunday",8,1);
	GUI_ShowString(14,HEIGHT-1-10,"Cloudy",8,1);
	//温度
	GUI_ShowString(WIDTH/2-1+2,13,"TEMP",8,1);
	GUI_DrawCircle(WIDTH-1-19, 25, 1,2);
	GUI_ShowString(WIDTH-1-14,20,"C",16,1);
	GUI_ShowString(WIDTH/2-1+9,20,(u8 *)data1,16,1);
	
	//湿度
	GUI_ShowString(WIDTH/2-1+2,39,"HUM",8,1);
	GUI_DrawBMP(6,16,51,32, BMP5, 1);
	sprintf(data2, "%.1f", hum);
	GUI_ShowString(WIDTH/2-1+9,46,(u8 *)data2,16,1);
	GUI_ShowString(WIDTH-1-14,46,"%",16,1);
}

main.c

#include "stm32f10x.h"
#include "bsp_usart.h"
#include "delay.h"
#include "bsp_aht20.h"
#include "bsp_led.h"
#include "gui.h"
#include "oled.h"
#include "test.h"

extern u32 flag;//标志是否开启延迟
int main(void)
{
	u32 CT_data[2]={0};
    volatile float  hum=0,temp=0;
	u32 i=1;
	u32 num = 0;//记录AHT20采集次数
	USART_Config();			//USART1初始化
	LED_GPIO_Config();		//LED端口初始化
    delay_init();	    	//延时函数初始化	  
    temphum_init();         //初始化温湿度传感器
	OLED_Init();			         //初始化OLED  
	OLED_Clear(0);             //清屏(全黑)
	while(1)
	{
		flag = i;
		/* 采集3次温湿度  */
		if(i<4)
		{
			AHT20_Read_CTdata(CT_data);       //不经过CRC校验,直接读取AHT20的温度和湿度数据 
			hum = CT_data[0]*100*10/1024/1024;  //计算得到湿度值(放大了10倍)
			temp = CT_data[1]*200*10/1024/1024-500;//计算得到温度值(放大了10倍)

			printf("湿度:%.1f%%\r\n",(hum/10));
			printf("温度:%.1f度\r\n",(temp/10));
			printf("\r\n");
			Temp_Hum(temp/10, hum/10);
			num++;
			green_led_on;
			delay_ms(1000);
			green_led_off;
			delay_ms(1000);
		}
		
		/* 显示个人简介 */
		if(i==4){
			OLED_Clear(0);
			Display_introduction();
			delay_ms(1000);
		}
		
		/*  显示个人座右铭*/
		if(i==5)
		{
			OLED_Clear(0);
			Display_motto();
			delay_ms(1000);
			OLED_Clear(0);
			i = 0;
			num=0;
		}
		if(num == 3)
		{
			num = 0;
			i = 3;
		}
			
		i++;
		printf("i=%d,num=%d\r\n",i,num);
	 }
}

OLED屏滚动指令

参考链接
SSD1306-0.96寸oled屏-滚动指令介绍

效果展示

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Pin Number Symbol I/O Function P Po o we er r S Su up pp pl ly y 9 VDD P P Po o we er r S Su up pp pl ly y f fo or r L Lo og gi ic c This is a voltage supply pin. It must be connected to external source. 8 VSS P G Gr ro ou un nd d o of f L Lo og gi ic c C Ci ir rc cu ui it t This is a ground pin. It acts as a reference for the logic pins. It must be connected to external ground. 28 VCC P P Po o we er r S Su up pp pl ly y f fo or r OE EL L P Pa an ne el l This is the most positive voltage supply pin of the chip. A stabilization capacitor should be connected between this pin and V SS when the converter is used. It must be connected to external source when the converter is not used. 29 VLSS P G Gr ro ou un nd d o of f A An na al lo og g C Ci ir rc cu ui it t This is an analog ground pin. It should be connected to V SS externally. D Dr ri iv ve er r 26 IREF I C Cu ur rr re en nt t R Re ef fe er re en nc ce e f fo or r B Br ri ig gh ht tn ne es ss s A Ad dj ju us st t me en nt t This pin is segment current reference pin. A resistor should be connected between this pin and V SS . Set the current at 12.5μA maximum. 27 VCOMH O V Vo ol lt ta ag ge e Ou ut tp pu ut t Hi ig gh h L Le ev ve el l f fo or r C C O M S Si ig gn na al l This pin is the input pin for the voltage output high level for COM signals. A capacitor should be connected between this pin and V SS . D DC C/ /D DC C C Co on nv ve er rt te er r 6 VDDB P P Po o we er r S Su up pp pl ly y f fo or r DC C/ / DC C C Co on nv ve er rt te er r C Ci ir rc cu ui it t This is the power supply pin for the internal buffer of the DC/DC voltage converter. It must be connected to external source when the converter is used. It should be connected to V DD when the converter is not used. 4 / 5 2 / 3 C1P / C1N C2P / C2N I P Po os si it ti iv ve e T Te er r mi in na al l o of f t th he e F Fl ly yi in ng g I In nv ve er rt ti in ng g C Ca ap pa ac ci it to or r Ne eg ga at ti iv ve e T Te er r mi in na al l o of f t th he e F Fl ly yi in ng g B Bo oo os st t C Ca ap pa ac ci it to or r The charge-pump capacitors are required between the terminals. They must be floated when the converter is not used. I In nt te er rf fa ac ce e 10 11 12 BS0 BS1 BS2 I C Co o m mu un ni ic ca at ti in ng g P Pr ro ot to oc co ol l S Se el le ec ct t These pins are MCU interface selection input. See the following table: BS0 BS1 BS2 I 2 C 0 1 0 3-wire SPI 1 0 0 4-wire SPI 0 0 0 8-bit 68XX Parallel 0 0 1 8-bit 80XX Parallel 0 1 1 14 RES# I P Po o we er r R Re es se et t f fo or r C Co on nt tr ro ol ll le er r a an nd d Dr ri iv ve er r This pin is reset signal input. When the pin is low, initialization of the chip is executed. Keep this pin pull high during normal operation. 13 CS# I C Ch hi ip p S Se el le ec ct t This pin is the chip select input. The chip is enabled for MCU communication only when CS# is pulled low. 15 D/C# I Da at ta a/ /C Co o m ma an nd d C Co on nt tr ro ol l This pin is Data/Command control pin. When the pin is pulled high, the input at D7~D0 is treated as display data. When the pin is pulled low, the input at D7~D0 will be transferred to the command register. When the pin is pulled high and serial interface mode is selected, the data at SDIN will be interpreted as data. When it is pulled low, the data at SDIN will be transferred to the command register. In I 2 C mode, this pin acts as SA0 for slave address selection. For detail relationship to MCU interface signals, please refer to the Timing Characteristics Diagrams. 17 E/RD# I R Re ea ad d/ / Wr ri it te e E En na ab bl le e o or r R Re ea ad d This pin is MCU interface input. When interfacing to a 68XX-series microprocessor, this pin will be used as the Enable (E) signal. Read/write operation is initiated when this pin is pulled high and the CS# is pulled low. When connecting to an 80XX-microprocessor, this pin receives the Read (RD#) signal. Data read operation is initiated when this pin is pulled low and CS# is pulled low. When serial or I 2 C mode is selected, this pin must be connected to V SS . GoldenMorning Electronic 4 1.5 Pin Definition (Continued) Pin Number Symbol I/O Function I In nt te er rf fa ac ce e ( (C Co on nt ti in nu ue ed d) ) 16 R/W# I R Re ea ad d/ / Wr ri it te e S Se el le ec ct t o or r Wr ri it te e This pin is MCU interface input. When interfacing to a 68XX-series microprocessor, this pin will be used as Read/Write (R/W#) selection input. Pull this pin to “High” for read mode and pull it to “Low” for write mode. When 80XX interface mode is selected, this pin will be the Write (WR#) input. Data write operation is initiated when this pin is pulled low and the CS# is pulled low. When serial or I 2 C mode is selected, this pin must be connected to V SS . 18~25 D0~D7 I/O Ho os st t Da at ta a I In np pu ut t/ / Ou ut tp pu ut t B Bu us s These pins are 8-bit bi-directional data bus to be connected to the microprocessor’s data bus. When serial mode is selected, D1 will be the serial data input SDIN and D0 will be the serial clock input SCLK. When I 2 C mode is selected, D2 & D1 should be tired together and serve as SDA out & SDA in in application and D0 is the serial clock input SCL. Unused pins must be connected to V SS except for D2 in serial mode. R Re es se er rv ve e 7 N.C. - R Re es se er rv ve ed d P Pi in n The N.C. pin between function pins are reserved for compatible and flexible design. 1, 30 N.C. (GND) - R Re es se er rv ve ed d P Pi in n ( (S Su up pp po or rt ti in ng g P Pi in n) ) The supporting pins can reduce the influences from stresses on the function pins. These pins must be connected to external ground as the ESD protection circuit.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值