Interfacing PIC18LF4550 to 16x2 LCD

Status
Not open for further replies.

Akhil Mohan

Member level 2
Joined
May 13, 2011
Messages
53
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,731
Hello,

I am trying to interface a PIC18LF4550 with a 16x2 LCD display (h as a JHD162A Processor) in the 4 bit mode. I am using PICkit 2 for programming which loads the hex code in to PIC. I have done some modifications to the code that I got (this code I got it from PyroElectro.com), but, the display shows nothing and am not sure where is the mistake. Could you please help me to resolve this ?

Code:
#include <htc.h>
#include<delays.h>
#include <pic18F4550.h>

#define E_PIN    PORTDbits.RD6   /* PORT for E  */
#define RW_PIN   PORTDbits.RD5   /* PORT for RW */
#define RS_PIN   PORTDbits.RD4   /* PORT for RS */
#define _XTAL_FREQ 20000000
__CONFIG (1, FOSC_HS);
__CONFIG (2, WDTDIS & PWRTEN & BOREN & LVPEN);

void prnt(unsigned int);
void commd(unsigned int);
void lcd_init(void);
void Delay10KTCYx(unsigned char unit); 
void Delay1KTCYx(unsigned char unit);

void main(void)
{

   int count=0;

   int marquee_1 = 0;
   int dir_1 = 0;

   char output[] = " Hello ";
   char output2[] = " World !! ";

   TRISD=0x00;
   PORTD=0x00;

   Delay10KTCYx(200); // After Power On, this instruction will give 16ms delay

   lcd_init();

   while(output[count] != '\0')
   {
   prnt(output[count]);
   count++;
   }

   commd(0b11000000);   //Move 2nd Next Line

   count = 0;
   while(output2[count] != '\0')
   {
   prnt(output2[count]);
   count++;
   }

   commd(0b10000000);

   while(1)
   {

   if(marquee_1 == 0)
      dir_1 = 1;

   if(marquee_1 == 9)
      dir_1 = 0;

   if(dir_1)
        {
      commd(0b00011100);
      marquee_1++;
   }
   else
        {
      commd(0b00011000);
      marquee_1--;
   }

   Delay10KTCYx(200);

   }

}

void lcd_init(void)
{
E_PIN = 0;
RS_PIN = 0;
RW_PIN = 0;

commd(0b00100000); // 

commd(0b00101100); // Function Set

commd(0b00001000); // Display OFF

commd(0b00000001); // Display Clear

commd(0b00000110); // Entry Mode Set
}


//4-bit print interface

void prnt(unsigned int character)
{

PORTD=character >> 4;

RS_PIN = 1;
RW_PIN = 0;
E_PIN = 1;
E_PIN = 0;

PORTD=character & 0x0f;

RS_PIN = 1;
RW_PIN = 0;
E_PIN = 1;
E_PIN = 0;

Delay1KTCYx(200);
//Delay1KTCYx(1); //The Delay Above Is Only To
              //Create The Type-Writer Effect

}


//4-bit instruction interface

void commd(unsigned int commd)
{

PORTD=commd >> 4;
RS_PIN = 0;
RW_PIN = 0;
E_PIN = 1;
E_PIN = 0;

PORTD=commd &0x0f;
RS_PIN = 0;
RW_PIN = 0;
E_PIN = 1;
E_PIN = 0;

Delay1KTCYx(10);

}

Thanks in Advance
Akhil
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…