Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing PIC18LF4550 to 16x2 LCD

Status
Not open for further replies.

Akhil Mohan

Member level 2
Member level 2
Joined
May 13, 2011
Messages
53
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Visit site
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 have done some modifications to the code that I got from PyroElectro.com, but, the display shows nothing and am not sure where is the mistake. Could you please help me to resolve this ?

Interface of PIC to LCD.png

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
 

1. Keep RW always low
2. Insert small delay between Enable signal high to low.
3. After each write command or data insert some ms delay. At start keep this delay high. After working u may reduce it.
 

hello,

Your wiring is abfull !
why mixing bits for LCD data ?
use a quartet of bits for the LCD DATA ie: RD0..RD3 or RD4..RD7
and other bits for LCD control..


Your LCD init sequence is wrong ....
there is plenty of example on this forum ...for a good LCD Init. in 4 bits mode.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top