[STC MCU learning] Lesson 17: LCD1602 display

[Mr. Zhu's course summary intrusion]

The first part, chapter list

1.17.1_2. LCD display related background 1_2

1.17.3. Start learning LCD1602

1.17.4. Low-level timing of LCD1602 controller 1

1.17.5. Low-level timing of LCD1602 controller 2

1.17.6. Code Practice


Part Two, Classroom Record

1.17.1_2. LCD display related background 1_2

1.17.1.1 Introduction to LCD
(1) Display
CRT display (big head TV)
LCD liquid crystal display
LED liquid crystal display, etc.

(2) LCD (Liquid Crystal Display), liquid crystal display, principle introduction
The working principle of liquid crystal display is to use the physical characteristics of liquid crystal , When the electricity is turned on, the liquid crystal arrangement becomes orderly, making the light easy to pass; when the electricity is not turned on, the arrangement becomes chaotic, preventing the light from passing through.
Transmittance!
(3) LCD application areas
Tablet PCs, laptops, mobile phone screens, smart TV screens...
(4) LED OLED (recognized as the next-generation display)
OLED: curved screen, especially Samsung


1.17.1.2, the principle of electronic displays
(1 ) Pixels (resolution):

  • Pixel (px): The smallest unit that makes up an image
  • Resolution: Screen resolution refers to the maximum number of pixels in vertical and horizontal directions
  • PPI: Number of pixels per inch


Take drawing as a demonstration!

(2) Video memory (graphic card memory): memory used for display

  • Video memory is used to store graphics information to be processed , used to store pixel data
  • Graphics card = video memory + GPU + circuit board + BIOS firmware
  • When programming, you don’t have to worry about storing the pixels you want to manipulate in the video memory!

(3) Font: The font is the corresponding code when the character is displayed on the dot matrix

  • Fonts are used when displaying Chinese characters or characters
  • I have touched it before when displaying Chinese characters on the LED dot matrix
  • The font is not unique: Times New Roman, Kaiti, HeiTi, Time New Rome, etc., the same character has different codes corresponding to different fonts
    Description of the generated font

(4) Font library: The library containing fonts is
     similar to movable type printing
(5) Controller and driver

  • The controller of the display: The control chip is responsible for communicating with the CPU, which is closer to the software.
  • Display driver: Take the LCD driver as an example, it is used to modulate the phase, peak value, frequency, etc. of the potential signal applied to the electrode of the liquid crystal display device to establish a driving electric field to achieve the display effect during the liquid crystal display, which is closer to the hardware .
  • Consider the controller when programming, the driver is not sensitive.

(6) Software + hardware realization function

  • The hardware only needs to be understood, and the controller is used to control the video memory and then the hardware to realize the function.


1.17.3. Start learning LCD1602


1.17.3.1 Introduction
(1) Introduction to LCD1602

  • 16 columns x 2 rows, the display shows 2 rows, each with 16 characters.
  • Dot matrix LCD module specially used to display letters, numbers and symbols
  • It can display 32 characters, but the number of pixels is not 32 because a character is composed of multiple pixels. It is possible that a character is composed of 5*7=35 pixels, or it may be composed of 5*10=50 pixels.
  • LCD1602 has a built-in font library. You can get the font directly!

(2) Cannot display Chinese

  • LCD1602 has ASCII code font library. When we want LCD1602 to display a certain ASCII code character, we only need to send the ASCII code corresponding to this character to the controller inside LCD1602, the controller will check the font library to get the font, and then send the font Give the internal driver to drive the LCD for display.

(3) Purpose: It is rarely used,
View source image

1.17.3.2, schematic diagram and wiring pins can be used in the calculator

(1) Pins:

  • 8 data interfaces—DB0-DB7: parallel data transmission
  • 3 control interfaces—RS: data/command selection bit (H/L), RW: read/write selection bit (H/L), E: enable signal
  • Adjust the contrast 1: VO
  • VCC/GND 4: GND, VCC, BG VCC, BG GND: positive and negative power supply and backlight positive and negative

(2) Parallel interface (DB0-DB7)
Parallel means that there are multiple data lines, each of which can transmit 1 bit, so multiple bits can be transmitted at the same time. LCD1602 has 8 data lines, so 8 bits are simultaneously transmitted at a time.
(3) Wiring confirmation

  • How to connect LCD1602 to the development board (demo)
  • How to connect the MCU to the LCD1602 socket: it has been connected, as long as the sbit is declared well



1.17.3.3. Data manual
Click SMC1602 data manual to download
(1) Concept: LCM: LCD Module (LCD module)
(2) Analysis of main technical parameters
(3) Pin definition (combined with schematic diagram for comparative analysis)

(4) Control Controller interface description (note the controller model)

When RS=H, D0-D7 transmits data. When
RS=L, D0-D7 transmits commands. When
RW=H, it means we want to read. When
RW=L, it means we want to write
E=H. When enable           
E=L, it means forbid (disable)

1.17.4. Low-level timing of LCD1602 controller 1

1.17.4.1 Key points
(1) Timing control interface pins


(2) Status word, instruction code, and data are all through DB0-DB7 data interface
>>Status word:

  • Official routine read and write detection function

STA0-6 is the value of the current address, which is the cursor!
The controller comes with an 80*8 bit (80 bytes) RAM buffer, as shown below:
RAM address range:

  • Official routine coordinate display function
  • Realize coordinate configuration by writing instructions

>>Command code:

  • Initialization:
    0x38 (open, 5*7, 8-bit data)
  • Display on/off settings:
    0x0C turn on the display without displaying the cursor
    0x08 turn off the display
    0x0F turn on the display and display the cursor and the cursor blinks

  • Cursor setting:
    0x06 (read and write a character, add one to the address pointer and cursor)

  • Clear screen:
    0x01
  • Carriage return:
    0x02
  • Set the starting coordinates
    0x80+(0x00-0x0F) The first line set address pointer instruction
    0x80+(0x40-0x4F) The second line set address pointer instruction

    addr | 0x80, you can realize addr plus 0x80, think about why?

>>Data: To
write data directly, just set RS/RW/E and put the data in DB0-DB7! Because the data is transmitted in parallel, it can be transmitted at the same time!

1.17.4.2 Analysis of the underlying time series function

  • Read_Busy()
  • Lcd1602_Write_Cmd()
  • Lcd1602_Write_Data()

1.17.5.1、Read data

  • The sample code does not have this function to read data.
  • Data can be read out from LCD1602, and then printed in the serial port!

1.17.5. Low-level timing of LCD1602 controller 2

1.17.5.1 RAM space

(1) RAM address range (the address range is 00-39 per line, but we only use 00-16 per line)

(2) What is the
data: data: the ASCII code value of the character to be displayed
Write data method:

  • The string "" or the character ''
  • Send the code value in the ascii code table directly             

1.17.6. Code Practice

//main.c
#include "lcd1602.h"

void LCD_init(void);
void LCD_show(u8 *str);
void main(void)
{
	u8 str[] = "hello,everyone!";
	LCD_init();
	LCD_show(str);
	while(1);
}

void LCD_init(void)
{
	Lcd1602_Write_Cmd(0x38); //初始化
	Lcd1602_Write_Cmd(0x0C); //显示开/关设置
	Lcd1602_Write_Cmd(0x06); //光标设置
	Lcd1602_Write_Cmd(0x01); //清屏
	LCD_setcursor(0,0);
}
void LCD_show(u8 *str)
{
	while(*str != '\0')
	{
		Lcd1602_Write_Data(*str);
		str++;
	}
}
//lcd1602.h
#ifndef __LCD1602_H_
#define __LCD1602_H_

#include <reg51.h>

#define  u8  unsigned char
#define  u16  unsigned int
#define LCD_DB  P0  //DB0-DB7

sbit LCD_EN = P2^7;
sbit LCD_RS = P2^6;
sbit LCD_WR = P2^5;

void RW_Busy();  //忙检测函数
void Lcd1602_Write_Cmd(unsigned char cmd);   //写命令
void Lcd1602_Write_Data(unsigned char dat);  //写数据
void LCD_setcursor(u8 x,u8 y); //设置坐标


#endif
//lcd1602.c
#include "lcd1602.h"

void RW_Busy()  //忙检测函数,读状态
{
	  unsigned char sta;    
    LCD_DB = 0xff;		//
    LCD_RS = 0;
    LCD_WR = 1;
    do
    {
        LCD_EN = 1;
        sta = LCD_DB;
        LCD_EN = 0;    //使能,用完就拉低,释放总线
    }while(sta & 0x80);//判断第7位是否为0
}
void Lcd1602_Write_Cmd(unsigned char cmd) //写命令
{
	RW_Busy();
	LCD_RS = 0;
  LCD_WR = 0;
	LCD_DB = cmd;
	LCD_EN = 1;
	LCD_EN = 0;	
}
void Lcd1602_Write_Data(unsigned char dat) //写数据
{
	RW_Busy();
	LCD_RS = 1;
  LCD_WR = 0;
	LCD_DB = dat;
	LCD_EN = 1;
	LCD_EN = 0;
}
void LCD_setcursor(u8 x,u8 y) //设置坐标
{
	unsigned char addr;
  if(y == 0)
			addr = 0x00 + x;
	else
			addr = 0x40 + x;
    
 Lcd1602_Write_Cmd(addr|0x80);
	
}

Program download link for this lesson: LCD1602

This lesson is over!

Guess you like

Origin blog.csdn.net/qq_27148893/article/details/110581194