分布式机器 双重检验锁 ipv4 phpmyadmin pagination controller pyqt ios4 GMU 管理后台ui ddos压力测试 jq选择子元素 jq延时 bootstrap中文api文档 map删除指定元素 java获取字符串 matlab网页版 idea批量替换快捷键 网页设计公司 python迭代 python基础教程 python链接mysql数据库 python查找指定字符 python搭建网站 java类型 java替换字符 java将数据写入文件 java中接口的定义 corelpainter 俄罗斯方块c语言代码 免费的视频剪辑 剑三醉猿 7个人 拼多多商家下载 华为手机屏保怎么设置 ajax获取数据 美图秀秀pc版下载 firework软件 cad怎么拉伸 jdk8安装教程
当前位置: 首页 > 学习教程  > 编程语言

嵌入式实验三——OLED的SPI接口数据显示实验

2020/12/28 19:04:45 文章标签:

文章目录实验要求一、资料与简介二、显示中文与数字三、显示AHT20的温度和湿度四、滑动显示长字符总结初学者课程实验,慎重参考 实验要求 1、显示自己的学号和姓名; 2、显示AHT20的温度和湿度; 3、上下或左右的滑动显示长字符,比…

文章目录

  • 实验要求
  • 一、资料与简介
  • 二、显示中文与数字
  • 三、显示AHT20的温度和湿度
  • 四、滑动显示长字符
  • 总结

初学者课程实验,慎重参考

实验要求

1、显示自己的学号和姓名;
2、显示AHT20的温度和湿度;
3、上下或左右的滑动显示长字符,比如“Hello,欢迎来到重庆交通大学物联网205实训室!”

一、资料与简介

1.字模提取
链接:https://pan.baidu.com/s/13dP5HOBougn35s1-MmofmQ
提取码:f7kp
复制这段内容后打开百度网盘手机App,操作更方便哦
2.SPI的定义
SPI(Serial Peripheral Interface)就是串行外围设备接口。
SPI,是一种高速的,全双工,同步的通信总线,并且在芯片的管脚上只占用四根线,节约了芯片的管脚。SPI 是一个环形总线结构,由 ss(cs)、sck、sdi、sdo 构成,时序主要是在 sck 的控制下,两个双向移位寄存器进行数据交换。
上升沿发送、下降沿接收、高位先发送。
上升沿到来的时候,sdo 上的电平将被发送到从设备的寄存器中。
下降沿到来的时候,sdi 上的电平将被接收到主设备的寄存器中。
3.SPI的连接方式
在这里插入图片描述

SS( Slave Select):从设备选择信号线,常称为片选信号线。
SCK (Serial Clock):时钟信号线,用于通讯数据同步。
MOSI (Master Output, Slave Input):主设备输出/从设备输入引脚。
MISO(Master Input,,Slave Output):主设备输入/从设备输出引脚。
4.SPI的通讯过程
在这里插入图片描述

MOSI 与 MISO 的信号只在 NSS 为低电平的时候才有效,在 SCK 的每个时钟周期 MOSI 和 MISO 传输一位数据。
5.0.96寸OLED显示屏相关介绍
http://www.lcdwiki.com/zh/0.96inch_SPI_OLED_Module
6.资料包
0.96寸SPI_OLED模块配套资料包

二、显示中文与数字

1.打开资料包,选择与自己平台相同的实例,打开Demo的工程
2.学习后修改代码
要显示中文与数字其实就是调用GUI_ShowString()和GUI_ShowCHinese()两个函数,并将显示内容进行更改,根据注释我们在main.c的主函数和gui.c的字模16x16存放的函数进行修改
(1)main.c

#include "delay.h"
#include "sys.h"
#include "oled.h"
#include "gui.h"
#include "test.h"
int main(void)
{	
	delay_init();	    	       //延时函数初始化	  
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);	 //设置NVIc中断分组2:2位抢占优先级,2位响应优先级
	
	OLED_Init();			         //初始化OLED
	OLED_Clear(0);             //清屏,全黑
	GUI_ShowString(20,0,"631807030426",8,1);
	GUI_ShowCHinese(16,20,16,"大汤圆",1);
}

(2)gui.c>>oledfont.h>>const typFNT_GB16 cfont16[] (字模用前面的字模提取软件获取)

const typFNT_GB16 cfont16[] = 
{
"大",0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00,
0x02,0x80,0x02,0x80,0x04,0x40,0x04,0x40,0x08,0x20,0x10,0x10,0x20,0x08,0xC0,0x06,/*"大",0*/
"汤",0x00,0x00,0x23,0xF0,0x10,0x20,0x10,0x40,0x80,0x80,0x41,0x00,0x43,0xFC,0x11,0x24,
0x11,0x24,0x21,0x24,0xE2,0x24,0x22,0x44,0x24,0x44,0x28,0x84,0x21,0x28,0x02,0x10,/*"汤",1*/
"圆",0x00,0x00,0x7F,0xFC,0x40,0x04,0x4F,0xE4,0x48,0x24,0x4F,0xE4,0x40,0x04,0x5F,0xF4,
0x50,0x14,0x51,0x14,0x51,0x14,0x52,0x94,0x44,0x44,0x48,0x24,0x7F,0xFC,0x40,0x04,/*"圆",2*/

};

3.连接烧录
用USB连线连接电脑和开发板(我小组用的指南者),按下面连接显示屏和开发板
在这里插入图片描述
编译连接生成.hex文件烧录
在这里插入图片描述
显示成功
在这里插入图片描述

三、显示AHT20的温度和湿度

1.移植
将之前湿温度采集实验工程中的myiic.c和hemtem.c文件移植到我们这个oled工程中
在这里插入图片描述
2.修改代码
(1)main.c

#include "delay.h"
#include "sys.h"
#include "oled.h"
#include "gui.h"
#include "test.h"
#include "temhum.h"
#include "myiic.h"
int main(void)
{	u32 CT_data[2]={0};
    volatile float  hum=0,tem=0;     

    temphum_init();    
	delay_init();	    	     
	NVIC_Configuration(); 	 
	OLED_Init();			         
	OLED_Clear(0);            
	while(1) 
	{		
	    GUI_ShowCHinese(16,20,16,"大汤圆",1);
		GUI_ShowCHinese(16,36,16,"湿度",1);
		GUI_ShowCHinese(16,54,16,"温度",1);
		delay_ms(1500);
	  OLED_Clear(0);
		AHT20_Read_CTdata(CT_data);    

        hum = CT_data[0]*100*10/1024/1024;  
        tem = CT_data[1]*200*10/1024/1024-500;
	      GUI_ShowNum(50,36,hum/10,10,8,1);
		  GUI_ShowNum(50,54,tem/10,10,8,1);
     
		delay_ms(3000);
	}

(2)字模

const typFNT_GB16 cfont16[] = 
{
"大",0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00,
0x02,0x80,0x02,0x80,0x04,0x40,0x04,0x40,0x08,0x20,0x10,0x10,0x20,0x08,0xC0,0x06,/*"大",0*/

"汤",0x00,0x00,0x23,0xF0,0x10,0x20,0x10,0x40,0x80,0x80,0x41,0x00,0x43,0xFC,0x11,0x24,
0x11,0x24,0x21,0x24,0xE2,0x24,0x22,0x44,0x24,0x44,0x28,0x84,0x21,0x28,0x02,0x10,/*"汤",1*/

"圆",0x00,0x00,0x7F,0xFC,0x40,0x04,0x4F,0xE4,0x48,0x24,0x4F,0xE4,0x40,0x04,0x5F,0xF4,
0x50,0x14,0x51,0x14,0x51,0x14,0x52,0x94,0x44,0x44,0x48,0x24,0x7F,0xFC,0x40,0x04,/*"圆",2*/

"温",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,/*"温",3*/

"度",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,/*"度",4*/

"湿",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,/*"湿",5*/

"度",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,/*"度",6*/
};

3.编译烧录
软件有问题,暂时先放着

四、滑动显示长字符

1.修改代码
(1)main.c

#include "delay.h"
#include "sys.h"
#include "oled.h"
#include "gui.h"
#include "test.h"
void roll(void);
int main(void)
{	
	delay_init();	    	       
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);	 //
	OLED_Init();			        
	OLED_Clear(0);        
	while(1) 
	{	
			GUI_ShowCHinese(20,25,16,"露陷的黑芝麻汤圆",1);
			delay_ms(50);
		  roll();
	}
}
	

(2)oled.c添加函数void roll(void)

void roll(void)
{
        OLED_WR_Byte(0x2e,OLED_CMD);       
        OLED_WR_Byte(0x29,OLED_CMD);       
        OLED_WR_Byte(0x00,OLED_CMD);       
        OLED_WR_Byte(0x00,OLED_CMD);        
        OLED_WR_Byte(0x07,OLED_CMD);        
        OLED_WR_Byte(0x07,OLED_CMD);        
        OLED_WR_Byte(0x01,OLED_CMD);       
        OLED_WR_Byte(0x2F,OLED_CMD); 
}      

(3)字模

const typFNT_GB16 cfont16[] = 
{
"大",0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x01,0x00,0x01,0x00,
0x02,0x80,0x02,0x80,0x04,0x40,0x04,0x40,0x08,0x20,0x10,0x10,0x20,0x08,0xC0,0x06,/*"大",0*/

"汤",0x00,0x00,0x23,0xF0,0x10,0x20,0x10,0x40,0x80,0x80,0x41,0x00,0x43,0xFC,0x11,0x24,
0x11,0x24,0x21,0x24,0xE2,0x24,0x22,0x44,0x24,0x44,0x28,0x84,0x21,0x28,0x02,0x10,/*"汤",1*/

"圆",0x00,0x00,0x7F,0xFC,0x40,0x04,0x4F,0xE4,0x48,0x24,0x4F,0xE4,0x40,0x04,0x5F,0xF4,
0x50,0x14,0x51,0x14,0x51,0x14,0x52,0x94,0x44,0x44,0x48,0x24,0x7F,0xFC,0x40,0x04,/*"圆",2*/

"温",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,/*"温",3*/

"度",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,/*"度",4*/

"湿",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,/*"湿",5*/

"露",0x3F,0xF8,0x01,0x00,0x7F,0xFE,0x41,0x02,0x9D,0x74,0x01,0x00,0x1D,0x70,0x00,0x40,
0x7C,0xF8,0x45,0x48,0x7C,0x30,0x11,0xCE,0x5C,0x00,0x50,0xF8,0x5C,0x88,0xE0,0xF8,/*"露",6*/

"陷",0x00,0x80,0x78,0x80,0x48,0xF8,0x51,0x08,0x52,0x10,0x64,0x00,0x50,0x40,0x4B,0x9C,
0x4A,0x04,0x4A,0x04,0x6B,0x9C,0x52,0x04,0x42,0x04,0x42,0x04,0x43,0xFC,0x42,0x04,/*"陷",7*/

"的",0x10,0x40,0x10,0x40,0x20,0x40,0x7E,0x7C,0x42,0x84,0x42,0x84,0x43,0x04,0x42,0x44,
0x7E,0x24,0x42,0x24,0x42,0x04,0x42,0x04,0x42,0x04,0x7E,0x04,0x42,0x28,0x00,0x10,/*"的",8*/

"黑",0x00,0x00,0x3F,0xF8,0x21,0x08,0x29,0x28,0x25,0x48,0x3F,0xF8,0x01,0x00,0x01,0x00,
0x3F,0xF8,0x01,0x00,0x01,0x00,0xFF,0xFE,0x00,0x00,0x48,0x88,0x44,0x44,0x84,0x44,/*"黑",9*/

"芝",0x08,0x20,0x08,0x20,0xFF,0xFE,0x08,0x20,0x0A,0x20,0x01,0x00,0x01,0x00,0x7F,0xF8,
0x00,0x30,0x00,0xC0,0x03,0x00,0x0C,0x00,0x30,0x00,0x48,0x00,0x87,0xFE,0x00,0x00,/*"芝",10*/

"麻",0x01,0x00,0x00,0x80,0x3F,0xFE,0x22,0x10,0x22,0x10,0x22,0x10,0x3F,0xBE,0x22,0x10,
0x26,0x10,0x27,0x38,0x2A,0xB4,0x2A,0x54,0x52,0x92,0x42,0x10,0x82,0x10,0x02,0x10,/*"麻",11*/

};

2.编译烧录
在这里插入图片描述

总结

这次实验通过实物显示屏显示出了数据,感觉特别有成就感,还和上一次实验联动一下,移植过程中出现了很多问题,但是多试试重新打开就可以了,果然遇事不决就重启。冲!


本文链接: http://www.dtmao.cc/news_show_550142.shtml

附件下载

相关教程

    暂无相关的数据...

共有条评论 网友评论

验证码: 看不清楚?