-
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
-
I forgot to add that we all use 16F684 16-pin PIC chips!
-
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?
-
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
-
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!
-
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.