Ads

Get STM32 tutorial using HAL at $10 for a limited time!

Saturday, June 20, 2015

LCD 16x2 HD44780 Tutorial 2 - Basic Commands and Displaying Text

In this post, I will explain how to send commands and characters data to LCD 16x2 HD44780. From the previous tutorial, we have finished building the circuit on the breadboard. When you power up this circuit, you will see a series of square only on line 1 of the display. This is the default pattern of an uninitialized LCD display. The LCD will always reset itself to this pattern when power is applied. If you not see this pattern, you can turn the resistor variable that controls the contrast of the LCD until see this pattern.


Before we can display characters on the LCD, we must send several commands for control the LCD settings. This is the step when we want to send a command to the LCD:
  1. Set the Register Select switch to logic low (not pressed).
  2. Set the dip switch to the desired command.
  3. Press the Enable push button (which "enables" the chip to accept command).
This is the full list of commands that can be sent:


The first command that we will send is function set. This command is for setting interface mode, line mode, and font type. We will use 8-bit interface, 2 line mode, and 5x7 dots font type. Therefore we set the command to 0b00111000 or 0x38 in hexadecimal. Set the register select pin to low and then press the enable button. After press the enable button, the default pattern on the LCD will be cleared.

The second command that must be entered is display on/off and cursor. In this command we turn on the LCD display and set the cursor style (underline and blinking cursor on/off). Therefore we set the command to 0b00001111 or 0x0F to make the LCD display on, cursor underline on, and cursor blinking on. Set the register select pin to low and then press the enable button. After press the enable button, the LCD will display underline and blinking cursor on first line. 

After that, we can start to enter characters data. To enter a character to the LCD we must use this step:
  1. Set the Register Select switch to logic high (pressed).
  2. Set the dip switch to the desired ASCII data.
  3. Press the Enable push button (which "enables" the chip to accept data).
For example, we want display "A" character on LCD. First, we set the data to 0b01000001 or 0x41 in hexadecimal. Then set the register select pin to high and finally press the enable button. After press the enable button, character "A" will be displayed and the cursor is move to the next column.

To clear the LCD display, we can send command 0b00000001 or 0x01 set the RS pin to low (because we want to send command) then press enable button. 

This is process when we want to display "AnNyeongHaSeYo" to the LCD display from the LCD reset:


This is the result (you can hide the cursor by sending command 0x00001100 to LCD):


This is another example:


감사합니다!

No comments :

Post a Comment