Question

Anybody have some sure to work 4-bit interface C code for a PIC 18f4685 to Hitachi LCD 2-line display? I'm using a Northmicro proto board with a LCD module which is Hitachi 44780 compatible.

Lower nibble on PORTB to D4-7; E:RA4
RS:RB4
RW:RB5 Backlight:RA5

I've looked all around Google land and have found stuff that should get me through the process but none have been written for my particular configuration. I've gone through and think I've tweaked them for my uses but I can't even get the LCD to initialize. Timing delays seem to be okay when I run it through the MPlabSim.

I've tried to use the libraries in the mcc18 src folder too but that didn't work either.

I'm looking for code that is known to work so I can troubleshoot if it's my crappy coding or the board. So far I've only been able to turn the backlight on and off but that doesn't really count as it's just a pin connected to a mosfet and has nothing to do with the onboard mcu of the LCD.

I've been at it for a few hours each day for the past week... 16 hours is a long time to spend on a silly project like this so I'd love it if I could get a helping hand with it please.

Was it helpful?

Solution

i'm giving the code running on PIC18f458/16F877 written in c and compiled in micro c compiler..hope it may b helpful for u...

#define rs PORTB.F0
#define rw PORTB.F2
#define en PORTB.F1
#define lcd PORTD


    void delay()
    {
         int i;
         for(i=0;i<500;i++);

    }


    void lcd_cd(unsigned char c)
    {
         rs=0;
         lcd = (lcd & 0x0F) | (c & 0xF0);
         en=1;
         delay();
         en=0;
         lcd = (lcd & 0x0F) | (c <<4);
         en=1;
         delay();
         en=0;

    }



    void lcd_data(char *c)
    {
         rs=1;
         while(*c!='\0')
         {

             lcd = (lcd & 0x0F) | (*c &0xF0);
             en=1 ;
             delay();
             en=0;
             lcd = (lcd & 0x0F) | (*c <<4);
             en=1;
             delay();
             en=0;
             c++;
         }
    }



    void lcd_int()
    { 

         lcd_cd(0x02);
         delay();
         lcd_cd(0x28);
         delay();
         lcd_cd(0x80);
         delay();
         lcd_cd(0x01);
         delay();
         lcd_cd(0x0e);
         delay();
    }




    void main()
    {
         rw=0;
         TRISB=0X00;
         TRISD=0X00;

         while(1)
         {
              lcd_int();
              delay();
              lcd_data("HELLO INDIA");
              delay();
              lcd_cd(0xc2);
              lcd_data("HELLO INDIA");
              delay();
         }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top