dolphinlabs
...
Doplhin labs
News

PIC18F4520-LCD Interfacing


ˇ         Program statement:  Interfacing of LCD with PIC18F4520

Connections:  RD0=RS, RD1=RW, RD2=EN

                        PORTB=data lines of LCD

 

Hardware connections for PIC184520 Board:

1.      Give supply to the Board with the help of adapter.

2.      Connect +5V pin of PIC controller to +5v supply and GND pin of controller to GND pin of supply.

3.      Connect +5V pin of LCD to +5V supply and GND pin of LCD to GND pin of supply

4.      Connect data lines of LCD to PORT B of controller.

5.      Connect RS to RD0, RW to RD1 and EN to RD2 pin of controller.

 

 

Program code:

#include<P18F4520.h>

#define lcd PORTB                                             //PORTC =LCD data pins

#define rs PORTDbits.RD0                                //rs=PORTD.0

#define rw PORTDbits.RD1                              //rw=PORTD.1

#define en PORTDbits.RD2                              //en=PORTD.2

 

void lcddata(unsigned char);

void lcdcmd(unsigned char);

void delay(unsigned int);

void main()

{

                TRISB=0;                                                                             //make port C as output

                TRISD=0;                                                                             //make port D as output

                en=0;                                                                                      //enab;e idle low

                delay(250);

                lcdcmd(0x38);                                                     //initialize lcd

                delay(250);

                lcdcmd(0x0e);                                                      //display on,cursor on

                delay(15);

                lcdcmd(0x01);                                                     //clear lcd

                delay(15);

                lcdcmd(0x06);                                                     //shift cursor right

                delay(15);

                lcdcmd(0x80);                                                     //line1,position 6

                delay(15);

                lcddata('D');                                                          //display letter 'D'

                delay(15);

                lcddata('o');                                                           //display letter 'O'

                delay(15);

                lcddata('l');                                                            //display letter 'l'

                delay(15);

                lcddata('p');                                                           //display letter 'p'

                delay(15);

                lcddata('h');                                                           //display letter 'h'

                delay(15);

                lcddata('i');                                                            //display letter 'i'

                delay(15);

    lcddata('n');

                delay(15);                                                             //display letter 'n'

                lcdcmd(0xc0);

                delay(15);

                lcddata('L');

                delay(15);

                lcddata('a');

                delay(15);

                lcddata('b');

                delay(15);

                lcddata('s');

                delay(15);

}

void lcdcmd(unsigned char c)

{

                lcd=c;                                                                                     //put commands on pins

                rs=0;

                rw=0;

                en=1;                                                                                      //strobe the enable pin

                delay(1);

                en=0;

}             

void lcddata(unsigned char d)

{

                lcd=d;

                rs=1;

                rw=0;

                en=1;

                delay(1);

                en=0;

}

void delay(unsigned int k)

{

                unsigned int i,j;

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

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

}

 

 

 

 

 

 

 

 

 

 


Get SOCIAL







SAFE & SECURE SHOPPING

visa card master card maestro card
Maverick IT Industries Pvt. Ltd.