Introduction to the use of LCD1602

Introduction to LCD1602

      LCD1602 liquid crystal is also called 1602 character liquid crystal module. LCD1602 liquid crystal is a dot matrix liquid crystal module specially used to display letters, numbers and symbols. LCD1602 liquid crystal is composed of several 5x7 dot matrix characters, and each dot matrix character can display a character (including letters, numbers, symbols), and a total of 16x2 characters can be displayed . There is a dot pitch interval between each bit of the LCD1602 liquid crystal, and there is also an interval between each line, which plays the role of character spacing and line spacing. LCD1602 liquid crystal can only display characters (including letters, numbers, symbols), and cannot display pictures.

      LCD1602 liquid crystal module has the advantages of small size and low power consumption. It is widely used in various industrial equipment, household electronic products, instrumentation, embedded systems and other occasions.

LCD1602 technical parameters

LCD1602 pin description

The function of each pin of the       LCD1602 liquid crystal module is introduced as follows:

      1. Pin 1 of LCD1602 liquid crystal: VSS is connected to the negative pole of 5V power supply, that is, GND.

      2. Pin 2 of LCD1602 liquid crystal: VDD is connected to the positive pole of 5V power supply.

      3. Pin 3 of LCD1602 liquid crystal: VL is the display bias signal of the liquid crystal, which is used to adjust the contrast of the liquid crystal display. The contrast is the weakest when connected to the positive pole of the power supply, and the contrast is the highest when connected to the ground. When the contrast is too high, a "ghost" phenomenon will occur, resulting in unclear characters displayed on the LCD. We can adjust the contrast by using a 10kΩ potentiometer.

      4. Pin 4 of LCD1602 liquid crystal: RS is the register selection pin of liquid crystal. When this pin is high level, it selects the data register , and when this pin is low level, it selects the instruction register .

      5. Pin 5 of the LCD1602 liquid crystal: R/W is the read/write selection pin. When the pin is high, the read operation is performed, and when the pin is low, the write operation is performed.

      a  When the RS and R/W pins are both low, the command or display address can be written.

      b  When the RS pin is low and the R/W pin is high, the busy signal can be read.

      c  When the RS pin is high and the R/W pin is low, data can be written.

      6. Pin 6 of LCD1602 liquid crystal: E pin is the enable terminal, when the E pin jumps from high level to low level, the liquid crystal module executes the command.

      7. Pins 7~14 of LCD1602 liquid crystal: D0~D7 are 8-bit bidirectional data lines of liquid crystal.

      8. Pin 15 of LCD1602 liquid crystal: the positive pole of the backlight source of the liquid crystal module.

      9. Pin 16 of LCD1602 liquid crystal: the negative electrode of the backlight source of the liquid crystal module.

Liquid crystal LCD1602 instruction

​LCD LCD1602 Timing

      Read Operation Timing

       Write Timing

 

       timing parameters

Liquid crystal LCD1602 initialization process

      1. Delay 15ms.

      2. Write command 38H (do not detect busy signal).

      3. Delay 5ms.

      4. Write command 38H (do not detect busy signal).

      5. Delay 5ms.

      6. Write command 38H (do not detect busy signal).

      (The busy signal needs to be detected between each write command and read and write data operation in the future).

     7. Write command 38H: display mode setting.

     8. Write command 08H: display off.

     9. Write command 01H: clear the screen.

     10. Write command 06H: display cursor movement setting.

     11. Write command 0CH: display on and cursor setting. 

Liquid crystal LCD1602 routine

/****************LCD driver basic code****************      

*MCU model: STC89C52RC, crystal oscillator frequency: 11.0592M

*Development environment: KEIL

*Note: LCD1602 displays letters, numbers and symbols.   

******************************************************/

#include<reg52.h>

#include<intrins.h>

#define LCD_Data P0

#define Busy 0x80

sbit LCD_RS = P1^0;

sbit LCD_RW = P1^1;

sbit LCD_E  = P2^5;

unsigned char code welcome[] = {"YOU ARE WELCOME"};

unsigned char code mcu[] = {"SL-51A"};

void Delay5Ms(void);

void WriteDataLCD(unsigned char WDLCD);

void WriteCommandLCD(unsigned char WCLCD,BuysC);

unsigned char ReadDataLCD(void);

unsigned char ReadStatusLCD(void);

void LCDInit(void);

void DisplayOneChar(unsigned char X, unsigned char Y, unsigned char DData);

void DisplayListChar(unsigned char X, unsigned char Y, unsigned char code *DData);

void Info_display(void);

void Delay5Ms(void)

{

 unsigned int TempCyc=3552;

 while(TempCyc--);

}

void WriteDataLCD(unsigned char WDLCD)

{

 ReadStatusLCD();

 LCD_Data=WDLCD;

 LCD_RS=1;

 LCD_RW=0;

 LCD_E=0;    

 LCD_E=0;

 LCD_E=1;

}

void WriteCommandLCD(unsigned char WCLCD,BuysC)

{

 if(BuysC)ReadStatusLCD();

 LCD_Data=WCLCD;

 LCD_RS=0;

 LCD_RW=0;

 LCD_E=0;

 LCD_E=0;

 LCD_E=1;

}

unsigned char ReadStatusLCD(void)

{

 LCD_Data=0xFF;

 LCD_RS=0;

 LCD_RW=1;

 LCD_E=0;

 LCD_E=0;

 LCD_E=1;

 while(LCD_Data&Busy);

 return(LCD_Data);

}

void LCDInit(void)

{

 LCD_Data = 0;

 WriteCommandLCD(0x38,0);Delay5Ms();

 WriteCommandLCD(0x38,0);Delay5Ms();

 WriteCommandLCD(0x38,0);Delay5Ms();

 WriteCommandLCD(0x38,1); 

 WriteCommandLCD(0x08,1);

 WriteCommandLCD(0x01,1);

 WriteCommandLCD(0x06,1);

 WriteCommandLCD(0x0C,1);

}

void DisplayOneChar(unsigned char X,unsigned char Y,unsigned char DData)

{

 Y&=0x1;X&=0xF; 

 if(Y)X|=0x40;

 X|=0x80;

 WriteCommandLCD(X,0);

 WriteDataLCD(DData);

}

void DisplayListChar(unsigned char X,unsigned char Y,unsigned char code *DData)

{

 unsigned char ListLength;

 ListLength=0;

 Y&=0x1;X&=0xF;

 while(DData[ListLength]>=0x20)

 {

  if(X<=0xF)

  {

   DisplayOneChar(X,Y,DData[ListLength]);

   ListLength++;

   X++;

  }

 }

}

void main(void)

 LCDInit(); 

 DisplayListChar(5,0,mcu);

 DisplayListChar(0,5,welcome);

 while(1){;}

}

LCD1602 application circuit diagram

 

Guess you like

Origin blog.csdn.net/weichen_78/article/details/128262615