Learn to use three minutes LCD LCD1602

1 Introduction

Common types of SCM display as physical design, is a specialized for the LCD1602 display letters, numbers, symbols, dot matrix LCD, 1602 refers to the content which is 16X2 LCD display, which can display two lines of 16 character (a Chinese character occupies two characters).

 

2. hardware parameters

(1) LCD1602 main technical parameters

  • Display capacity: 16 × 2 characters.

  • Chip Operating voltage: 4.5-5.5V

  • Working current: 2.0mA (5.0V)

  • Module optimum operating voltage: 5.0V

  • Character Size: 2.95 × 4.35 (W × H) mm

     

 

(2) the pin definitions

LCD1602 pin main logic supply pin VDD, VSS; backlight with power pin BLA, BLK; data pins D0-D7, RS, R / W, EN; the VL pin bias signal; wherein:

  • VL pin: a liquid crystal display contrast adjustment end, connected to the positive supply when the weakest contrast, when the highest contrast ground, will have a "ghosting" when the contrast is too high, the contrast can be adjusted by a 10K potentiometer use;

  • Pin RS: RS is selected register, the data register selected at a high level, a low level selection instruction register

  • R / W pin: R / W signal is a read-write lines, read operation at a high level, a low level write operation. When RS and R / W is low together can display address or the write command, when the RS is low R / W is high read busy signal, when the RS is high R / W is low data can be written.

  • EN pin: E to enable terminal end, when E Duanyou high jump into the low level, the liquid crystal module execution command.

 

(3) a circuit diagram

Wherein an adjustable resistor for adjusting the contrast of the display of the P. Resistor R as the current limiting resistor to prevent overcurrent burned display backlight.

 

3. Control program

LCD1602 down simplified display control program, is relatively simple, only need to implement write data , write command , initialization three control functions can be realized control of the LCD1602. (Generally do not write, do not say is omitted here)

(1) Write Timing

To achieve the following functions write data and a write instruction, the write operation timing is to be programmed, to achieve effective control; wherein the difference, and the write timing by the RS pin definitions, write data and write commands that pin RS level; when RS is high, the write data; when RS is low, write command.

(2) write data function

//写数据
void write_data(uchar date)
{
  LCDRS=1;
  P0=date;
  LCDdelay(5);
  LCDEN=1;
  LCDdelay(5);
  LCDEN=0;
}

 

(3) write instruction function

//写命令
void write_com(uchar com)
{
  LCDRS=0;
  P0=com;
  LCDdelay(5);
  LCDEN=1;
  LCDdelay(5);
  LCDEN=0;
}

 

(4) the initialization function

LCD1602 initialization need to do the following settings:

. A set write operation: R / W is set to a low level;

. B Screen Set Mode: 38H write instruction;

. C Open display, the cursor off: 0CH write instruction;

. D set the display position of the cursor: write command 06H;

. E character display position is provided: a write command (the starting position of character display);

void Init1602()
{
  uchar i=0;
  LCDRW = 0;
  write_com(0x38);//屏幕初始化
  write_com(0x0c);//打开显示 无光标 无光标闪烁
  write_com(0x06);//当读或写一个字符是指针后一一位
  write_com(0x01);//清屏
  write_com(0x80);//设置位置
}

NOTE: Because of the need to implement a read operation control LCD1602, so R / W after the initialization constant (this pin is directly or a short to ground) is low.

 

4. Display characters

To display a specific character in the LCD1602, is actually written into the corresponding data on the LCD1602 DDRAM, the display will show the character you want.

(1) DDRAM address map

Can be seen from RAM, read means, as the display position address, the address of each row 40, 1602 uses the first 16, a total of two lines, as shown in a correspondence relationship: 

The write instruction format, since the address is 7, when the write address, bit 8 always 1, as shown:

When we want to write to the specified location, specify the address of the first, as the first written in the first line, the address bits are 00H, coupled with the DB7 1, namely 80H (0010000000), the second line of the first bit is 40H, coupled with the DB7 1, namely C0H (0011000000), and so on.

For example, to write at position 3, line 1 "HELLO WOLRD", i.e. the first write address, write data and then:

write_com(0x40+0);  //第1行第3位
write_com(‘H’);
write_com(‘O’);
.....
write_com(‘D’);

If it is written in row 2, 2:

write_com(0x40+0x80+2);  //第2行第2位//数据与上面一样

(2) Display Function

For simplicity and convenience of the program, we will show the program into one display function:

​​​​​

void Display_1602(uchar x,uchar y,uchar *str){ unsigned char addr;    if (y == 0)  {    addr = 0x00 + x; //第一行的x位置显示  }  else  {    addr = 0x40 + x; //第二行x的位置显示  }  write_com(addr + 0x80);  while (*str != '\0')  {    write_data(*str++);  }}

      To achieve the above display is relatively simple:

Line a third display "HELLO WOLRD":

Display_1602(3,1,”HELLO WOLRD”);

Row 2 2 display "HELLO WOLRD":

Display_1602(2,2,”HELLO WOLRD”);

 

For more information about LCD1602

Focus on micro-channel public number "small things bright road"

 

 

发布了9 篇原创文章 · 获赞 4 · 访问量 229

Guess you like

Origin blog.csdn.net/weixin_44206126/article/details/104355202