16×2 lcd in 4-bit mode with pic microcontroller – Project requirements
- 16×2 character lcd.
- Pic 16f877.
- Potentiometer (For setting lcd contrast).
- Crystal(20MHz).
- Connecting wires.
- Bread board or PCB for the circuit.
- Power Supply.
16×2 lcd in 4-bit mode
In 4-bit mode only 4-bit data is send to lcd at a time. Since 8-bit microcontrollers contains data in 8-bit form so we divide our data in to two nibbles(1-nibble=4-bits). First higher 4-bits(nibble) is send to lcd and then the lower 4-bits(nibble) with enable stroke signal. Only D4,D5,D6,D7 data pins of 16×2 lcd are used in 4-bit interface mode. D1,D2,D3,D4 are left empty. D4 is our least significant bit and D7 is highest significant bit in 4-bit interface mode. A typical interfacing diagram is given at the right side.
|
Interfacing 16×2 Lcd with pic microcontroller in 4-bit mode – Project circuit diagram
Taking the upper tutorial will led you know how 16×2 lcd works & how to configure it.The circuit diagram of the project is given below.
Interfacing 16×2 lcd in 4-bit mode with pic microcontroller- Project code
Some functions and their working.
It is assumed that you know all about operators like (>>,& etc) and their functions.
lcdcmd()
- This function is sending high and low bytes of a command one by one to llcdcmd() function.
- The statement llcdcmd(c>>4); is moving our high Byte (four high bits) to right and then sends them to llcdcmd function.
- The statement llcdcmd(c); is sending our low Byte(four low bits) to llcdcmd function.
display()
- This function is also working in the same way as lcdcmd(). The difference is it is sending data to ddisplay() function.
llcdcmd()
This function is separating four bits from our command and puts them on RB0,RB1,RB2,RB3 line and then sends them to lcd. The following instructions are separating four bits.
RB0=(value >> 0) & 0x01;
RB1=(value >> 1) & 0x01;
RB2=(value >> 2) & 0x01;
RB3=(value >> 3) & 0x01;
ddisplay()
This function is separating four bits from our 8-bit data and puts the 4-bit data on RB0,RB1,RB2,RB3 pins and then sends them to lcd. Following instructions are separating four bits.
RB0=(value >> 0) & 0x01;
RB1=(value >> 1) & 0x01;
RB2=(value >> 2) & 0x01;
RB3=(value >> 3) & 0x01;
If you dont know what is meant by commands and data send to 16×2 lcd here is a simple tutorial.
In the main function i first called lcdint() function. This function is initializing our lcd. Refer to the data sheet of lcd if you dont know what is lcd initialization. Then i am sending data to 16×2 lcd which i want to display on lcd screen. I am displaying word “Microcontroller” on lcd display screen.
Filed Under: Microcontroller Projects, PIC Microcontroller
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.