Interfacing 16X2 LCD Display with STM32 Bluepill Microcontroller
In this post we will learn about connecting LCD Display to STM32f103c8t6 microcontroller, i.e we will be Interfacing 16X2 LCD Display with STM32 Bluepill Microcontroller. The LCD display is an important component while interfacing any sensors and displaying the output value. The 16X2 Alphanumeric display is the most popular display in Embedded Electronics System.
Here we will be programming STM32 via Arduino IDE and uploading the code to STM32 via the bootloader method. You can also upload code using STLink Debugger or USB-TTL Converter. Before starting the LCD & STM32 interfacing you can go through our previous post:
1. Getting Started with STM32 Microcontroller : Blinking of LED
2. STM32 Bootloader: Programming STM32F103C8 Board using USB Port
Components Required
- STM32 Blue Pill Development Board
- 16×2 LCD display
- 10K Potentiometer
- Connecting Wires
C16X2 LCD Display
LCD (Liquid Crystal Display) screen is an electronic display module and finds a wide range of applications. A 16×2 LCD display is a very basic module and is very commonly used in various devices and circuits. A 16×2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5×7 pixel matrix. This LCD has two registers, namely, Command and Data.
The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.
|
Pin No
|
Function
|
Name
|
|
1
|
Ground (0V)
|
Ground
|
|
2
|
Supply voltage; 5V (4.7V – 5.3V)
|
Vcc
|
|
3
|
Contrast adjustment; through a variable resistor
|
VEE
|
|
4
|
Selects command register when low; and data register when high
|
Register Select
|
|
5
|
Low to write to the register; High to read from the register
|
Read/write
|
|
6
|
Sends data to data pins when a high to low pulse is given
|
Enable
|
|
7
|
8-bit data pins
|
DB0
|
|
8
|
DB1
|
|
|
9
|
DB2
|
|
|
10
|
DB3
|
|
|
11
|
DB4
|
|
|
12
|
DB5
|
|
|
13
|
DB6
|
|
|
14
|
DB7
|
|
|
15
|
Backlight VCC (5V)
|
Led+
|
|
16
|
Backlight Ground (0V)
|
Led-
|
Circuit Diagram & Connection
The circuit diagram for interfacing 16X2 LCD Display with STM32 Development Board is given below. Make an exact same connection like this.
Supply 5V to LCD pins 2,15 from 5V pin of STM32
Connect pin 1,5,16 of LCD to GND of STM32
Connect pin 3 of LCD to 10K Pot as shown in above circuit.
Connect pin 4 (RS) of LCD to PB11 of STM32
Connect pin 6 (EN) of LCD to PB10 of STM32
Connect pin 11 (DB4) of LCD to PA4 of STM32
Connect pin 12 (DB5) of LCD to PA3 of STM32
Connect pin 13 (DB6) of LCD to PA2 of STM32
Connect pin 14 (DB7) of LCD to PA1 of STM32
Programming STM32 with LCD using Arduino IDE
There are 6 methods by which you can program STM32 Microcontroller. The methods are:
1. STM32duino Bootloader Method
2. Serial Method
3. By using ST-Link Debugger
4. By BMP (Black Magic Pro)
5. Jlink Method
6. By HID bootloader 2.0
I have used the first method i.e STM32duino bootloader method. By this method, you can directly upload code to STM32 via usb port. But before that, you need to install the bootloader in STM32. To learn more about this method check here: STM32 Bootloader: Programming STM32F103C8 Board using USB Port
You can also use the Serial Method to program STM32 Microcontroller. For this, you need a USB to TTL Converter like FTDI Module to program STM32. Check more about this method here: Getting Started with STM32 Microcontroller : Blinking of LED
Source Code/Program
Here is a code/program for interfacing 16×2 LCD with the STM32 development board. Copy this code to Arduino IDE and upload it by any method mentioned above.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <LiquidCrystal.h> // include the LCD library const int rs = PB11, en = PB10, d4 = PA4, d5 = PA3, d6 = PA2, d7 = PA1; //STM32 Pins to which LCD is connected LiquidCrystal lcd(rs, en, d4, d5, d6, d7); //Initialize the LCD void setup() { lcd.begin(16, 2);//Defining 16*2 LCD lcd.setCursor(0, 0); //LCD Row 0 and Column 0 lcd.print("Interfacing LCD"); //Print this Line lcd.setCursor(0, 1); //LCD Row 0 and Column 1 lcd.print("with STM32 Board"); //Print this Line delay(4000); //wait for four secounds lcd.clear(); //Clear the screen } void loop() { lcd.setCursor(0, 0); //LCD Row 0 and Column 0 lcd.print(" STM32 with LCD "); //Print This Line lcd.setCursor(0, 1); //LCD Row 0 and Column 1 lcd.print(millis() / 1000); //Print the value of secounds } |









1 Comment
What is the difference between Arduino and micro controller, I interfaced Arduino to LCD only 4 data lines, rs, enable but 8051 micro controller I connected all the data lines to 8051 port what is the difference b/w both controllers ??