SCROLLING TEXT ON LCD USING PIC MICROCONTROLLER|Mikro C (original) (raw)

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:

scrolling text on lcd

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:

Lcd_Cmd: Sends command to LCD.

Before initialization of LCD, this interfacing requires pin out settings and pin directions.

SCHEMATIC DIAGRAM of scrolling text on LCD

scrolling text on lcd using pic microcontroller

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

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