当前位置:网站首页>[STM32 learning] (17) STM32 realizes LCD12864 display serial implementation
[STM32 learning] (17) STM32 realizes LCD12864 display serial implementation
2022-07-24 09:51:00 【Use small materials】
Source download link :(1 Bar message ) STM32 Realization LCD12864 Show - Serial implementation - Telecommunication document resources -CSDN download
About LCD12864 Information , Let me post a little for you first .
Pin definition when working in parallel mode :
PIN1------------------GND Power on -, In general 0V( Depending on the specific LCD model )
PIN2------------------ Power on +, In general 5V( Depending on the specific LCD model )
PIN3------------------ Contrast adjustment end ,VDD and GND Connect both ends of the adjustable resistor , The middle tap is connected to V0
PIN4------------------RS Instructions / Data selection
PIN5------------------R/W Reading and writing choices
PIN6------------------E, Enable signal
PIN7------------------D0, Data bits 0
PIN8------------------D1, Data bits 1
PIN9------------------D2, Data bits 2
PIN10------------------D3, Data bits 3
PIN11------------------D4, Data bits 4
PIN12------------------D5, Data bits 5
PIN13------------------D6, Data bits 6
PIN14------------------D7, Data bits 7
PIN15------------------PSB parallel :PSB=1, Can connect VCC, Serial :PSB=0, In general GND
PIN16------------------NC, Not connected
PIN17------------------~RST, Module reset , Not connected
PIN18------------------NC, Not connected
PIN19------------------LED+, Backlight +, In general 5V( Depending on the specific LCD model )
PIN20------------------LED-, Backlight -, In general GND
Pin definition when working in serial mode :
PIN1------------------GND Power on -, In general 0V( Depending on the specific LCD model )
PIN2------------------ Power on +, In general 5V( Depending on the specific LCD model )
PIN3------------------ Contrast adjustment end ,VDD and GND Connect both ends of the adjustable resistor , The middle tap is connected to V0
PIN4------------------RS(CS), Chip selection
PIN5------------------R/W(SID), data
PIN6------------------E(SCK), pulse
PIN7------------------NC, Not connected
PIN8------------------NC, Not connected
PIN9------------------NC, Not connected
PIN10------------------NC, Not connected
PIN11------------------NC, Not connected
PIN12------------------NC, Not connected
PIN13------------------NC, Not connected
PIN14------------------NC, Not connected
PIN15------------------PSB parallel :PSB=1, Can connect VCC, Serial :PSB=0, In general GND
PIN16------------------NC, Not connected
PIN17------------------~RST, Module reset , Not connected
PIN18------------------NC, Not connected
PIN19------------------LED+, Backlight +, In general 5V( Depending on the specific LCD model )
PIN20------------------LED-, Backlight -, In general GND
12864 LCD parallel port driver is used more , But considering that sometimes SCM or MCU Of IO The serial drive method can be used when the port is limited . Here are 12864 LCD serial sequence diagram , Now let's analyze it according to this figure 12864 Implementation of serial timing , Only by really understanding the sequence diagram can we really understand the principle of serial transmission .

It can be seen from the figure that serial transmission requires CS,SCLK,SID Three signal lines , But because of CS It's high level effective , So you can also CS Long connect high level , Then only two wires are needed OK 了 , Of course, when using 12864 In serial mode ,PSB The pin must be connected to the low level , Reset RST The pin can be suspended , because 12864 There is an internal power on reset circuit .
Because data is transmitted in one byte 8bits In units of , So the function implementation of transferring one byte is posted below
As can be seen from the sequence diagram , To transmit a byte of data completely , It takes three times to transmit , That is, three bytes need to be transmitted , These three bytes are : Command control word , The upper four bits of bytes + Four lower 0 Composed byte , The lower four bits of bytes + Senior four 0 Composed byte .
Command control word 11111RWRS0
RW Represents reading or writing LCD , by 0 Representative writing , by 1 Representative reading .RS Represents write command or data , by 0 For writing commands , by 1 For writing data , rest 6 Bit fixation . So suppose you want to write data to the LCD , You must first send 11111010, Write a command and send 11111000.
The following is the specific implementation of the program , This is the key !
Hardware :
Single chip model :STM32L052K8* In fact, no matter which MCU achieves the same effect
LCD model :LCD12864
connection :
PA0 Pick up RS(CS)
PA1 Pick up R/W(SID)
PA2 Pick up E(SCK)
PA3 Pick up RST You can skip this , Suspended or connected to high level (VCC), The LCD has the function of power on reset , See your own implementation needs to add
lcd12864.c
#include "lcd12864.h"
#include "main.h"
/******************************************
* name :void Write_8bits(uint8_t W_bits)
* function : According to the serial communication protocol of LCD , send data
* Input :W_bits
* Output : nothing
*******************************************/
void Write_8bits(uint8_t W_bits)
{
uint8_t i,Temp_data;
for(i=0; i<8; i++)// Move eight times in total , You can put the 8bits All the data is transmitted
{
Temp_data = W_bits;
Temp_data <<= i;// Move the data left in turn
if((Temp_data&0x80)==0) // Judge whether the corresponding bit is 0
{
HAL_GPIO_WritePin(SID_GPIO_Port,SID_Pin,GPIO_PIN_RESET);
HAL_GPIO_WritePin(CLK_GPIO_Port,CLK_Pin,GPIO_PIN_RESET); //SCLK = 0;// Transmit data on the falling edge of the clock
HAL_GPIO_WritePin(CLK_GPIO_Port,CLK_Pin,GPIO_PIN_SET); // SCLK = 1;// Set high level , Prepare for the next transmission
}
else // The corresponding bit is 1
{
HAL_GPIO_WritePin(SID_GPIO_Port,SID_Pin,GPIO_PIN_SET); //SID = 1;
HAL_GPIO_WritePin(CLK_GPIO_Port,CLK_Pin,GPIO_PIN_RESET); //SCLK = 0;// Transmit data on the falling edge of the clock
HAL_GPIO_WritePin(CLK_GPIO_Port,CLK_Pin,GPIO_PIN_SET); // SCLK = 1;// Set high level , Prepare for the next transmission
}
}
}
/****************************************
* name :void W_1byte(uint8_t RW, uint8_t RS, uint8_t W_data)
* function : Write serial data , according to RW RS Configuration of , Determine whether to transmit commands or data
* Input :uint8_t RW, uint8_t RS, uint8_t W_data
* Output : nothing
******************************************/
void W_1byte(uint8_t RW, uint8_t RS, uint8_t W_data)
{
uint8_t H_data,L_data,S_ID = 0xf8; //11111RWRS0
if(RW == 0)
{
S_ID &=~ 0x04;
}
else //if(RW==1)
{
S_ID |= 0X04;
}
if(RS == 0)
{
S_ID &=~ 0x02;
}
else //if(RS==1)
{
S_ID |= 0X02;
}
// The above command words are combined according to the read-write command and whether to send data or command
H_data = W_data;
H_data &= 0xf0; // Shielding is low 4 A data
L_data = W_data; //xxxx0000 Format
L_data &= 0x0f; // High shielding 4 A data
L_data <<= 4; //xxxx0000 Format
HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_SET); //CS = 1; Can send when
Write_8bits(S_ID); // Send command word S_ID
Write_8bits(H_data); // send out H_data
Write_8bits(L_data); // send out L_data
HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_RESET); //CS = 0; Can send when
}
/*****************************************
* function :lcdinit()
* function : Initialization function
* Input :cmdcode
* Output : nothing
*****************************************/
void lcdinit(void)
{
HAL_Delay(10);
W_1byte(0,0,0x30);// Feature set 8 Bit data , Basic instructions ;
HAL_Delay(10);
//W_1byte(0,0,0x02); // Address homing
//HAL_Delay(10);
//W_1byte(0,0,0x06); // Move the cursor and display right one bit
//HAL_Delay(10);
W_1byte(0,0,0x0c); // Display state ON, The cursor OFF, The irony OFF
HAL_Delay(10);
W_1byte(0,0,0x01); // Clear the display
HAL_Delay(10);
}
/******************************************
* name :void LCD_Wmessage(uint8_t* message,uint8_t address)
* function : towards LCD12864 Write a row of data in ( Because you can't send only one byte of data at a time )
* Input :uint8_t* message,uint8_t address
* Output : nothing
******************************************/
void LCD_Wmessage(uint8_t* message,uint8_t address)
{
W_1byte(0, 0, address);
while(*message>0)// This judgment is crucial , Judge whether your content has been sent
{
W_1byte(0,1,*message); // Kernel or send byte function
message++; // The pointer works well ..
}
}
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
void Write_8bits(uint8_t W_bits);
void W_1byte(uint8_t RW, uint8_t RS, uint8_t W_data);
void lcdinit(void);
void LCD_Wmessage(uint8_t *message,uint8_t address);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();
/* USER CODE BEGIN 2 */
lcdinit();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
LCD_Wmessage(dis3,LINE1);
LCD_Wmessage(dis4,LINE2);
LCD_Wmessage(dis5,LINE3);
LCD_Wmessage(dis6,LINE4);
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}The effect is as follows :

Code download link :(1 Bar message ) STM32 Realization LCD12864 Show - Serial implementation - Telecommunication document resources -CSDN download
边栏推荐
- [don't bother with reinforcement learning] video notes (I) 3. Why use reinforcement learning?
- 07 Jason module
- LiteOS_ a - SYS_ The run() function is missing a header file.
- This article takes you to understand the dynamic memory allocation of C language
- 【笔记】什么是内核/用户空间 从CPU如何运行程序讲起
- Cyclicbarrier and countdownlatch [concurrent programming]
- [don't bother to strengthen learning] video notes (IV) 2. Dqn realizes maze walking
- Openstack network neutron knowledge point "openstack"
- It is reported that the prices of some Intel FPGA chip products have increased by up to 20%
- 缓冲区的概念真的理解么?带你揭开缓冲区的面纱~
猜你喜欢
![[note] what is kernel / user space? Let's start with how the CPU runs the program](/img/b5/0ab4f2841faf3573b4502d2cd09069.png)
[note] what is kernel / user space? Let's start with how the CPU runs the program

Tencent 5g innovation center was established, laying out key directions such as unmanned ports, smart mines and E-sports events

What's the difference between testing / developing programmers' professionalism and salted fish? They don't want to be excellent coders?
![[STM32 learning] (4) press the key to control the flow light](/img/2a/b26860e2c65c0790a60ac207bf52ec.png)
[STM32 learning] (4) press the key to control the flow light

Write a simple memo using localstorage

ASI-20220222-Implicit PendingIntent

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

Lung CT segmentation challenge 2017 dataset download and description
![[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
![[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?
随机推荐
C # +opencvsharp+wpf learning notes (I)
Add SSH key to bitbucket
[leetcode] 31. Next arrangement
Server load and CPU performance tuning
Color recognition of regions of interest in pictures and videos based on OpenCV
Financial digital transformation
Anti shake and throttling
PHP Basics - session control - Session
Arduino serial port information reading and output
Android Version Description security privacy 13
Tencent 5g innovation center was established, laying out key directions such as unmanned ports, smart mines and E-sports events
[don't bother with reinforcement learning] video notes (I) 1. What is reinforcement learning?
Write a simple memo using localstorage
Scala learning: why emphasize immutable objects?
What are the 6% annualized products?
Openstack network neutron knowledge point "openstack"
RxJS Beginner Guide
PHP Basics - PHP super global variables
Basic knowledge of PHP - complete collection of PHP functions
Raspberry Pie: /bin/sh: 1: bison: not found