当前位置:网站首页>[STM32 learning] (18) STM32 realizes LCD12864 display - parallel implementation of 8-bit bus
[STM32 learning] (18) STM32 realizes LCD12864 display - parallel implementation of 8-bit bus
2022-07-24 09:50:00 【Use small materials】
The last blog is to realize serial display , Now let's implement a parallel display ,8 Implementation of bit bus , In fact, the implementation of four bit bus is similar to 1602 almost , There is no need to realize .
Let's stick it first 1284 Some information about . and 1602 And similar to .






Display address :

Specific information can be inquired online , A lot of information .
Hardware :STM32L052K8* This and others STM32 almost , It's just that this single chip microcomputer is IO When writing values, you cannot write two bytes at a time , You can only write one by one , This and F Series of microcontrollers are different , But there are solutions . You can see the following code implementation .
connection :
PA0-PA7 Pick up D0-D7
PB1 Pick up RS
PB2 Pick up RW
PB3 Pick up EN
The code is as follows :
lcd12864.c
#include "lcd12864.h"
#include "stm32l052xx.h"
#include "stm32l0xx_hal_gpio.h"
uint16_t temp;
// Time delay
void delay(uint32_t m)
{
uint32_t i,j;
for(i=0;i<m;i++)
for(j=0;j<10;j++);
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOB, RS_Pin|RW_Pin|EN_Pin, GPIO_PIN_RESET);
/*Configure GPIO pins : PA0 PA1 PA2 PA3
PA4 PA5 PA6 PA7 */
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3
|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pins : RS_Pin RW_Pin EN_Pin */
GPIO_InitStruct.Pin = RS_Pin|RW_Pin|EN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}
//LCD initialization
void LCD_Init(void)
{
LCD_wcmd(0x30);// Feature set : Basic instruction set
HAL_Delay(10);
//LCD_wcmd(0x08);
//HAL_Delay(10);
//LCD_wcmd(0x10);
//HAL_Delay(10);
LCD_wcmd(0x0C);// Show on , Guan cursor
HAL_Delay(10);
LCD_wcmd(0x01);// Clear the display
HAL_Delay(10);
//LCD_wcmd(0x06);
//HAL_Delay(10);
}
// Busy judgment
void CheckBusy(void)
{
uint8_t status;
HAL_GPIO_WritePin(RS_GPIO_Port,RS_Pin,GPIO_PIN_RESET);
HAL_GPIO_WritePin(RW_GPIO_Port,RW_Pin,GPIO_PIN_SET); // Read the data ,RW=1
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7,GPIO_PIN_SET);
do
{
HAL_GPIO_WritePin(EN_GPIO_Port,EN_Pin,GPIO_PIN_SET);
HAL_Delay(5);
status = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_7);// receive BF position , Judge if you are busy
HAL_GPIO_WritePin(EN_GPIO_Port,EN_Pin,GPIO_PIN_RESET);
}while(status & 0x80);
}
//LCD Write orders
void LCD_wcmd(uint8_t cmd)
{
CheckBusy();
HAL_GPIO_WritePin(RS_GPIO_Port,RS_Pin,GPIO_PIN_RESET);
HAL_GPIO_WritePin(RW_GPIO_Port,RW_Pin,GPIO_PIN_RESET); // Read the data ,RW=0
HAL_Delay(5);
temp=(temp&0xff00)|cmd;//temp The lower eight digits of will be cleared cmd Put it in
Write_data(temp);
//GPIO_Write(GPIOA,temp);// adopt GPIO_Write() Function to send data to A port ( That is to say LCD Data port )
HAL_GPIO_WritePin(EN_GPIO_Port,EN_Pin,GPIO_PIN_SET);// Enable bit on
HAL_Delay(10);//10ms It should be able to send
HAL_GPIO_WritePin(EN_GPIO_Port,EN_Pin,GPIO_PIN_RESET);// The enable bit is off
}
//LCD Writing data
void LCD_wdat(uint8_t dat)
{
CheckBusy();
HAL_GPIO_WritePin(RS_GPIO_Port,RS_Pin,GPIO_PIN_SET);
HAL_GPIO_WritePin(RW_GPIO_Port,RW_Pin,GPIO_PIN_RESET);
HAL_Delay(5);
temp=(temp&0xff00)|dat; //temp The lower eight digits of will be cleared dat Put it in
Write_data(temp);
//GPIO_Write(GPIOA,temp);// adopt GPIO_Write() Function to send data to A port ( That is to say LCD Data port )
HAL_GPIO_WritePin(EN_GPIO_Port,EN_Pin,GPIO_PIN_SET);// Enable bit on
HAL_Delay(10);//10ms It should be able to send
HAL_GPIO_WritePin(EN_GPIO_Port,EN_Pin,GPIO_PIN_RESET);// The enable bit is off
}
// towards LCD12864 Write a row of data in ( Because you can't send only one byte of data at a time )
void LCD_Wmessage(uint8_t* message,uint8_t address)
{
LCD_wcmd(address);// Location to display , You want the content to appear in LCD Which line? , Send the starting address of the line by writing a command , Amazing , Is there any
while(*message>0)// This judgment is crucial , Judge whether your content has been sent
{
LCD_wdat(*message); // Kernel or send byte function
message++; // The pointer works well ..
}
}
void Write_data(uint16_t temp)
{
/* high 8 Bit value judgment */
if((temp&0X0080) == 0X0080) // **** **** 1000 0000
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_SET);
}
else
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_RESET);
}
/* high 7 Bit value judgment */
if((temp&0X0040) == 0X0040) // **** **** 1000 0000
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_6,GPIO_PIN_SET);
}
else
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_6,GPIO_PIN_RESET);
}
/* high 6 Bit value judgment */
if((temp&0X0020) == 0X0020) // **** **** 1000 0000
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET);
}
else
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET);
}
/* high 5 Bit value judgment */
if((temp&0X0010) == 0X0010) // **** **** 1000 0000
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4,GPIO_PIN_SET);
}
else
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_4,GPIO_PIN_RESET);
}
/* high 4 Bit value judgment */
if((temp&0X0008) == 0X0008) // **** **** 1000 0000
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_SET);
}
else
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_3,GPIO_PIN_RESET);
}
/* high 3 Bit value judgment */
if((temp&0X0004) == 0X0004) // **** **** 1000 0000
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2,GPIO_PIN_SET);
}
else
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_2,GPIO_PIN_RESET);
}
/* high 2 Bit value judgment */
if((temp&0X0002) == 0X0002) // **** **** 1000 0000
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1,GPIO_PIN_SET);
}
else
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1,GPIO_PIN_RESET);
}
/* high 1 Bit value judgment */
if((temp&0X0001) == 0X0001) // **** **** 1000 0000
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_0,GPIO_PIN_SET);
}
else
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_0,GPIO_PIN_RESET);
}
}
lcd12864.h
#include "main.h"
#define LINE1 0x80 // The starting address of the first line , The same below
#define LINE2 0x90
#define LINE3 0x88
#define LINE4 0x98
#define RS_Pin GPIO_PIN_1
#define RS_GPIO_Port GPIOB
#define RW_Pin GPIO_PIN_3
#define RW_GPIO_Port GPIOB
#define EN_Pin GPIO_PIN_5
#define EN_GPIO_Port GPIOB
void MX_GPIO_Init(void);
void LCD_Init(void);
void CheckBusy(void);
void LCD_wcmd(uint8_t cmd);
void LCD_wdat(uint8_t dat);
void LCD_Wmessage(uint8_t* message,uint8_t address);
void Write_data(uint16_t temp);main.c
int main(void)
{
/* USER CODE BEGIN 1 */
uint8_t dis3[]={" abed, I see a silver light ,"};
uint8_t dis4[]={" The frost on the ground ,"};
uint8_t dis5[]={" look at the bright moon ,"};
uint8_t dis6[]={" Bow your head and think of your hometown ."};
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
LCD_Init();
/* USER CODE BEGIN 2 */
//LCD_Wmessage(dis3,LINE1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
LCD_Wmessage(dis3,LINE1);
LCD_Wmessage(dis4,LINE2);
LCD_Wmessage(dis5,LINE3);
LCD_Wmessage(dis6,LINE4);
}
/* USER CODE END 3 */
}
The display effect is as follows :

边栏推荐
- Arduino drive Lora module master node
- Learning transformer: overall architecture and Implementation
- Embedded development: Tools - optimizing firmware using DRT
- JS, the return statement used in the for loop should be placed in the function to terminate the loop, similar to the invalid return problem in break & foreach
- Foreign lead operation takes one month to collect money, and the sideline still needs it
- Scala learning: why emphasize immutable objects?
- Raspberry Pie: serial port login does not display print information
- The most complete solution for distributed transactions
- Where is the bitbucket clone address
- PHP Basics - session control - cookies
猜你喜欢
![[don't bother to strengthen learning] video notes (IV) 1. What is dqn?](/img/74/51219a19595f93e7a85449f54d354d.png)
[don't bother to strengthen learning] video notes (IV) 1. What is dqn?

It is reported that the prices of some Intel FPGA chip products have increased by up to 20%

【笔记】什么是内核/用户空间 从CPU如何运行程序讲起
![[200 opencv routines] 236. Principal component analysis of feature extraction (openCV)](/img/31/57217a67533d8d37bf86d507996ed7.png)
[200 opencv routines] 236. Principal component analysis of feature extraction (openCV)
![[don't bother to strengthen learning] video notes (II) 2. Write a small example of Q learning](/img/b1/d5c869bc68ba273be2030202f94a55.png)
[don't bother to strengthen learning] video notes (II) 2. Write a small example of Q learning

Little dolphin "transformed" into a new intelligent scheduling engine, which can be explained in simple terms in the practical development and application of DDS
Gin framework uses session and redis to realize distributed session & Gorm operation mysql

Server load and CPU performance tuning
![[don't bother to strengthen learning] video notes (II) 1. What is Q-learning?](/img/4f/809adc96e30fad03a113acc3df4b61.png)
[don't bother to strengthen learning] video notes (II) 1. What is Q-learning?
![[C language] implementation of three versions of address book small project (including source code)](/img/3b/926001332ec05378de4c35dc28ed55.png)
[C language] implementation of three versions of address book small project (including source code)
随机推荐
[don't bother to strengthen learning] video notes (III) 2. SARS learning realizes maze walking
Anti shake and throttling
Dorissql syntax Usage Summary
Raspberry Pie: the serial port has been unable to read the information sent by the upper computer
Re6: reading paper licin: a heterogeneous graph based approach for automatic legal stat identification fro
How to improve office efficiency through online collaborative documents
Leetcode question brushing series -- 174. Dungeon games
NVIDIA set persistent mode
Cyclicbarrier and countdownlatch [concurrent programming]
[don't bother to strengthen learning] video notes (IV) 2. Dqn realizes maze walking
配置系统环境变量的时候误删了Path怎么办?
Countdownlatch and join [concurrent programming]
Es search summary
Spark Learning: using RDD API to implement inverted index
Use of jstack "JVM common commands"
Understanding of magnetic parameters in Hall sensors
《动手学深度学习》(七) -- 边界框和锚框
We were tossed all night by a Kong performance bug
With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
Openstack network neutron knowledge point "openstack"