LCD controller interface

This is a discussion on LCD controller interface within the C Programming forums, part of the General Programming Boards category; Hi everyone! Am new here, but need some urgent help and opinions. We have a section of code supplied by ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    4

    Talking LCD controller interface

    Hi everyone! Am new here, but need some urgent help and opinions. We have a section of code supplied by one of our lecturers to use with LCD displays, however in a University project I need to use a different screen. I am using a Display Tech 20x4 dot matrix display, which uses a "KS0066U" controller, however the supplied code works only for Hitachi HD44780 controller LCD. Is there any way to adapt the following code to be able to make this LCD work? Or will I have to start from scratch/ scrap the project? Thanks for looking


    Code:
    #include <pic.h>
    /*  cLCD.c - Write a String to a 4 Bit Hitachi 44780 LCD I/F
    
    This Program Initializes Hitachi 44780 Based LCD in 4 Bit Mode
      and then writes a simple string to it.  The simulator was used
      to time delay values.  
    
    RC3:RC0 - LCD I/O D7:D4 (Pins 14:11)
    RC4     - LCD E Clocking Pin
    RC5     - LCD R/S Pin
    
    */
    __CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
      & UNPROTECT & BORDIS & IESODIS & FCMDIS);
    
    int i, j, k, n;                 //  Use Global Variables for Debug
    
    //                         1234567890123456
    const char TopMessage[] = "    Who am I     ";
    const char BotMessage[] = "  Tom Page   ";
    
    #define E  RC4                  //  Define the LCD Control Pins
    #define RS RC5
    
    const int Twentyms = 1250;      //  Declare a Constant for 20 ms Delay
    const int Fivems = 300;
    const int TwoHundredus = 10;
    
    LCDWrite(int LCDData, int RSValue)
    {
    
        PORTC = (LCDData >> 4) & 0x0F;  //  Get High 4 Bits for Output
        RS = RSValue;
        E = 1;  E = 0;              //  Toggle the High 4 Bits Out
    
        PORTC = LCDData & 0x0F;     //  Get Low 4 Bits for Output
        RS = RSValue;
        E = 1;  E = 0;              //  Toggle the Low 4 Bits Out
    
        if ((0 == (LCDData & 0xFC)) && (0 == RSValue))
            n = Fivems;             //  Set Delay Interval
        else
            n = TwoHundredus;
    
        for (k = 0; k < n; k++);    //  Delay for Character
    
    }  //  End LCDWrite
    
    main()
    {
    
        PORTC = 0;                  //  Start with Everything Low
        CMCON0 = 7;                 //  Turn off Comparators
        ANSEL = 0;                  //  Turn off ADC
        TRISC = 0;                  //  All of PORTC are Outputs
    
    //  Initialize LCD 
        j = Twentyms;
        for (i = 0; i < j; i++);    //  Wait for LCD to Power Up
    
        PORTC = 3;                  //  Start Initialization Process
        E = 1;  E = 0;              //  Send Reset Command
        j = Fivems;
        for (i = 0; i < j; i++);
    
        E = 1;  E = 0;              //  Repeat Reset Command
        j = TwoHundredus;
        for (i = 0; i < j; i++);
    
        E = 1;  E = 0;              //  Repeat Reset Command Third Time
        j = TwoHundredus;
        for (i = 0; i < j; i++);
    
        PORTC = 2;                  //  Initialize LCD 4 Bit Mode
        E = 1;  E = 0;
        j = TwoHundredus;
        for (i = 0; i < j; i++);
    
        LCDWrite(0b00101000, 0);    //  LCD is 4 Bit I/F, 2 Line
    
        LCDWrite(0b00000001, 0);    //  Clear LCD 
    
        LCDWrite(0b00000110, 0);    //  Move Cursor After Each Character
    
        LCDWrite(0b00001110, 0);    //  Turn On LCD and Enable Cursor
    
        for (i = 0; TopMessage[i] != 0; i++)
            LCDWrite(TopMessage[i], 1);
    
        LCDWrite(0b11000000, 0);    //  Move Cursor to the Second Line
    
        for (i = 0; BotMessage[i] != 0; i++)
            LCDWrite(BotMessage[i], 1);
    
        while(1 == 1);              //  Finished
    
    }  //  End cLCD

  2. #2
    Registered User
    Join Date
    May 2011
    Posts
    4
    I forgot to add that we all use 16F684 16-pin PIC chips!

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    const int Twentyms = 1250; // Declare a Constant for 20 ms Delay
    const int Fivems = 300;
    const int TwoHundredus = 10;

    There are some other recent threads where the poster turned out to be using a much faster processor, and thus screwing up all the delay calculations.
    So first, check these values are really giving you the delays you want.

    From google, it seems the KS0066U is just a clone of the HD44780, so in principle, the same code should drive both of them.

    > This Program Initializes Hitachi 44780 Based LCD in 4 Bit Mode
    Does the new device start up in 4-bit mode?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    May 2011
    Posts
    4
    Thanks for the reply! Looking at page 6 of the data sheet, I think it starts up in 8-bit mode. What do you think?

    Displaytech | Optoelectronics and Displays | Displays | LCD Displays - Alphanumeric | Alphanumeric |204A-CC-BC-3LP

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    4
    Page 6 of the data sheet also gives the initialisation sequence. Would this match the code shown above? Does anyone have experience of KS0066U controllers and HD44780 controllers? Thanks!

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    Did you verify the clock / time delay issue I mentioned?

    You're the one sitting with this module in front of you, it's kinda up to you to do the reading and experimenting.

    It seems to me that this is just another example of "I found this code on the net, it doesn't work, can you fix it for me?".

    You have all the info, it's now time for some reading and applying new knowledge to solving the problem.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an XBox controller for my PC
    By Mario F. in forum General Discussions
    Replies: 5
    Last Post: 12-14-2010, 08:58 PM
  2. About Traffic light controller.
    By ovid in forum C++ Programming
    Replies: 4
    Last Post: 03-28-2010, 02:22 PM
  3. Serial controller algorithm
    By kenneth_888 in forum C++ Programming
    Replies: 17
    Last Post: 09-05-2007, 06:47 AM
  4. I'm looking for a Joystick controller
    By Raideen in forum Windows Programming
    Replies: 0
    Last Post: 06-24-2003, 10:36 PM
  5. The controller jiggle code
    By Ipsec Espah in forum Game Programming
    Replies: 2
    Last Post: 05-24-2003, 11:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21