LCD 16X2 Problem

Started by Sumit Bhatnagar October 23, 2008
I have been trying to get the LCD working with the PIC16F684. The only
thing I could get going is the LCD with one row live and the other
blank. Even the LCD code from myke predko.

I am not sure if there is something wrong with the connections or I am
missing a few resistors and capacitors. But If someone can post a
photo or help me with some directions. The code listing is provided below.
-Sumit

#include
/* 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.

LCD Write Information can be found at http://www.myke.com

RC3:RC0 - LCD I/O D7:D4 (Pins 14:11)
RC4 - LCD 6 Clocking Pin
RC5 - LCD 4 Pin

myke predko
04.11.08
*/

__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
& UNPROTECT & BORDIS & IESODIS & FCMDIS);

int i, j, k, n; // Use Global Variables for Debug

// 1234567890123456
const char TopMessage[] = " PIC MCU ";
const char BotMessage[] = " Evil Genius ";

#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 according to the Web Page
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

post photo of ur ckt.

On Mon, Oct 6, 2008 at 7:22 AM, Sumit Bhatnagar wrote:

> I have been trying to get the LCD working with the PIC16F684. The only
> thing I could get going is the LCD with one row live and the other
> blank. Even the LCD code from myke predko.
>
> I am not sure if there is something wrong with the connections or I am
> missing a few resistors and capacitors. But If someone can post a
> photo or help me with some directions. The code listing is provided below.
> -Sumit
>
> #include
> /* 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.
>
> LCD Write Information can be found at http://www.myke.com
>
> RC3:RC0 - LCD I/O D7:D4 (Pins 14:11)
> RC4 - LCD 6 Clocking Pin
> RC5 - LCD 4 Pin
>
> myke predko
> 04.11.08
> */
>
> __CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
> & UNPROTECT & BORDIS & IESODIS & FCMDIS);
>
> int i, j, k, n; // Use Global Variables for Debug
>
> // 1234567890123456
> const char TopMessage[] = " PIC MCU ";
> const char BotMessage[] = " Evil Genius ";
>
> #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 according to the Web Page
> 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
>
>
>
Hi Sumit.

I have the same problem trying to initialise an LCD and haven't found
the solution as I haven't been able to work on it for about 2 weeks.

I did find these two pdf's that I think are very useful and may help you.

www.epemag.wimborne.co.uk/lcd1.pdf
www.epemag.wimborne.co.uk/lcd2.pdf

Once you get it working, please let me know what your solution was.

Regards,

William

2008/10/6 Sumit Bhatnagar :
> I have been trying to get the LCD working with the PIC16F684. The only
> thing I could get going is the LCD with one row live and the other
> blank. Even the LCD code from myke predko.
>
> I am not sure if there is something wrong with the connections or I am
> missing a few resistors and capacitors. But If someone can post a
> photo or help me with some directions. The code listing is provided below.
> -Sumit
>
> #include
> /* 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.
>
> LCD Write Information can be found at http://www.myke.com
>
> RC3:RC0 - LCD I/O D7:D4 (Pins 14:11)
> RC4 - LCD 6 Clocking Pin
> RC5 - LCD 4 Pin
>
> myke predko
> 04.11.08
> */
>
> __CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
> & UNPROTECT & BORDIS & IESODIS & FCMDIS);
>
> int i, j, k, n; // Use Global Variables for Debug
>
> // 1234567890123456
> const char TopMessage[] = " PIC MCU ";
> const char BotMessage[] = " Evil Genius ";
>
> #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 according to the Web Page
> 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

Try the attached - has always worked for me.

Colin
--
cdb, c...@btech-online.co.uk on 17/11/2008

Web presence: www.btech-online.co.uk

Hosted by: www.1and1.co.uk/?k_idy88359

Hi harinder singh dalal,
Could you please post in english? Not everybody understands your language.

Thanks,
JF

--- In p..., "harinder singh dalal"
wrote:
>
> post photo of ur ckt.
>
> On Mon, Oct 6, 2008 at 7:22 AM, Sumit Bhatnagar wrote:
>
> > I have been trying to get the LCD working with the PIC16F684.
The only
> > thing I could get going is the LCD with one row live and the other
> > blank. Even the LCD code from myke predko.
> >
> > I am not sure if there is something wrong with the connections or I am
> > missing a few resistors and capacitors. But If someone can post a
> > photo or help me with some directions. The code listing is
provided below.
> > -Sumit
> >
> > #include
> > /* 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.
> >
> > LCD Write Information can be found at http://www.myke.com
> >
> > RC3:RC0 - LCD I/O D7:D4 (Pins 14:11)
> > RC4 - LCD 6 Clocking Pin
> > RC5 - LCD 4 Pin
> >
> > myke predko
> > 04.11.08
> > */
> >
> > __CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT \
> > & UNPROTECT & BORDIS & IESODIS & FCMDIS);
> >
> > int i, j, k, n; // Use Global Variables for Debug
> >
> > // 1234567890123456
> > const char TopMessage[] = " PIC MCU ";
> > const char BotMessage[] = " Evil Genius ";
> >
> > #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 according to the Web Page
> > 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
> >
> >
>
hello everyone
i have the same problem, but i program in picbasicpro
can somebody help me
thanks

The memory for a 16 x 2 LCD is usually arranged 20 x 2.
So if you can't get the function working to move the cursor down to
the next line, you can try writing 4 dummy characters at the end of
the first line, and this should achieve the same result.