4. Introduction to LED1602 LCD module and its programming

Reference materials:
1602 related parameters: http://www.elecfans.com/xianshi/20180205630037.html

One, the basic introduction of 1602

1602 is a basic liquid crystal module, where 16 means that 16 characters are displayed on one line, and 02 means that 2 lines are displayed. 1602 is a liquid crystal module with 2 lines and 16 characters in each line. The letter before 1602 is the name of the manufacturer.
Insert picture description here
The display effect of black screen and white characters is better. The LCD module with backlight means that the screen has bottom light after the backlight board power supply. The display effect is better, but the power consumption is relatively large. The module without the backlight board is thin and not suitable for low-light environments. Used in.

Commonly used chip packaging technology:
SMT/TAB/COG/COF/COB usually looks like a black drop-shaped bump
Insert picture description here

1. Pin distribution and meaning

(Generally speaking, it is made of 16 pins)
Insert picture description here
VEE is the problem of adjusting the contrast, you need to connect an adjustable resistor to adjust
DB0-DB7 is the data bus, DB0 is the lowest bit
parallel method of the data bus : DB0-DB7 (Consuming resources, but fast)
Serial method: DB4-DB7 (saving resources, but slow)

2, 1602 LCD dial fast drive circuit

Insert picture description here
(Because the data is basically written into 1602, the bit of RW control read and write is directly grounded)

www.Alldatasheet.com can find the main control chip HD44780U of 1602, which is the interaction of the two chips of stm8 and 44780U.

Two, 1602 programming use

1602 LCD module pin meaning
RS/RW/EN These control lines are necessary, DB0-DB7 are data buses

1. Timing diagram

Figure out the reading sequence diagram: (less use)
Insert picture description here

2. Read sequence operation-read data command to 1602 (less use)

Visible:
Read status: RS = 0, RW = 1, EN = 1, after tDDR time, the status can be read.
Read data: RS = 1, RW = 1, EN = 1. After tDDR time, data can be read.
Operation process:
Insert picture description here

3. Write sequence operation-write data command to 1602 (commonly used)

Write status: RS = 0; RW = 0; data ready; EN = 1 ----> 0
write data: RS = 1; RW = 0; data ready; EN = 1 ----> 0
Insert picture description here
(All the rising edges of the appeal are changed to falling edges, and data writing can be realized only when a falling edge is generated)

3. Introduction to the three major registers of 1602

Question 1: Where does the data we write or read data come from, or where is it written?
Question 2: Thinking about how to display characters in the DDRAM address?

CGROM: ​​character generator unit
CGRAM: user-defined character generator RAM unit
DDRAM: display data storage RAM unit

Insert picture description here
Common ROMs are: EEPROM, EPRROM, Flash flash memory (will not be lost after power failure, but the data is slower)
Common RAM: SRAM, SROM (will be lost after power failure, but the speed is faster)

1. CGROM: ​​character generator unit

The HD44780 controller chip has built-in 192 commonly used character touches, which are stored in the character generator CGROM, which is not lost when the power is turned off, in order to facilitate the user to take the modulus.
Insert picture description here

2. CGRAM: User-defined character generator RAM unit

In the appeal, in addition to this, there are 8 additional characters that allow user-defined characters to be generated in RAM and stored in CGRAM. That is, its role in creating characters. A space where you can make your own words
Insert picture description here

3. DDRAM: display data storage RAM unit

This is a RAM unit for displaying data, which is used to store the character code that needs to be displayed. It has a total size of 80 bytes, and a row can support up to 40 bytes. But 1602 only needs the first 16 bytes in size, and the latter is temporarily unnecessary.
Insert picture description here
to sum up:
Insert picture description here

4. Instruction set

Question 3: The above knows that the reading and writing of data refers to the font, and what do the reading and writing commands refer to?
The command is to let the liquid crystal display a certain function. The instruction set is as follows:
Insert picture description here

Fourth, the specific programming realization of 1602

Data is used to display different functions, and commands are used to select 1602 functions.
Write status: RS = 0; RW = 0; Data is ready; EN = 1 ----> 0
Write data: RS = 1; RW = 0; prepare data; EN = 1 ----> 0

Question: Why is the display address of the first line 0x80?
Reason: The address needs to be offset, and an address of 80 needs to be added.
Insert picture description here
Determine the required command.
Insert picture description here
Determine the circuit connection. The
Insert picture description here
code is as follows: Display two lines of character string

#include "iostm8s208mb.h"

#define u8  uint8_t
#define u16 uint16_t
#define u32 uint32_t
typedef unsigned char    uint8_t;
typedef unsigned short   uint16_t;
typedef unsigned long    uint32_t;

#define LED1602EN PF_ODR_ODR4
#define LED1602RW PF_ODR_ODR3
#define LED1602RS PF_ODR_ODR0
#define LED1602Data    PB_ODR

void GPIO_Init(void);
void LED1602_Init(void);	
void LED1602_WriteData(u8 Data);	//写数据
void LED1602_WriteComm(u8 Data);	//写命令
void LED1602_Play(void);			//字符串显示
void LED1602_DataPrev(u8 Data);		//数据准备
void Delay(u16 time);

//显示的两个字符串
u8 StringBuff1[16] = "  Hello World!  ";
u8 StringBuff2[16] = "  My Clichong!  ";

int main( void )
{
  GPIO_Init();
  LED1602_Init();
  LED1602_Play();
  
  return 0;
}

void GPIO_Init(void)
{
    PF_DDR |= 0x19;
    PF_CR1 |= 0x19;
    PF_CR2 &= 0xE6;
    
    PB_DDR |= 0xFF;
    PB_CR1 |= 0xFF;
    PB_CR2 &= 0x00;
    
}

void LED1602_Init(void)
{
    LED1602_WriteComm(0x01);    //清屏功能
    LED1602_WriteComm(0x3C);    //8位2行点阵
    LED1602_WriteComm(0x0D);    //显示功能开启,无光标,光标不闪烁
    LED1602_WriteComm(0x06);    //写入新数据后显示屏不移动仅光标右移
}

void LED1602_DataPrev(u8 Data)
{
    LED1602Data = Data;
}

void LED1602_WriteData(u8 Data)
{
    LED1602RS = 1;
    LED1602RW = 0;
    LED1602_DataPrev(Data);
    Delay(2);
    LED1602EN = 1;	//产生一个下降沿触发,发送命令
    Delay(2);
    LED1602EN = 0; 
}

void LED1602_WriteComm(u8 Data)
{
    LED1602RS = 0;
    LED1602RW = 0;
    LED1602_DataPrev(Data);
    Delay(2);
    LED1602EN = 1;	//产生一个下降沿触发,发送数据
    Delay(2);
    LED1602EN = 0;
}

void LED1602_Play(void)
{
    u8 i;
    for(i = 0; i < 16; i++){
        LED1602_WriteData(StringBuff1[i]);
    }
    LED1602_WriteComm(0xC0);  //注意偏移量为0x80,所以0x40的基础上加上0x80为0xc0才是第二行的第一个,否则会无法显示第二行
    for(i = 0; i < 16; i++){
        LED1602_WriteData(StringBuff2[i]);
    } 
}

void Delay(u16 time)
{
  u8 i,j;  
  while(time--){
    for(i = 0; i < 20; i++)
      for(j = 0; j < 50; j++);
  }
}

Guess you like

Origin blog.csdn.net/weixin_44751294/article/details/106677879