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.

[SOLVED] lcd interfacing with PIC18f4550 Problem

Status
Not open for further replies.

MrSingh

Newbie level 5
Newbie level 5
Joined
Mar 21, 2014
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
69
Hi
i am interfacing LCD(JHD162a) with pic 18f4550 uC but instead of showing the desired output the there are black boxes on the 1st line of lcd .
the code is working well in the Proteus Software
i am using mikroC with 4MHz crystal programmer is pickit2
the code is

Code:
sbit LCD_RS at RE0_bit;
sbit LCD_EN at RE2_bit;
sbit LCD_D0 at RD0_bit;
sbit LCD_D1 at RD1_bit;
sbit LCD_D2 at RD2_bit;
sbit LCD_D3 at RD3_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D4 at RD4_bit;

// Pin direction
sbit LCD_RS_Direction at TRISE0_bit;
sbit LCD_EN_Direction at TRISE2_bit;
sbit LCD_D7_Direction at TRISD7_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D3_Direction at TRISD3_bit;
sbit LCD_D2_Direction at TRISD2_bit;
sbit LCD_D1_Direction at TRISD1_bit;
sbit LCD_D0_Direction at TRISD0_bit;
void ibusy()
{
TRISD=0xFF;
   LATE2_bit=1;
   LATE0_bit=0;
      LATE1_bit=1;
      while(LCD_D7)
      {
          LATE2_bit=0;

    //Delay_ms(50);
        LATE2_bit=1;
      }
      TRISD=0x00;
}

 void lcmd(char xy)
 {     ibusy();
  LATD=xy;
      LATE0_bit=0;
      LATE1_bit=0;
       LATE2_bit=1;

 Delay_ms(20);
        LATE2_bit=0;
     Delay_ms(40);
    // Delay_ms(100);
 }
  void ldata(char xy)
 {   ibusy();
 LATD=xy;
      LATE0_bit=1;
      LATE1_bit=0;
       LATE2_bit=1;

  Delay_ms(20);
        LATE2_bit=0;
     Delay_ms(40);
  // Delay_ms(100);
 }

 void lcdinit()
  {    Delay_ms(10000);
  lcmd(0x38);  //
  Delay_ms(1000);
lcmd (0x0C);     //
 Delay_ms(1000);
lcmd(0x01);        //
Delay_ms(1000);
lcmd(0x06);       //
 Delay_ms(1000);
lcmd(0x80);     //
 Delay_ms(1000);
 }
   void icmd(char xy)
 {     //ibusy();
  LATD=xy;
      LATE0_bit=0;
      LATE1_bit=0;
       LATE2_bit=1;

 Delay_ms(20);
        LATE2_bit=0;
     Delay_ms(40);
    // Delay_ms(100);
 }
 void init()
  {    Delay_ms(10000);
  icmd(0x38);  //
  Delay_ms(1000);
    icmd(0x38);  //
  Delay_ms(1000);
    icmd(0x38);  //
  Delay_ms(1000);
lcmd (0x08);     //
 Delay_ms(1000);
lcmd(0x01);        //
Delay_ms(1000);
lcmd(0x06);       //
 Delay_ms(1000);
lcmd(0x80);     //
 Delay_ms(1000);
 }
void main() {
  TRISD=0x00;
  LATD=0x00;

  TRISE=0x00;    LATE=0x00;
   init();
    lcmd (0x0F);    //  Delay_ms(1000);
    ldata('E');
    
}
lcdpro.jpgWP_20140317_011.jpg

i would to get help from the members of this forum to help me solve this problem
 

You have to Connect a POT (wiper pin) to VEE pin of LCD. POT's other 2 pins will be connected to +5V and GND respectively. Use 5k POT/Preset. Why you want to use 8 bit LCD when mikroC has 4-bit LCD library available?
 

i have connected the Pot to vee pin but the results were same .
i had used the 4bit library but the lcd was not working so i have written the code refering various tutorials on the internet and i have found 8bit easier to program & also the h/w design i will be using is also 8 bit
 

Reduce all delays in LCD related functions to 50 ms. 1 sec delays are too high.

In busy function you are making whole PORTD as input port. Don't do that. Are you setting PORTD as output port after busy function?

For 18F devices you have to use LATx instead of PORTDx or RDx (also applies for other ports used as output port).

Replace these


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
sbit LCD_RS at RE0_bit;
sbit LCD_EN at RE2_bit;
sbit LCD_D0 at RD0_bit;
sbit LCD_D1 at RD1_bit;
sbit LCD_D2 at RD2_bit;
sbit LCD_D3 at RD3_bit;
sbit LCD_D7 at RD7_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D4 at RD4_bit;



with


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
sbit LCD_RS at LATE0_bit;
sbit LCD_EN at LATE2_bit;
sbit LCD_D0 at LATE0_bit;
sbit LCD_D1 at LATD1_bit;
sbit LCD_D2 at LATD2_bit;
sbit LCD_D3 at LATD3_bit;
sbit LCD_D7 at LATD7_bit;
sbit LCD_D6 at LATD6_bit;
sbit LCD_D5 at LATD5_bit;
sbit LCD_D4 at LATD4_bit;



i had used the 4bit library but the lcd was not working

Replacing PORTxx or Rxx_bit in LCD defines with LATxx will make it work.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top