Menu

Custom Search

Microcontroller Program lcd

#include<8051.h>

#define EN P1_2
#define RW P1_1
#define RS P1_0

#define lcd_data P3

void lcd_cmd(unsigned char);
void lcd_status();
void lcd_write(unsigned char);
void delay();
void delay1();


void main()
{

lcd_cmd(0x38);//8-bit interface, 2 lines, 5*7 Pixels
lcd_cmd(0x38);
lcd_cmd(0x0e);//Turn on visible underline cursor
lcd_cmd(0x06);//move corsor to right most position after each text write on lcd
lcd_cmd(0x01);//clear lcd
while(1)

{

lcd_write('E');
delay1();
lcd_write('n');
delay1();
lcd_write('d');
delay1();
lcd_write(' ');
delay1();
lcd_write('t');
delay1();
lcd_write('o');
delay1();
lcd_write(' ');
delay1();
lcd_write('e');
delay1();
lcd_write('n ');
delay1();
lcd_write('d');
delay1();
lcd_write(' ');
delay1();
lcd_write('c');
delay1();
lcd_write('o');
delay1();
lcd_write('m');
delay1();
lcd_write('-');
delay1();
delay();

lcd_cmd(0xc0);//go to next line
delay1();
lcd_write('m');
delay1();
lcd_write('u');
delay1();
lcd_write('n');
delay1();
lcd_write('i');
delay1();
lcd_write('c');
delay1();
lcd_write('a');
delay1();
lcd_write('t');
delay1();
lcd_write('i');
delay1();
lcd_write('o');
delay1();
lcd_write('n ');
delay1();
lcd_write('!');
delay1();
lcd_write(' ');
delay1();
lcd_write(' ');
delay1();
delay();
delay();
lcd_cmd(0x01);




}
}

void lcd_cmd(unsigned char s)
{
RS=0; //command mode
RW=0; //write mode
lcd_data=s;
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
lcd_data=0xff; //set all pins to 1 initially
EN=1; //clock out command to lcd
}while(P3_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_write(unsigned char c)
{
RS=1;
lcd_data=c;
EN=1;
EN=0;
lcd_status(); //wait until lcd is freed and enable RW=0(for writing on lcd)
}

void delay()
{
unsigned int a;
for(a=0;a<65000;a++);
}

void delay1()
{
unsigned int a;
for(a=0;a<35000;a++);
}

No comments:

Post a Comment