Lesson 9 LCD1602

Share for us

Introduction

In this experiment, the SunFounder Uno board is used to directly drive LCD1602 to display characters. Before the experiment, you need to solder the pin headers we provided onto the LCD1602 for convenience.

Components

– 1 * SunFounder Uno board

– 1 * Breadboard

– 1 * LCD1602

– 1 * Potentiometer (50kΩ)

– Jumper wires

– 1 * USB cable

Principle

Generally speaking, LCD1602 has parallel ports, that is, it needs to control several pins at the same time. LCD1602 can be categorized into eight-port and four-port connection. If the eight-port connection is used, then the digital ports of the SunFounder Uno board are basically completely occupied. If you want to connect more sensors, there will be no ports available. Therefore, the four-port connection is used.

Pins of LCD1602 and their functions:

VSS: A pin that connects to ground

VDD: A pin that connects to a +5V power supply

VO: A pin that adjust the contrast of LCD1602

RS: A register select pin that controls where in the LCD’s memory you are writing data to. You can select either the data register, which holds what goes on the screen, or an instruction register, which is where the LCD’s controller looks for instructions on what to do next.

R/W: A Read/Write pin that selects reading or writing mode

E: An enabling pin that, when supplied with low-level energy, causes the LDC module to execute relevant instructions.

D0-D7Pins that read and write data

A and K: Pins that control the LED backlight

In this experiment, a 50KΩ potentiometer is used to adjust the contrast of LCD1602 to display characters or figures you want. For programming, it is optimized by calling function libraries.

Experimental Procedures

Step 1: Build the circuit (please be sure the pins are connected correctly. Otherwise, characters will not be displayed properly):

The schematic diagram

Step 2: Program (Please refer to the example code in LEARN -> Get Tutorials on our website)

Step 3: Compile the code

Step 4: Upload the sketch to the SunFounder Uno board

Note: you may need to adjust the potentiometer on the LCD1602 until it can display clearly.

You should now see your LCD1602 display the characters “SunFounder” and “hello, world” in a rolling manner.

Code

// include the library code
#include <LiquidCrystal.h>
/**********************************************************/
char array1[]=” SUNFOUNDER               “; //the string to print on the LCD
char array2[]=”hello, world!               “; //the string to print on the LCD
int tim = 250; //the value of delay time
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(4, 6, 10, 11, 12, 13);
/*********************************************************/
void setup()
{
  lcd.begin(16, 2); // set up the LCD’s number of columns and rows:
}
/*********************************************************/
void loop()
{
  lcd.setCursor(15,0); // set the cursor to column 15, line 0
  for (int positionCounter1 = 0; positionCounter1 < 26; positionCounter1++)
  {
    lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left.
    lcd.print(array1[positionCounter1]); // Print a message to the LCD.
    delay(tim); //wait for 250 microseconds
  }
  lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
  lcd.setCursor(15,1); // set the cursor to column 15, line 1
  for (int positionCounter = 0; positionCounter < 26; positionCounter++)
  {
    lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left.
    lcd.print(array2[positionCounter]); // Print a message to the LCD.
    delay(tim); //wait for 250 microseconds
  }
  lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
}
/************************************************************/

Video