PDA

View Full Version : PIC18F4525 & LCD simple code problem



aggie007
- 2nd November 2007, 00:53
Hi,

I am new to any kind of programming and I am using PicBasic Pro to program PIC18F4525. I am hooking up the PIC to a parallel LCD screen which has HD44780 controller (16X2). I am just trying to test the connection and the working of the LCD by writing a code which displays a one line test statement. I am using Micro Code Studio.

The LCD screen is not displaying the message I want it to and remains blank. I know this is a very minor issue, but I am doing this stuff for the first time !!!

The LCD is connected to 4 pins of the PIC, since it is in 4 bit mode.

Please help me out with this....I would really appreciate it !!!


Here is the code -


DEFINE OSC 20

'******Setting up the LCD display******

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 7
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 6
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
'DEFINE LCD_COMMANDUS 2000
'DEFINE LCD_DATAUS 50

TRISB=0

LCDOUT $FE, 1
LCDOUT "PIC - LCD Test "
LCDOUT $FE, $C0

STOP

END

BrianT
- 2nd November 2007, 02:31
With the LCDs I use, (Taiwanese) they will not work without a contrast resistor. This can be a single resistor about 10k (needs experiment) from the contrast pin to ground. Preferably use a pot with the ends between +5 and ground with the wiper to the contrast pin.

Otherwise the screen will remain totally blank.

HTH
Brian

Archangel
- 2nd November 2007, 05:22
Hello aggie007,
BrianT is right on target with his post, I would also put a pause of about 1/2 second to 1 second before the first lcdout command to give the LCD time to initialise.

savnik
- 2nd November 2007, 05:52
'******Setting up the LCD display******

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 7
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 6
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2

DEFINE LCD_DBIT 4 Mean PORTB4-PORTB7
and you use the same pins for RSBIT 7 and EBIT 6

aggie007
- 2nd November 2007, 16:23
With the LCDs I use, (Taiwanese) they will not work without a contrast resistor. This can be a single resistor about 10k (needs experiment) from the contrast pin to ground. Preferably use a pot with the ends between +5 and ground with the wiper to the contrast pin.

Otherwise the screen will remain totally blank.

HTH
Brian


I am using a 20K pot which takes care of the contrast.

aggie007
- 2nd November 2007, 16:28
DEFINE LCD_DBIT 4 Mean PORTB4-PORTB7
and you use the same pins for RSBIT 7 and EBIT 6


Savnik,

I didnt know that LCD_DBIT 4 means PORTB4-B7 ....I thought it just states the starting data bit for a 4 bit bus.....I was totally confused on this one !!

Thanks for pointing it out....I'll try to make this work now !!!

BobK
- 2nd November 2007, 17:09
Hi Aggie,

There are more than enough posts on this forum that will help you work your way through just about anything you can think of. I'm not trying to chase you away but if you use the search facility on this forum you should have plenty of reading material that will get you going in no time. In fact I think there's almost enough here to write a book. What an idea!!!!! "USING PIC's WITH LCD DISPLAY". What an idea!!!!!

HTH,

BobK

aggie007
- 3rd November 2007, 16:29
I tried all those things mentioned above - 20K pot for contrast, etc, etc.

But it still doesnt work !!

The LCD lights up...but doesn't display anything. The PIC is working fine by itself, I tested it. But its not communicating with the LCD. I think the problem has something to do with the clock/oscillator.

Do I need to connect an external resonator (20MHz) to the two OSC pins of the PIC ? If so, how do I do it ? Do I need to add something to my code ? How ?

Please help.