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 .......
Bellsouth email not receiving mails
ReplyDeleteApple 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.
ReplyDeleteOneDrive Customer support number provides the best services and I just need help and to fix your problem OneDrive Customer support number.
ReplyDeleteOneDrive Customer support number provides the best services and I just need help and to fix your problem OneDrive Customer support number USA Canada.
ReplyDeleteApple pay refund support number provides the best services and I just need help and to fix your problem Apple pay refund support number.
ReplyDeleteApple pay customer service number provides the best services and I just need help and to fix your problem Apple pay customer service.
ReplyDeleteHitmanpro Customer Service Number
ReplyDeleteCCleaner Pro Customer Care Number
ReplyDeleteCCleaner Pro Customer Care Number
ReplyDeleteCCleaner Pro Customer Service Number
ReplyDeleteHitmanpro Customer Support Number
ReplyDeleteHitmanpro Customer Care Number
ReplyDeleteHitmanpro Customer Service Number
ReplyDeleteKaspersky Antivirus support remote support
ReplyDeleteAdobe support photoshop user guide
ReplyDelete