STM32F103 SPL Tutorial 7 – Interfacing LCD16x2


LCD16x2 is a popular display module and commonly used in various devices. In this tutorial, I will explain about how to use LCD16x2 with STM32F103 microcontroller. If you want to know the detail how LCD16x2 works, you can follow this tutorial. To interface the LCD with STM32F103, you need the library files (lcd16x2.h and lcd16x2.c). You can get the library files and from here.

STM32F103 LCD16x2

Continue reading “STM32F103 SPL Tutorial 7 – Interfacing LCD16x2”

LCD16x2 HD44780 Tutorial 6 – 4-bit Mode

LCD16x2 4-bit Mode

LCD16x2 can be used in 4-bit mode or 8-bit mode. Since the first tutorial until previous tutorial, we only use the 8-bit mode. In 8-bit mode, we need 8 wire from D7 to D0 in order to send command or data. In this tutorial, I will explain how to use LCD16x2 in 4-bit mode. This mode is useful when we want to control the LCD from microcontroller, because it uses less GPIO pins. In 4-bit mode, only 4 wire from D7 to D4 is used, D3 to D0 is not used. The transfer method is high nibble first, then followed by low nibble.

This is the procedure how to use 4-bit mode to display character ‘A’:

  1. Send command: 0b0010 xxxx (Set 4-bit mode).
  2. Send command: 0b0010 xxxx (high nibble of function set).
  3. Send command: 0b1000 xxxx (low nibble of function set).
  4. Send command: 0b0000 xxxx (high nibble of display on, underline on, and blinking on).
  5. Send command: 0b1111 xxxx (low nibble of display on, underline on, and blinking on).
  6. Send data: 0b0100 xxxx (high nibble of  ‘A’).
  7. Send data: 0b0001 xxxx (low nibble of ‘A’).

Thank you for reading this LCD tutorial.

LCD thank you

LCD16x2 HD44780 Tutorial 5 – Create Custom Characters


In this tutorial, I will explain how to create and display custom characters on LCD16x2. The first thing you must know is that on the LCD there are two type memories that store defined characters, CGROM and CGRAM. CGROM is used for storing all permanent font that can be displayed by using their ASCII code. For example, if we write 0x41 then on the display will show character ‘A’. CGROM memory is non-volatile and can’t be modified. CGRAM is another memory that can be used for storing user defined characters. This memory is volatile and can be modified any time. This memory can store up to 8 user defined characters. Characters that are stored in CGRAM can be accessed from code 0x00 to 0x07. This table below show character codes and character patterns for CGRAM and CGROM.

Char codes

Continue reading “LCD16x2 HD44780 Tutorial 5 – Create Custom Characters”

LCD16x2 HD44780 Tutorial 4 – Character Entry Mode

LCD16x2 Character Entry Mode 1

In this tutorial, I will explain about character entry mode of the LCD16x2. There are 4 character entry modes that can be used. So far, we have been used the default character entry mode until previous post. The entry mode is auto-incrementing the cursor address every a new character is entered. This is the default entry mode every LCD is powered up. To do the first entry mode or the default entry mode, we can send instruction 0b00000110 to the LCD. Every a new character is entered, the cursor/DDRAM address is auto-incremented by 1. This mode is illustrated by animation below.

LCD entry 1

Continue reading “LCD16x2 HD44780 Tutorial 4 – Character Entry Mode”

LCD16x2 HD44780 Tutorial 3 – Display Address and Shifting


In this tutorial, I will explain about LCD16x2 DDRAM (Display Data RAM) addressing. The function of DDRAM is to store character that are displayed on LCD screen. HD44780 controller has 128 different addresses for DDRAM, although not all addresses have their own location on LCD screen. Only 80 display locations can be used to store characters. HD44780 is an LCD controller that can be used not just for size 16×2, but also for other sizes such as 16×4, 20×2, or 40×2. The display location for all LCD size is the same (80 location). The different is number of location that can displayed on screen. For example, on size 16×2, there is only 32 location, but other locations still can be used to store characters, although not displayed. To displayed that, we can shift the display to the right or to the left. This is the address locations of DDRAM that displayed on LCD16x2 whenever the LCD is powered up.

LCD address

Continue reading “LCD16x2 HD44780 Tutorial 3 – Display Address and Shifting”