.post large { float:left; color: $headerBgColor; font-size:100px; line-height:80px; padding-top:1px; padding-right:5px; }

News and Materials Headline Animator

Sunday, June 6, 2010

Program to initialise the LCD in 4 bit mode using PIC microcontroller

It was for 16F72 at 4Mhz written in cc5x. LCD is connected to PORTB.RS at RB7,RW at RB1,EN at RB6. DB7 at RB2,DB6 at RB3, DB5 at RB4, and DB4 at RB5. A function delay_ms() is used , which is not shown here.

code will work for 2x16 character LCD modules.

void lcdw(unsigned char m)
{
PORTB.2=m.7;
PORTB.3=m.6;
PORTB.4=m.5;
PORTB.5=m.4;
en=1;
nop();
nop();
en=0;
}

void nbw(unsigned char m)
{
PORTB.2=m.7;
PORTB.3=m.6;
PORTB.4=m.5;
PORTB.5=m.4;
en=1;
nop();
nop();
en=0;
PORTB.2=m.3;
PORTB.3=m.2;
PORTB.4=m.1;
PORTB.5=m.0;
en=1;
nop();
nop();
en=0;
}

void goadr(unsigned char a)
{

rs=0;
nbw(0x80 + a);
delay_ms(5); // delay of 5msec

}


void main()
{
................

TRISB=0;
PORTB=0;
rw=0;
rs=0;
lcdw(0x28); // lcdw function is only used once to initialise the LCD to 4 bit mode.
delay_ms(5);
nbw(0x28);
delay_ms(5);
nbw(0x0c);
delay_ms(5);
nbw(0x06);
delay_ms(5);
nbw(0x01);
delay_ms(5);
goadr(0x02);
rs=1;
nbw('a'); //displays the character "a" at location 0x02
nbw('b'); //displays the character "b" at location 0x03
.........................


}

No comments:

Post a Comment

Popular Posts

News and Materials

Subscribe Now: Feed Icon

Infolinks In Text Ads

Related Posts with Thumbnails

Latest News

Time