[SOLVED] Pic lcd interface not working

Status
Not open for further replies.

burrow

Full Member level 2
Joined
Dec 15, 2014
Messages
147
Helped
3
Reputation
6
Reaction score
3
Trophy points
18
Visit site
Activity points
1,148
Well, i ran into a problem which many other beginners face while interfacing pic with lcd. i googled and checked solution given in all forums and i cant still get it to work.

Iam using pic18f4520.
The lcd iam using is JHD162A.

My Mikroc program to check lcd is
Code:
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RD2_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC0_bit;
sbit LCD_D7 at RC1_bit;
sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISD2_bit;
sbit LCD_D4_Direction at TRISD0_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC0_bit;
sbit LCD_D7_Direction at TRISC1_bit;

void main() {

TRISB=0b00000000;

Delay_ms(100); 
Delay_ms(100);   
Delay_ms(100);
 
Delay_ms(100);
Delay_ms(100);
 Delay_ms(100);

 Lcd_Init(); // Initialize LCD

 Delay_ms(100);        
 Delay_ms(100);
Delay_ms(100);

 Lcd_Cmd(_LCD_CLEAR); // Clear display


    Delay_ms(100);
    PORTB=0b11111111;
    
    

            while(1)
            {
     Lcd_Out(1,3,"Helllooooo");

      PORTB=0b00000000;
 Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
   Delay_ms(100);
      Delay_ms(100);         Delay_ms(100);

       PORTB=0b11111111;
            Delay_ms(100);         Delay_ms(100);
      Delay_ms(100);


}
}

I tried with many combination of delays etc.
Wiring is okay, i checked the connection twice or thrice . Connection sees alright.
but i see only boxes.

iam using pic internal oscillator, and frequency iam using is 4mhz
I am using pot for contrast pin.

And yea lcd is working with other pic.
 

For PIC18F you have to use LATx instead of PORTx.

Changes to


Code C - [expand]
1
2
3
4
5
6
sbit LCD_RS at LATC2_bit;
sbit LCD_EN at LATD2_bit;
sbit LCD_D4 at LATD0_bit;
sbit LCD_D5 at LATC5_bit;
sbit LCD_D6 at LATC0_bit;
sbit LCD_D7 at LATC1_bit;

 

For PIC18F you have to use LATx instead of PORTx.

Changes to


Code C - [expand]
1
2
3
4
5
6
sbit LCD_RS at LATC2_bit;
sbit LCD_EN at LATD2_bit;
sbit LCD_D4 at LATD0_bit;
sbit LCD_D5 at LATC5_bit;
sbit LCD_D6 at LATC0_bit;
sbit LCD_D7 at LATC1_bit;


Ok i will try that.
But u know, my code works in proteus..
 

Ok i will try that.
But u know, my code works in proteus..


Tried your suggestions too.. still not working.
tried changing ports
still no use..
what else could go wrong ?

any problem with internal oscilator ?
 

I just changed ports and started using port D, and it seems to work now, Not sure if port was causing the problem
 

If the pins used for LCD also have analog (ADC) functions then disable them using ANSELx or ADCONx registers.
 

I had disabled all other functions on that pins, anyway i guess i should try with previous pin setup again and trouble shoot what was wrong
 

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…