SCROLLING TEXT ON LCD USING PIC MICROCONTROLLER: We can display any text on LCD using PIC microcontroller. Now in this tutorial we will examine how to scroll that display. It’s very easy because we just need to know how to effectively use LCD commands. We can use any type of LCD like 16×2, 8×1, 16×4, 8×2, 16×1, 20×1, 20×2 etc.
LCD PIN DIAGRAM:
LCD PIN DISCRIPTION:
Pin 1 GND (0v)
Pin 2 Vcc (5v)
Pin 3 VEE (contrast adjustment through variable resistor)
Pin 4 RS (command register when low, data register when high)
Pin 5 R/W (high for read from register, low for write to the register)
Pin 6 EN (sends data to data pins when high to low pulse is given)
Pin 7-14 DB0-DB7 (8-bit data pins)
Pin 15 LED+ (backlight, Vcc 5v)
Pin 16 LED- (backlight, GND 0v)
Scrolling text on LCD on using pic microcontroller
In the interfacing of LCD with PIC MCU, the MCU used is PIC 16F877A and 16×2 display LCD is LM016L. 5Kohm variable resister is used for contrast adjustment. In this tutorial we will use 4 data pins [D4-D7]. Some LCD library functions are already discussed in tutorial of interfacing LCD with PIC MCU. Now only those functions will be discussed which are mentioned in our code.
Library for scrolling text on LCD
Lcd_Init: Initializes LCD module.
Lcd_Out: voidLcd_Out(row, column, text);
Prints text on LCD starting from specified position. Both string variables and literals can be passed as a text.
Parameters:
- row:starting position row number
- column:starting position column number
- text:text to be written
Lcd_Cmd: Sends command to LCD.
- Lcd_Cmd(_LCD_CLEAR): To Clear the LCD
- Lcd_Cmd(_LCD_CURSOR_OFF): This function is used for setting the cursor off.
- Lcd_Cmd(_LCD_SHIFT_RIGHT): This function is used for shifting on the right hand side.
- Lcd_Cmd(_LCD_SHIFT_LEFT): This function is used for shifting on the left hand side.
- Lcd_Cmd(_LCD_RETURN_HOME): Return cursor or a shifted display to its to home position.
Before initialization of LCD, this interfacing requires pin out settings and pin directions.
- RS pin of LCD is connected to RD6 of microcontroller.
- EN pin of LCD is connected to RD7 of microcontroller.
- R/W of LCD is connected to ground for write operation.
- D4-D7 of LCD is connected to RB4-RB7 of MCU for data transfer.
SCHEMATIC DIAGRAM of scrolling text on LCD
Video results of scrolling text on LCD
CODE of scrolling text on LCD
EXAMPLE 1:
// Lcdpinout settings
sbit LCD_RS at RD6_bit; sbit LCD_EN at RD7_bit; sbit LCD_D7 at RB7_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D4 at RB4_bit; // Pin direction sbitLCD_RS_Direction at TRISD6_bit; sbitLCD_EN_Direction at TRISD7_bit; sbit LCD_D7_Direction at TRISB7_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB4_bit; void main() { unsignedinti,j; char text1[]={" www.Microcontrollerslab.com!"}; char text2[]={"Electronics"}; Lcd_Init(); Lcd_Out(1, 7, "Hello!"); // Write text in first row, seven column delay_ms(500); delay_ms(500); Lcd_Cmd(_LCD_CLEAR); // clear the text while(1) { for(i=0;i<15;i++) { Lcd_Out(1,1,text1); // Write text in first row, first column Lcd_Cmd(_LCD_SHIFT_RIGHT); // Move text to the right 14 times delay_ms(200); //shifting speed } Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Cmd(_LCD_RETURN_HOME); // returning to home position for(j=0;j<15;j++) { Lcd_Out(2,2,text2); // Write text in second row, second column Lcd_Cmd(_LCD_SHIFT_RIGHT); // Move text to the right 14 times delay_ms(200); //shifting speed } delay_ms(500); Lcd_Cmd(_LCD_RETURN_HOME); delay_ms(500); } }
OUTPUT of scrolling text on LCD
- This program firstly writesMicrocontrollerslab.com in first row first column.
- Then it shifts the display right without changing data.
- After that it returns the shifted display to its original position or home.
- It again writes Electronics in second row second column.
- Shifts the whole display right without changing data.
- Return to home and then again shift display. While loop goes on.
EXAMPLE 2 OF Scrolling text on LCD
// Lcdpinout settings
sbit LCD_RS at RD6_bit; sbit LCD_EN at RD7_bit; sbit LCD_D7 at RB7_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D4 at RB4_bit; // Pin direction sbitLCD_RS_Direction at TRISD6_bit; sbitLCD_EN_Direction at TRISD7_bit; sbit LCD_D7_Direction at TRISB7_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D4_Direction at TRISB4_bit; void main() { unsignedinti,j; char text1[]={" www.Microcontrollerslab.com!"}; Lcd_Init(); Lcd_Out(1, 7, "Hello!"); // Write text in first row, seven column delay_ms(500); delay_ms(500); Lcd_Cmd(_LCD_CLEAR); // clear the text while(1) { for(i=0;i<20;i++) { Lcd_Out(1,1,text1); Lcd_Cmd(_LCD_SHIFT_RIGHT); // Move text to the right 19 times delay_ms(200); } Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off for(j=0;j<20;j++) { Lcd_Cmd(_LCD_SHIFT_LEFT); // Move text to the left 19 times delay_ms(200); } delay_ms(500); delay_ms(500); } }
OUTPUT of second example with scrolling text on LCD
- This program firstly writes Microcontrollerslab.com in first row first column.
- Then it shifts the display right without changing data.
- Now shifts the whole display left without changing data.
- Again shifts display towards right and While loop goes on.
A really useful explanation how about if we want to control the position of the cursor
in above circuit diagram or in code crystal frequency details are not seem