当前位置:网站首页>[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
边栏推荐
- C # +opencvsharp+wpf learning notes (I)
- Getting started with identityserver4
- Tencent 5g innovation center was established, laying out key directions such as unmanned ports, smart mines and E-sports events
- What is the cloud native mid platform business architecture?
- [STM32 learning] (5) press the key to control the flow light (interrupt Implementation)
- Huawei wireless device security policy configuration command
- Ask you to build a small program server
- JS 84*148=b6a8 how many decimal places can you make both sides equal
- Simple parsing JSON strings with regular expressions
- Why add where exists() to the update select statement? And update with a with statement
猜你喜欢

Foreign lead operation takes one month to collect money, and the sideline still needs it
![CAS principle [concurrent programming]](/img/f0/77e7e1079f70198c601b0f1e25106e.png)
CAS principle [concurrent programming]
![[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

云原生(十二) | Kubernetes篇之Kubernetes基础入门
![[STM32 learning] (22) STM32 realizes 360 degree rotary encoder](/img/8e/fb036296ec3aff5e60acee5018943c.png)
[STM32 learning] (22) STM32 realizes 360 degree rotary encoder
![[don't bother to strengthen learning] video notes (III) 2. SARS learning realizes maze walking](/img/a8/0d3bd3cc2b3e1d43e201e5dfe4b729.png)
[don't bother to strengthen learning] video notes (III) 2. SARS learning realizes maze walking
![[example] v-contextmenu right click menu component](/img/d7/9287b24a6d9ada01a7f258dd34f0f8.jpg)
[example] v-contextmenu right click menu component

Embedded development: Tools - optimizing firmware using DRT

Li Kou 300 longest increasing subsequence dynamic programming

Spark Learning: a form of association in a distributed environment?
随机推荐
A null pointer exception is reported when the wrapper class inserts into the empty field of the database table
It is reported that the prices of some Intel FPGA chip products have increased by up to 20%
Anti shake and throttling
[STM32 learning] (4) press the key to control the flow light
C # +opencvsharp+wpf learning notes (I)
LiteOS_ a - SYS_ The run() function is missing a header file.
[leetcode] 31. Next arrangement
【机器人学习】机构运动学分析与matlab仿真(三维模型+word报告+matlab程序)
IdentityServer4入门
MySQL基础篇(一)-- SQL基础
[don't bother to strengthen learning] video notes (III) 2. SARS learning realizes maze walking
Dorissql syntax Usage Summary
[Luogu p5410] [template] extend KMP (Z function) (string)
获取所有股票历史行情数据
Arduino serial port information reading and output
PHP Basics - PHP magic constants
Hucang integrated e-commerce project (I): introduction to the project background and structure
error: field ‘XXX’ declared as a function
PHP Basics - session control - cookies
Leetcode question brushing series -- 174. Dungeon games