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