当前位置:网站首页>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 )

1

 

2

 

3

  Add project file

4
5

  Add the header file path

6

(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  

原网站

版权声明
本文为[Embedded maker workshop]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221540160461.html