Table of Contents
1. Module introduction
Follow the WeChat public account – Star Aid Studio and send keywords (LCD12864)
2. Connection and driver code – serial
LCD.c
LCD.h
main.c
3. Reference
1. Module Introduction
The LCD12864 display module is a common liquid crystal display module with a size of 128×64 pixels. It uses LCD technology and can display text, graphics and images.
LCD12864 display module usually consists of LCD screen, driver circuit and backlight. An LCD screen consists of a large number of liquid crystal pixels, each of which can be turned on or off to form text, graphics and images. The drive circuit is responsible for controlling the switching state of each pixel and controlling the content displayed on the screen by inputting a trigger signal. The backlight provides backlight illumination so that the displayed content can be clearly seen in dark environments.
The LCD12864 display module has the following features:
- High resolution: 128×64 pixel display area, can display more content.
- Versatility: Can display text, graphics and images, suitable for different application scenarios.
- Easy to control: Parallel or serial interfaces are usually used to communicate with microcontrollers or other devices to control display content.
- Low power consumption: LCD display technology has relatively low power consumption and is suitable for battery-powered devices.
- High reliability: LCD modules have a long service life and stability, and are suitable for long-term running applications.
- Good display effect: With high contrast and clarity, the display content is clearly visible.
LCD12864 display module is widely used in industrial control, instrumentation, electronic equipment and other fields, and is often used to display real-time data, system status, menus and other information.
Follow the WeChat public account–Xingzhiyuan Studio sends keywords (LCD12864)
?
2. Connection and driver code — Serial
LCD12864 is a serial interface based LCD display with a resolution of 128×64 pixels. The following is a brief description of its wiring and driver code.
1. Connection
1. VCC (power supply positive) connected to +5V
2. GND (power supply negative) connected to ground
3. RS (data bit latch) is connected to the digital port of Arduino (such as D2)
4. RW (read-write control) is connected to the digital port of Arduino (such as D3)
5. EN (enable control) is connected to the digital port of Arduino (such as D4)
6. Connect D0-D7 (data lines) to the digital port of Arduino (such as D5-D12)
7. Connect the clock signal (CLK) to the Arduino
The picture below is STM32f103F103C8T6
LCD.c
The LCD driver code is as follows
#include "lcd.H" #include "delay.h" /*! * @brief GPIO_init * @since v1.0 * @param None */ void lcd_GPIO_init() { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); // Enable PB and PE port clock GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; // LED0-->PB.5 port configuration GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // Push-pull output GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // IO port speed is 50MHz GPIO_Init(GPIOB, & amp;GPIO_InitStructure); // Initialize GPIOB.5 according to the set parameters // GPIO_SetBits(GPIOB, GPIO_Pin_5); // PB.5 output high SID = 1; SCLK = 1; } /* Character display RAM address 4 rows and 8 columns */ u8 LCD_addr[4][8] = { {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87}, // first line {0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97}, // second line {0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F}, // Third line {0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F} // Fourth line }; /*! * @brief LCD serial sends one byte * @since v1.0 * @param byte write byte * @author Z Xiaoxuan */ void SendByte(u8 byte) { u8i; for (i = 0; i < 8; i + + ) { if ((byte << i) & amp; 0x80) // 0x80(1000 0000) will only keep the highest bit { SID = 1; // The pin outputs high level, which means sending 1 } else { SID = 0; // The pin outputs low level, which means sending 0 } \t\t/*or SID = (Dbyte << i) & amp; 0x80; The above is for ease of understanding */ SCLK = 0; // Set clock line low to allow SID to change delay_us(5); // Delay to write data SCLK = 1; // Pull up the clock and let the slave read the SID } } /*! * @brief LCD write command * @since v1.0 * @param Cmd The command to write * @author Z Xiaoxuan */ void Lcd_WriteCmd(u8 Cmd) { delay_ms(1); // Since we have not written the LCD busy detection, we directly delay it by 1ms so that the interval between each writing of data or instructions is greater than 1ms, so there is no need to write the busy status detection. SendByte(WRITE_CMD); // 11111,RW(0),RS(0),0 SendByte(0xf0 & amp; Cmd); //high four digits SendByte(Cmd << 4); //lower four bits (execute first<<) } /*! * @brief LCD write data * @since v1.0 * @param Dat The data to be written * @author Z Xiaoxuan */ void Lcd_WriteData(u8 Dat) { delay_ms(1); SendByte(WRITE_DAT); // 11111,RW(0),RS(1),0 SendByte(0xf0 & amp; Dat); //high four digits SendByte(Dat << 4); //lower four bits (execute first<<) } /*! * @brief LCD initialization * @since v1.0 * @param None * @author Z Xiaoxuan */ void Lcd_Init(void) { delay_ms(50); //Waiting for LCD self-test (delay>40ms) Lcd_WriteCmd(0x30); // Function setting: select basic instruction set delay_ms(1); // delay>100us Lcd_WriteCmd(0x30); // Function setting: select 8bit data stream delay_ms(1); // delay>37us Lcd_WriteCmd(0x0c); // Turn on display delay_ms(1); // delay>100us Lcd_WriteCmd(0x01); //Clear the display and set the address pointer to 00H delay_ms(30); // delay>10ms Lcd_WriteCmd(0x06); // Enter the set point, initialization completed } /*! * @brief Display characters or Chinese characters * @since v1.0 * @param x: row(0~3) * @param y: line(0~7) * @param str: Characters or Chinese characters to be displayed * @author Z Xiaoxuan */ void LCD_Display_Words(uint8_t x, uint8_t y, uint8_t *str) { Lcd_WriteCmd(LCD_addr[x][y]); //Write initial cursor position while (*str > 0) { Lcd_WriteData(*str); //Write data str + + ; } } /*! * @brief show picture * @since v1.0 * @param *pic picture address * @author */ void LCD_Display_Picture(uint8_t *img) { uint8_t x, y, i; Lcd_WriteCmd(0x34); // Switch to extended instructions Lcd_WriteCmd(0x34); // Turn off graphic display for (i = 0; i < 1; i + + ) // Upper and lower screen writing { for (y = 0; y < 32; y + + ) // Write vertical Y 32 times { for (x = 0; x < 8; x + + ) // Write X horizontally 8 times { Lcd_WriteCmd(0x80 + y); // Row address Lcd_WriteCmd(0x80 + x + i); // Column address Lcd_WriteData(*img + + ); //Write high-order byte data D15-D8 Lcd_WriteData(*img + + ); //Write low byte data D7-D0 } } } Lcd_WriteCmd(0x36); // Turn on graphic display Lcd_WriteCmd(0x30); // Switch back to basic instructions } /*! * @brief screen clear function * @since v1.0 * @param None * @author Z Xiaoxuan */ void LCD_Clear(void) { Lcd_WriteCmd(0x01); // Clear screen command delay_ms(2); // Delay until the liquid crystal stabilizes [at least 1.6ms] }
LCD.h
#ifndef __lcd12864_H_ #define __lcd12864_H_ #include "sys.h" #define WRITE_CMD 0xF8 // Write command #define WRITE_DAT 0xFA // Write data //Interface (SID: PB1 SCLK: PB0) #define SIDPBout(1) #define SCLKPBout(0) void lcd_GPIO_init(void); void Lcd_Init(void); void SendByte(u8 Dbyte); void LCD_Clear(void); void LCD_Display_Words(uint8_t x, uint8_t y, uint8_t *str); void LCD_Display_Picture(uint8_t *img); void Lcd_WriteData(u8 Dat); void Lcd_WriteCmd(u8 Cmd); #endif
main.c
The LCD comes with a font library that can be used directly
#include "stm32f10x.h" #include "sys.h" #include "lcd.h" #include "delay.h" #include "usart.h" #include "adc.h" int main(void) { uart_init(115200); delay_init(); lcd_GPIO_init(); Lcd_Init(); while (1) { /*Chinese character display*/ LCD_Display_Words(0, 0, "Qing Dynasty Mingyue Han Shiguan"); LCD_Display_Words(1, 0, "Thousands of miles of long march have not yet been returned"); LCD_Display_Words(2, 0, "But the Dragon City Flying General will be here"); LCD_Display_Words(3, 0, "Don't teach Huma to cross the Yinshan Mountains"); } }
3. Reference
STM32 LCD12864 serial communication mode (let you understand from the principle)https://blog.csdn.net/as480133937/article/details/97650805?ops_request_misc= & amp;request_id= & amp;biz_id=102 & amp;utm_term=Display Module (LCD12864 — Serial) & amp;utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-1-97650805.142 ^v96^pc_search_result_base7 &spm=1018.2226.3001.4187
For the complete code, please follow the Satellite public account to obtain and consult