Since there is no predefined libraries to rotate a single row of an LCD we need to do it with our own functions.
I have written such function using this function u can
- Rotate any of the two row
- Rotate left or right
A sample program and its header file is given below
#include<lcd.h>
void main()
{
char *r1="LCD ROW ONE";
char *r2="LCD ROW TWO";
init_8bit();
hide_cursor;
string_8bit(r1);
xy_8bit(1,1);
string_8bit(r2);
clear_8bit(0,0); //clear_8bit(row,column)
delay(100);
while(1)
{
rotate(r2,1,'r'); //rotate("string",which row(0,1),which dir('r' ||'l'))
}
}
The Source code requires <lcd.h> header file which is defined below
#include<reg51.h>
#include<string.h>
#define hide_cursor cmd_8bit(0x0c)
#define interface_8bit
sbit RS=P3^3;
sbit RW=P3^4;
sbit EN=P3^5;
sfr lcdport=0x90;
void cmd_8bit(unsigned char);
void disp_8bit(unsigned char);
void xy_8bit(unsigned char,unsigned char);
void clear_8bit(unsigned char,unsigned char);
void rotate(char *,unsigned char ,unsigned char );
void rotate_right(char *,unsigned char);
void rotate_left(char *,unsigned char);
void cmd_4bit(unsigned char);
void disp_4bit(unsigned char);
void xy_4bit(unsigned char,unsigned char);
void delay(unsigned char);
void init_8bit();
void init_4bit();
void string_8bit(char *);
#ifdef interface_8bit
void cmd_8bit(unsigned char c)
{
lcdport=c;
RS=0;
RW=0;
EN=1;
delay(1);
EN=0;
}
void disp_8bit(unsigned char d)
{
lcdport=d;
RS=1;
RW=0;
EN=1;
delay(1);
EN=0;
}
void string_8bit(char *s)
{
while(*s!='\0')
{
disp_8bit(*s);
s++;
}
}
void init_8bit()
{
cmd_8bit(0x38);
cmd_8bit(0x0e);
cmd_8bit(0x80);
cmd_8bit(0x06);
cmd_8bit(0x01);
}
void xy_8bit(unsigned char r,unsigned char c)
{
if(r==0)
cmd_8bit(0x80+r);
else
cmd_8bit(0xc0+c);
}
void clear_8bit(unsigned char r,unsigned char c)
{
if(r)
{
cmd_8bit(0x80+(r-1));
disp_8bit(' ');
}
if(c)
{
cmd_8bit(0xc0+(c-1));
disp_8bit(' ');
}
}
void rotate(char *s,unsigned char r,unsigned char dir)
{
unsigned char row;
char *space=" ";
char result_string[50];
strcpy(result_string,space);
strcat(result_string,s);
strcat(result_string,space);
if(r==0)
row=0x80;
else
row=0xc0;
if(dir=='r')
rotate_right(result_string,row);
else
rotate_left(result_string,row);
}
void rotate_right(char *s,unsigned char row)
{
int i;
for(i=0;i<(strlen(s)+1);i++)
{
cmd_8bit(row);
string_8bit(s+i);
delay(1);
}
}
void rotate_left(char *s,unsigned char row)
{
int i;
for(i=0;i<(strlen(s)+1);i++)
{
cmd_8bit(row);
string_8bit(s+strlen(s)-i);
delay(1);
}
}
#else
void init_4bit()
{
cmd_4bit(0x02);
cmd_4bit(0x28);
cmd_4bit(0x0E);
cmd_4bit(0x80);
cmd_4bit(0x06);
}
void cmd_4bit(unsigned char c)
{
RS=0;
lcdport=(c&0xf0);
EN=1;
delay(100);
EN=0;
lcdport=(c&0x0f)<<4;
EN=1;
delay(100);
EN=0;
}
void disp_4bit(unsigned char d)
{
RS=1;
lcdport=d&0xF0;
EN=1;
delay(100);
EN=0;
lcdport=(d&0x0F)<<4;
EN=1;
delay(100);
EN=0;
}
void string_4bit(char *s)
{
RS=1;
while(*s!='\0')
{
disp_4bit(*s);
s++;
}
}
void xy_4bit(unsigned char r,unsigned char c)
{
if(r==0)
cmd_4bit(0x80+c);
else
cmd_4bit(0xc0+c);
}
#endif
void delay(unsigned char d)
{
int i;
TMOD=0x01;
for(i=0;i<d;i++)
{
TH0=0xee;
TL0=0x00;
TR0=1;
while(TF0==0);
TR0=0;
TF0=0;
}
}
If there is any updation with my code please let me know
through your comments
No comments:
Post a Comment