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

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

.........................

}



Related articles

version control system for keil & MPLAB.
PWM with 89S52
A microprocessor Program to convert BCD pack and Unpack number for 8085.
LED blinking program for Pic microcontroller
C Programming Options in AVR


For best business class hosting read InMotion Reviews and get a good web hosting deal.