Menu

Custom Search

Microcontroller Program lcd

#include<8051.h>
#define EN P1_2
#define RW P1_1
#define RS P1_0
void lcd_init();
void lcd_status();
void lcd_clr();
void lcd_write(unsigned char*);
unsigned char *pb=(unsigned char xdata*)0x0001;
unsigned char *ctrl=(unsigned char xdata*)0x0003;
unsigned char string[]={'S','U','N','I','L','\0'};
void main()
{


unsigned char *p;
p=string;

*ctrl=0x80; //8255 initialization Port B as output

lcd_init();
lcd_clr();
lcd_write(p);


}
void lcd_init()
{
RS=0; //command mode
RW=0; //write mode
*pb=0x38; //8-bit interface, 2 lines, 5*7 Pixels
EN=1;
EN=0;
lcd_status();
RS=0;
*pb=0x0e; //Turn on visible underline cursor
EN=1;
EN=0;
lcd_status();
RS=0;
*pb=0x06; //move corsor to right most position after each text write on lcd
EN=1;
EN=0;
lcd_status();
}
void lcd_status()
{

do{
EN=0; //start lcd command(do not enable lcd unless u configure other control pins)
RS=0; //it's lcd command
RW=1; //read lcd status
*pb=0xff; //set all pins to 1 initially
EN=1; //clock out command to lcd
}while(P1_7!=0); //P1_7=1/0 lcd busy/lcd free
EN=0; //finished the command
RW=0; //turn off RW for future command i.e. to write on lcd
}
void lcd_clear()
{
RS=0; //it's a command
*pb=0x01; //command value for lcd clear
EN=1;
EN=0;
lcd_status();
}
void lcd_write(unsigned char *c)
{
RS=1;
while(*c!='\0')
{
*pb=*c;
EN=1;
EN=0;
lcd_status(); //wait until lcd is freed and enable RW=0(for writing on lcd)
c++;
}



}

No comments:

Post a Comment