当前位置:网站首页>STM32 series (HAL Library) - f103c8t6 hardware SPI illuminates OLED screen with word library
STM32 series (HAL Library) - f103c8t6 hardware SPI illuminates OLED screen with word library
2022-06-22 17:20:00 【Embedded maker workshop】
1. Software preparation
(1) Programming platform :Keil5
(2)CubeMX
(3) Program : Click to download
2. Hardware preparation
(1)1.3 Inch band font OLED

(2)F1 The board of , This example uses classic F103C8T6

(3)ST-link Downloader

(4) There are several DuPont lines

3.CubeMX To configure
(1) Chip selection

(2) To configure RCC、SYS、 Clock tree

To configure RCC

To configure SYS

Configure clock tree
(3) To configure IIC

(4) To configure GPIO

(5) Set the path 、 Generate code Engineering
5、Keil5 Code
(1) Add files _____( Just follow the picture )



Add project file


Add the header file path

(2) Full compile compile once
The following error will be reported , Double click the error to jump to oled.h

(3) modify oled.h

#ifndef __OLED_H
#define __OLED_H
#include "main.h"
#define u8 uint8_t
#define u16 uint16_t
#define u32 uint32_t
#define OLED_RES_Clr() HAL_GPIO_WritePin(OLED_RES_GPIO_Port, OLED_RES_Pin, GPIO_PIN_RESET)//RES
#define OLED_RES_Set() HAL_GPIO_WritePin(OLED_RES_GPIO_Port, OLED_RES_Pin, GPIO_PIN_SET)
#define OLED_DC_Clr() HAL_GPIO_WritePin(OLED_DC_GPIO_Port, OLED_DC_Pin, GPIO_PIN_RESET)//DC
#define OLED_DC_Set() HAL_GPIO_WritePin(OLED_DC_GPIO_Port, OLED_DC_Pin, GPIO_PIN_SET)
#define OLED_CS_Clr() HAL_GPIO_WritePin(OLED_CS_GPIO_Port, OLED_CS_Pin, GPIO_PIN_RESET)//CS
#define OLED_CS_Set() HAL_GPIO_WritePin(OLED_CS_GPIO_Port, OLED_CS_Pin, GPIO_PIN_SET)
#define ZK_CS_Clr() HAL_GPIO_WritePin(ZK_CS_GPIO_Port,ZK_CS_Pin, GPIO_PIN_RESET)//CS2
#define ZK_CS_Set() HAL_GPIO_WritePin(ZK_CS_GPIO_Port,ZK_CS_Pin, GPIO_PIN_SET)
(4) modify oled.c
①①① Modify header file

#include "oled.h"
#include "stdlib.h"
//#include "delay.h
#include "spi.h"②②② Modify the script function

// towards SSD1306 Write a byte .
//mode: data / Command flag 0, To express an order ;1, According to the data ;
void OLED_WR_Byte(u8 dat,u8 cmd)
{
if(cmd)
OLED_DC_Set();
else
OLED_DC_Clr();
OLED_CS_Clr();
// for(i=0;i<8;i++)
// {
// OLED_SCLK_Clr();
// if(dat&0x80)
// OLED_MOSI_Set();
// else
// OLED_MOSI_Clr();
// OLED_SCLK_Set();
// dat<<=1;
// }
HAL_SPI_Transmit(&hspi1, &dat, 1, 0X100);
OLED_CS_Set();
OLED_DC_Set();
}③③③ Modify initialization function

HAL_Delay(10);(5) modify zk.c
①①① Modify the script function

// Send instructions to the crystal link word library IC
void Send_Command_to_ROM(u8 dat)
{
// u8 i;
// for(i=0;i<8;i++)
// {
// ZK_SCLK_Clr();
// if(dat&0x80)
// {
// ZK_MOSI_Set();
// }
// else
// {
// ZK_MOSI_Clr();
// }
// dat<<=1;
// ZK_SCLK_Set();
// }
HAL_SPI_Transmit(&hspi1, &dat, 1, 0X100);
}②②② Modify the byte reading function

// From jinglianxun word library IC Take Chinese characters or character data (1 Bytes )
u8 Get_data_from_ROM(void)
{
u8 read=0;
// for(i=0;i<8;i++)
// {
// ZK_SCLK_Clr();
// read<<=1;
// if(ZK_MISO())
// {
// read++;
// }
// ZK_SCLK_Set();
// }
HAL_SPI_Receive(&hspi1, &read, 1, 0X100);
return read;
}(6)main.c
① Add header file
#include "oled.h"
#include "bmp.h"②whlie Add... Before loop :
OLED_Init();
OLED_ColorTurn(0);//0 Normal display ,1 Reverse color display
OLED_DisplayTurn(1);//0 Normal display 1 The screen flips to show
OLED_Clear();③while Add :
OLED_Display_128x64(bmp1);
HAL_Delay(500);
OLED_Display_GB2312_string(0,0,"12864, With Chinese character library "); /* In the 1 page , The first 1 Column , A string of displays 16x16 Dot matrix Chinese character or 8x16 Of ASCII word */
OLED_Display_GB2312_string(0,2,"16X16 Simplified Chinese character library ,"); /* A string of displays 16x16 Dot matrix Chinese character or 8x16 Of ASCII word . The following are the same */
OLED_Display_GB2312_string(0,4," or 8X16 Lattice ASCII,");
OLED_Display_GB2312_string(0,6," or 5X7 Lattice ASCII code ");
HAL_Delay(500);
OLED_Clear();
OLED_Display_GB2312_string(24,0," Zhongjingyuan electronics ");
OLED_Display_GB2312_string(0,2," Main production OLED modular ");
OLED_Display_GB2312_string(0,4," Customer first and sincere service ");
OLED_Display_GB2312_string(0,6," Honesty and quality first !");
HAL_Delay(500);
OLED_Clear();
OLED_Display_GB2312_string(0,0,"GB2312 Simplified character library and ");
OLED_Display_GB2312_string(0,2," It has the function of pattern , But since the ");
OLED_Display_GB2312_string(0,4," Make up large characters or images ");
OLED_Display_GB2312_string(0,6," rare word , for example :");
OLED_Display_16x16(97,6,jiong1); /* In the 7 page , The first 81 The column shows a single self-made rare Chinese character “ Embarrassed ”*/
OLED_Display_16x16(113,6,lei1);
HAL_Delay(500);
OLED_Clear();
OLED_Display_GB2312_string(0,0,"<[email protected]#$%^&*()_-+]/"); /* In the 1 page , The first 1 Column , A string of displays 16x16 Dot matrix Chinese character or 8*16 Of ASCII word */
OLED_Display_string_5x7(0,2,"<[email protected]#$%^&*()_-+]/;.,?[");/* In the 3 page , The first 1 Column , A string of displays 5x7 Lattice ASCII word */
OLED_Display_string_5x7(0,3,"XY electronics Co., ");/* A string of displays 5x7 Lattice ASCII word */
OLED_Display_string_5x7(0,4,"Ltd. established at ");/* A string of displays 5x7 Lattice ASCII word */
OLED_Display_string_5x7(0,5,"year 2010.Focus OLED ");/* A string of displays 5x7 Lattice ASCII word */
OLED_Display_string_5x7(0,6,"Mobile:13265585975");/* A string of displays 5x7 Lattice ASCII word */
OLED_Display_string_5x7(0,7,"Tel:0755-32910715");/* A string of displays 5x7 Lattice ASCII word */
HAL_Delay(500);
OLED_Clear();
OLED_Display_GB2312_string(0,0," Ah, ah, ah, ah, AI "); /* In the 1 page , The first 1 Column , A string of displays 16x16 Dot matrix Chinese character or 8x16 Of ASCII word */
OLED_Display_GB2312_string(0,2," Cancer is high and low, which hinders love "); /* A string of displays 16x16 Dot matrix Chinese character or 8x16 Of ASCII word . The following are the same */
OLED_Display_GB2312_string(0,4," Ammonia An'an presses the case of dark shore amine ");
OLED_Display_GB2312_string(0,6," I am so proud of you ");
HAL_Delay(500);
OLED_Clear();
OLED_Display_GB2312_string(0,0," The servant men and women are all distinguished ");
OLED_Display_GB2312_string(0,2," The elk and the unicorn fight fiercely, the musk and the dais detract from the sun ");
OLED_Display_GB2312_string(0,4," The crafty hair is dark ");
OLED_Display_GB2312_string(0,6," The mouse flies ");
HAL_Delay(500);
OLED_Clear();6. effect

No refresh bar is visible to the naked eye , This effect can be achieved by mobile phone shooting
Download the source code of this routine : Click the jump
边栏推荐
- QT notes qmap user defined key
- Docker 之MySQL 重启,提示Error response from daemon: driver failed programming external connectivity on **
- 启牛学堂给的中信建投证券账户是不是真的?开户安全吗
- 你管这破玩意儿叫高可用?
- JMeter use case
- 试用了多款报表工具,终于找到了基于.Net 6开发的一个了
- [step 1 of advanced automated testing] 1 minute to introduce you to automated testing
- Read Apache shardingsphere
- STM32通过DMA进行ADC采集(HAL库)
- Qt筆記-QMap自定義鍵(key)
猜你喜欢

clickhouse 21.x 集群四分片一副本部署

Tried several report tools, and finally found a report based on Net 6

来厦门了!线上交流限额免费报名中

关于#数据库#的问题,如何解决?
Database mysql master-slave scheme

Vhedt business development framework

Recommend 7 super easy-to-use terminal tools - ssh+ftp

Xftp 7(FTP/SFTP客户端) V7.0.0107 官方中文免费正式版(附文件+安装教程)

Quartus Prime 18.0软件安装包和安装教程

Read Apache shardingsphere
随机推荐
【招聘】[北京中关村/远程][TensorBase][开源数据仓库]等一群人,做一件事
Thoughts on joint primary key
Vs2017 solution to not displaying qstring value in debugging status
linux系统维护篇:mysql8.0.13源码下载及安装之“傻瓜式”操作步骤(linux-centos6.8)亲测可用系列
client-go gin的简单整合十-Update
The world's "first" IEEE privacy computing "connectivity" international standard led by insight technology was officially launched
You call this crap high availability?
Windows8.1 64 installed by mysql5.7.27
来厦门了!线上交流限额免费报名中
Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + commercial realization
WPF effect chapter 190: playing listbox again
be based on. NETCORE development blog project starblog - (12) razor page dynamic compilation
. Net release and support plan introduction
[recruitment] [Beijing Zhongguancun / remote] [tensorbase][open source data warehouse] and other people do one thing
A classmate asked what framework PHP should learn?
新手必会的静态站点生成器——Gridsome
mysql5.7.27安装之windows8.1 64
Qt Notes - qmap Custom key
数据库mysql 主从方案
Summary of spark common operators