Drive LCD 16x2 with 4pin, Without I2C on STM32F407VG discovery board but you can use it for other microcontrollers.
attention: some unused peripheral are modified.
ALL YOU NEED IS THIS TWO PERIPHERALS:
- Timer (I wrote it for TIM1 with this settings.)
- GPIO
All pins are set on GPIOE:
d7 -> pin 15 as D7_Pin
d6 -> pin 14 as D6_Pin
d5 -> pin 13 as D5_Pin
d4 -> pin 12 as D4_Pin
E -> pin 11 as E_Pin
RS -> pin 10 as RS_Pin
RW -> pin 9 as RW_Pin
Send some command to LCD for turn LCD On and responsible and select 4pin Mode.(READ about commands in datasheet)
Because we use 4pin mode we should split our character ASCII HEX to 4 highbit and 4 lowbit.
Then sending 4 highbit and 4 lowbit of character to LCD_send function with rs = 0
(for sending data we need rs = 0, more information in LCD_send)
Work like LCD_send_data but with rs = 1
At first we define RS_Pin with function rs
input
RS_Pin must be 0 for sending data
RS_Pin must be 1 for sending data
In this step, char
is 4 bit, so we send it by set our 4 Data Pin(D4-D7), 1 or 0.
After that we set E_Pin, 1, to say to LCD that we sending data, read the pins! and give LCD some time, then set E_Pin to 0.
This function get a string, select string characters and send them to LCD_send_data function.
Select curser location with command.(READ datasheet to know how it works)
Send Clear-Screen command to LCD and give LCD some time.