Skip to main content

Tutorial for Scroll text on 16x2 LCD with 8051 Microcontroller in c

In our last tutorial we interface 2x16 LCD with 8051 in assembly, now lets display some scrolling text on LCD. it is very useful because generally we have a long text to display and a 2x16 LCD display only 16 character at a time.


if you don't know about LCD interfacing and  how it is display character on different address then plz read my last tutorial in which  i talk about LCD in detail.

i use keil to compile my code and simulate it in multisim (my fav.). you can you any simulator with hex file  but code is written in keil so c program file may not run in other compiler.

the concept here i use is that after writting 16 character to LCD i move my text to the left side one character at a time and then write next character.
command 18h is used to move text left ( if don't know please read last tutorial )

i connect my data line of LCD to port P1 and 3 control lines to port P2. as
RW-to pin P2.0
RS- to pin P2.1
EN-to pin P2.2 // change according your design 


as our last tutorial LCD interfacing with 8051 we need to subrouting ( functions ) also in C to send command and data.
command sending function:
//..............cmd.......................
void lcd_cmd(unsigned char cmd){
 
rs=0;           // rs is low means we are sending command to LCD
P1=cmd;
en=1;
delay(1);
en=0;
}
//here cmd is variable which get value command and pass to port P1, and rs, en are the command pins.

data sending function:
//............data...........................
void lcd_display(unsigned char text){
        rs=1;       //high means we are sending text to display on LCD  
P1=text;
en=1;
delay(1);
en=0;
}

now we need to initialize to LCD to get required result like cursor on/off, cursor moving direction etc..
LCD initialization:
//................init...................
void lcd_init(void ){
 
lcd_cmd(0x30); //selecting 8 bit mode, single line, and 5x7 font read more
lcd_cmd(0x0c); //for display on,cursor off and  blinking also off
lcd_cmd(0x06);//cursor position auto increment and move cursor to right
}

some code to clear LCD
//............clear..............
void lcd_clear(void){
   lcd_cmd(0x01);
}
now the main part of tutorial to scroll text.
//.............main...............

void main(void ){
unsigned char i,loc=0x80;
rw=0;                                             //we are writing to LCD 
lcd_clear();                           //clear
lcd_init();                          //initialize LCD
        for(i=0;text[i]!='\0';i++){  //reading  array character by charcter
loc++;                                                   // increment LCD address by one   
lcd_display(text[i]);              //sending text to display on port 
if(loc>=0x8f)   // this is the logic that we move text to left side after we reached at 
lcd_cmd(0x18);  // location 8fh which is last address on lcd in  first line
}
 


}

the whole program are like this
//..........................................LCD scrolling.............................................................
#include<REGX51.H>
#define rw P2_0  //read write pin
#define rs P2_1  // data/command pin
#define en P2_2 //enable pin

void lcd_init(void );
void lcd_cmd(unsigned char );
void delay(unsigned int );
void lcd_display(unsigned char);
void lcd_clear(void );
const unsigned char text[]={"electronets.blogspot.com | scrolling test on LCD  "}; 

void main(void ){
unsigned char i,loc=0x80;
rw=0;
lcd_clear();
lcd_init();
for(i=0;text[i]!='\0';i++){
loc++;
lcd_display(text[i]);
if(loc>=0x8f)
lcd_cmd(0x18);
}
 
}
void lcd_clear(void){
  
  lcd_cmd(0x01);
}
void lcd_init(void ){
 
lcd_cmd(0x30);
lcd_cmd(0x0c);
lcd_cmd(0x06);
}

void lcd_cmd(unsigned char cmd){
 
rs=0;
P1=cmd;
en=1;
delay(1);
en=0;
}

void lcd_display(unsigned char text){

rs=1;
P1=text;
en=1;
delay(1);
en=0;
void delay(unsigned int time){
unsigned int i,j;
for (i=0;i<time;i++)
for(j=0;j<1275;j++); 
}
this is the our scrolling LCD, i hide .c , .hex file and multisim simulation file behind this image. to get files download image and rename it to a ".rar" file or open it with winRaR.

click to zoom
 thanx for  comming and please share it if you like this .......

Comments

  1. Apple Pay supports most major credit and debit cards providers including Visa, MasterCard and American Express. Apple's Apple Card is also supported, unsurprisingly. I just need help and to fix apple pay contact Apple pay customer service number.

    ReplyDelete
  2. OneDrive Customer support number provides the best services and I just need help and to fix your problem OneDrive Customer support number.

    ReplyDelete
  3. OneDrive Customer support number provides the best services and I just need help and to fix your problem OneDrive Customer support number USA Canada.

    ReplyDelete
  4. Apple pay refund support number provides the best services and I just need help and to fix your problem Apple pay refund support number.

    ReplyDelete
  5. Apple pay customer service number provides the best services and I just need help and to fix your problem Apple pay customer service.

    ReplyDelete

Post a Comment

Popular posts from this blog

Multiplex 4 Seven Segment Display With 8051 In Assembly

Multiplexing is very essential part while working with 8051 because of its limited number of ports. which offer 32 pins for connecting external devices. 32 seems large but when you working with seven segment, keypad, LCD, ADC etc. or if you project have many parts to operate simultaneously then you definitely need to multiplex some of ports.

LCD Interfacing with 8051 in 4 bit mode : assembly tutorial

Hello friends, in this tutorial we are going to interface LCD with 8051 microcontroller but in 4 bit mode. we already interfaced LCD with 8051 in 8 bit and also done scrolling of text in previous tutorials.

how to get 7805 in multisim - Replacement of 7805 in multisim

  finding some parts in multisim is really tough work because multisim  not provide all general purpose component like 7085 and other voltage regulator. one more  bad information is that manufacturer of these component also not provide any PSPICE because output of these component are predetermined and not changed according to the circuit.