programming LCD in 4 bit mode using 8051 | code explanation | 8051 in ta...





code:-

#include<reg51.h>

sbit rs=P3^5;

sbit e= P3^4;

sbit rw=P3^6;

void cmdwrt_lcd(char);

void datas(char);

void delay(unsigned int);

void lcd_init();

void display_lcd(unsigned char *lcdstr);

void main()

{

lcd_init();

display_lcd("AbCdEfGh");

cmdwrt_lcd(0xc0);

display_lcd("Corona break");



while(1);

}

void lcd_init()

{

cmdwrt_lcd(0x02);

cmdwrt_lcd(0x28);

cmdwrt_lcd(0x0C);

cmdwrt_lcd(0x01);  

cmdwrt_lcd(0x80);

}





void cmdwrt_lcd( char com)

{

P1=(com & 0xF0);

rs=0;

rw=0;

e=1;

delay(5);

e=0;

delay(10);

P1 = ((com<<4) & 0xF0);

e=1;

delay(5);

e=0;



}

void datas( char dat)

{

P1=(dat & 0xF0);

rs=1;

rw=0;

e=1;

delay(5);

e=0;

delay(10);

P1 = ((dat<<4) & 0xF0);

e=1;

delay(5);

e=0;

}



void delay(unsigned int time)

{

unsigned int i,j;

for(i=0;i<time;i++)

for(j=0;j<1024;j++);

}

void display_lcd(unsigned char *lcdstr)

{

    while (*lcdstr !='\0')

{

datas(*lcdstr);

lcdstr++;

}

}

Comments