Skip to playerSkip to main content
Learn how to interface a 16x2 LCD with STM32 in 4-bit parallel mode — no I2C needed!
In this step-by-step tutorial, we’ll configure STM32CubeMX, connect the LCD pins,
and write HAL driver functions to display text, ASCII characters, and scrolling messages.

📂 Download Project Files & Code:
👉 [https://controllerstech.com/interface-lcd-16x2-with-stm32-without-i2c/]

📺 Related Videos:
- I2C LCD with STM32: [https://youtu.be/rfRJGfK2t-A]
- How to write the LCD library: [https://youtu.be/WAGLQOIHEio]
- STM32 Microsecond Delay Tutorial: [https://youtu.be/SqC0IhLKJ9o]
- STM32 Custom Characters on LCD: [https://youtu.be/diwjZPmFUKo]

If you found this helpful, don’t forget to LIKE 👍, SUBSCRIBE 🔔, and SHARE!

STM32 Playlist :::: https://www.youtube.com/playlist?list=PLfIJKC1ud8gga7xeUUJ-bRUbeChfTOOBd

#STM32 #LCD #MicrocontrollerProjects #EmbeddedSystems #Electronics #HAL #CubeMX #IoT #ArduinoAlternative #Microcontrollers #LCDDisplay

________________________________________________________________________________________


Facebook Page : https://www.facebook.com/controllerstech

Telegram Group : https://t.me/controllerstechdiscuss

Instagram : https://www.instagram.com/controllerstech/

For more info, visit https://controllerstech.com

Category

🤖
Tech
Transcript
00:00Hello everyone. Welcome to Controllers Tech. Many of you requested this, so here we are,
00:16interfacing LCD 16x2 with SDM32, but without i2c this time. In parallel connection, LCD can work
00:25in two different modes. 8-bit, and 4-bit mode. In 8-bit mode, we need to use all 8 data pins,
00:35and in 4-bit mode we can use only 4 data pins. We will use 4-bit mode in this tutorial. Let's
00:43start with the cube IDE. Create a new SDM32 project.
00:58I am using F103C8 controller. Give some name to the project, and click Finish.
01:28We have the cube MX here, for the setup. I am enabling the external crystal for the clock.
01:35Enable the serial wire debug. We also need the delay in microseconds, so I am using timer 1 for the same.
01:45If you don't know about microsecond delay, check out the video on the top right corner.
01:50Let's set up the clock first. I want to run the controller at maximum possible frequency, 72 MHz.
02:06The APB2 clock is also at 72 MHz, and timer 1 is connected to APB2. A prescaler of 72 will divide
02:16the clock to 1 MHz. Input the maximum possible value for the ARR, that is 0XFFF, as it is 16-bit register.
02:27As shown in this picture, pins PA1 to PA7 are connected to the LCD. We need to select them as output.
02:36This is it for the setup. Now click save and the project will be generated.
02:49Here is our main .c file.
03:11First of all we need to include the library files.
03:19You can get these files, after you download the project from the link in the description.
03:33There is nothing special in the header file. These are the functions that you can use for the LCD.
03:40We need to modify things in the LCD1602.c file.
03:44My connections is as shown in the picture. From RS to enable pin, and from D4 to D7.
03:54You can use any pin and any port for the connection. Just make sure you define them properly here.
04:10You can use the timer handler.
04:23Define the timer handler, that you are using for the delay.
04:26This function here is an internal function. And it is not defined in the header file.
04:42Send to LCD, is for writing the 4-bit data, or command, to the pins of the LCD.
04:49It takes two parameters. First is the useful data, which is only 4-bit long, and second is the RS.
04:57We update the pins, to the respective bit in the data variable.
05:08RS must be 1 for sending data, and 0 for sending command.
05:13Once the data is written to the pins, we will toggle the enable pin.
05:23This will ensure that the data has been updated successfully.
05:27I am keeping this 20 microseconds delay commented out right now.
05:33We will see if it works without the delay or not.
05:35For higher clocks, this delay must be there.
05:40If the display shows some weird characters, try increasing or reducing this delay.
05:47LCD send command is used, to send the command to the LCD.
05:52As we are only using 4 data pins, our 8-bit command should also be divided into two 4-bit commands.
05:59That's why we need to send the command into two halves, upper nibble, and lower nibble.
06:06Note that RS is 0, to indicate that it's a command.
06:11LCD send data is used to send the data to the LCD.
06:16It uses the same process of sending the upper nibble first, and then lower one.
06:22The RS pin must be high to indicate, that the data is being sent.
06:26This command is used to put the cursor at the entered location.
06:36Row can be 0 or 1, and column can be from 0 to 15.
06:49This function initializes the LCD in the 4-bit mode.
06:52These commands are written as per instructions in the datasheet.
06:58Then you have some display control functions here.
07:02You can modify them if you want some other configuration.
07:06For example if you want the blinking cursor, use C, and V as one in this command.
07:13Let's write the main code now.
07:15First, we need to include the header file.
07:26Make sure you start the timer before initializing the LCD.
07:30Now, I am going to put the cursor at 0, 0, and send some strings to the LCD.
07:41And then, put the cursor at first row, and 0 column.
07:57And then send another string.
07:58I want to wait for 3 seconds, and then clear the display.
08:11Inside the while loop, this function will print the ASCII characters from 1 to 128.
08:17Now, let's flash it.
08:21Build the code.
08:29There are no errors, let's flash it.
08:33Select SDM32 application.
08:36Click OK, and wait for the debugger to launch.
08:54As you can see, the characters are being printed but quite not what we want.
08:58This is happening due to the delay missing in the enable pin strobe.
09:19Let's enable the delay, and flash the code again.
09:22If you face the problem again, try increasing or decreasing this delay.
09:52As you can see, the data is being printed properly.
09:56Let me just reset the controller again.
10:06ASCII characters will continue to print from 0 to 128, every 250 milliseconds.
10:22This is it guys.
10:41I hope you understood the video.
10:44This video was made on demand, as I got many requests for this.
10:49Keep watching.
10:50Have a nice day.
Be the first to comment
Add your comment

Recommended