Sunday 19 July 2015

Lesson 6 LCD Scrolling Display With PIC 16F877A (MikroC)

In the previous tutorial, we talked about a 2x16 LCD, the number of pins it has and their various functions. We also discussed on its different connection mode. Do well to go through the previous tutorial (Lesson 5 MikroC) to get acquainted with it.
Here we are going to create a Scrolling Message on an LCD, which is very easy to achieve given the rich set of Library functions in MikroC. Lets get started with the program.

MikroC Code:

/**********************************
Project Name :
   Scrolling display with LCD
Author : Promise
Description :
   This project demonstrate how to Make scrolling Message on an LCD
Test configuration:
   MCU:  PIC 16F877A
   Oscillator: XT 8.0000 MHz, 8.0000 MHz Crystal
***********************************/

// Lcd pinout settings
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections

char txt[] = "WELCOME TO OUR..." ;
char txt1[] = "BLOG!!!" ;
char txt2[] = "www.mechatronicsandyou.blogspot.com" ;


void main() {

 Lcd_Init();                        // Initialize LCD

  Lcd_Cmd(_LCD_CLEAR);          // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);     // Cursor off

Lcd_Out(1,1,txt);              // output display
Lcd_Out(2,6,txt1);
delay_ms(3000);

Lcd_Cmd(_LCD_CLEAR);          // Cursor off

Lcd_Out(1,1,txt2);            // output display
   delay_ms(500);
 
while(1){                     //endless loop
 Lcd_Cmd(_LCD_SHIFT_LEFT);    // shift display to left
 delay_ms(100);
   }
 }


Proteus Schematic:

   
Scrolling display with LCD in 4 bits mode

2 comments:

  1. pls i want the codes that make the upper text stable or fixed and make the lower text continuously move. thanks toby lee

    ReplyDelete
    Replies
    1. this can be achieved using a for loop. The Lcd scroll command will shift everything on the dislpay.

      /*
      remember to include the lcd module connections in the code. its shown in the original post and also check lcd under the library manager. this code worked with the message i wanted to scroll. Adjust the for loop parameters to be able to scroll the message you want to display. i= 16 because only the 1st 16 characters are visible on 16x2 lcd. */

      void main(){
      ANSELB = 0; // Configure AN pins as digital I/O

      C1ON_bit = 0; // Disable comparators
      C2ON_bit = 0;

      Lcd_Init(); // Initialize LCD
      Lcd_Cmd(_LCD_CLEAR); // Clear display

      while(1){

      Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
      Lcd_Out(1,1,"text to be displayed on 1st row"); // Write text in first row

      for(i=16;i>0;i--){

      Lcd_Out(2,i,"text to be displayed on 2nd row");
      Delay_ms(500);
      Lcd_Cmd(_LCD_CLEAR);
      Lcd_Out(1,1,"text to be displayed on 1st row");

      }

      }
      }

      Delete