0
\$\begingroup\$

I am working on interfacing 16X2 lcd in 4bit mode with pic18f4550.The higher 4 bits (D4,D5,D6,D7) are connected to PORTA1,A2,A3,A4 , pin RAO as RS, RE2 as RW, RE3 as RE3. i am struck with below code which displays nothing .The below code compiles without any error ,but display nothing (assume no mistake in my hardware connection)? /* * File: main.c * Author: tamil * * Created on June 5, 2013, 11:32 PM */ #include

 #pragma config FOSC = HS  // to select external osc
// CPU System Clock Postscaler:
// [OSC1/OSC2 Src: /1][96 MHz PLL Src: /2 = 48 MHz CPU Clock]
#pragma config CPUDIV = OSC1_PLL2
#pragma config PWRT     = ON        // 62 ms waiting at start
#pragma config BOR      = ON        // Brown our Reset enabled (IMPORTANT!!!)
#pragma config BORV     = 2         // Reset level = 2,7 V
#pragma config WDT = OFF  // watch dog timer off
#pragma config DEBUG = ON,LVP = OFF // debugger on , as per pickit3
#pragma config PBADEN = OFF //PORTB<4:0> pins are configured as digital I/O on Reset
#pragma config MCLRE = ON //MCLR pin enabled; RE3 input pin disabled

//lvp should be off

 #define rs LATAbits.LATA0
 #define rw LATEbits.LATE1
 #define en LATEbits.LATE2
 #define lcdport LATA
    void Delay_ms(int ms)
 {
  int i,j=0;
   for(i=0;i<ms;i++)
    for(j=0;j<165;j++);

  }
       void lcdcmd(unsigned char cmdout)
     {
lcdport=(lcdport |(cmdout << 1));       //Send command to lcdport=PORTB
rs = 0;                     
rw = 0;
en = 1;
Delay_ms(1);
en = 0;
    }
       void lcddata(unsigned char dataout)
    {
lcdport=(lcdport | (dataout << 1)); //Send data to lcdport=PORTB
rs=1;
rw=0;
en=1;
Delay_ms(1);
en=0;
    }
   void dis_data(unsigned char data_value)
   {
unsigned char data_value1;
data_value1=(data_value&0xF0);
lcddata(data_value1);
data_value1=((data_value<<4)&0xF0);
lcddata(data_value1);
    }
    void dis_cmd(unsigned char cmd_value)
    {
unsigned char cmd_value1;
cmd_value1 = (cmd_value & 0xF0);    // Mask lower nibble because RB4-RB7 pins              are being used
lcdcmd(cmd_value1);         // Send to LCD
cmd_value1 = ((cmd_value<<4) & 0xF0);   // Shift 4-bit and mask
lcdcmd(cmd_value1);         // Send to LCD
    }
    void lcd_ini()
    {
dis_cmd(0x02);
    Delay_ms(200);// To initialize LCD in 4-bit mode.
dis_cmd(0x28);
    Delay_ms(200);// To initialize LCD in 2 lines, 5x7 dots and 4bit mode.
dis_cmd(0x0C);
    Delay_ms(200);
dis_cmd(0x06);
    Delay_ms(200);
dis_cmd(0x80);
    Delay_ms(200);
     }
   void main ()
     {
       unsigned char data[]="tamil";
       unsigned int x =8;
       //unsigned int y = 1;
        //unsigned int i=0;
           ADCON1=15; // to configure  all analog pins as digital i/o
           TRISA = 0; // to config port A as o/p
           TRISE = 0;// to make it as o/p
           lcd_ini();
           // LCD initialization

         while(data[i]!='\0')
       {
    dis_data(data[i]);
    Delay_ms(200);
    i++;
        }

}

\$\endgroup\$
2
\$\begingroup\$

I wonder how this code is getting compiled. The declaration of "i" is commented and still you are using the variable.

My Suggestions:

  1. Initialize "i" with 0, it might be getting random value and your while loop is not getting executed at all.

  2. Try increasing delay for High to Low transition on EN Pin, say around 50msec.

  3. Simulate this code using simulator or something if you are so sure about Hardware connection.
  4. Code says LCD is connected on Port A and comment says it's on Port B (first line of lcdcmd and lcddata)

Never forget the Golden Rule:

"When Code and comments don't match, probably both are wrong"

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.