PDA

View Full Version : PIC18F4525 & LCD problem - external resonator ?



aggie007
- 4th November 2007, 02:31
I am hooking up PIC 18F4525 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 shows black boxes. I also hooked up a 20K pot to adjust the contrast. 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. I just have a DEFINE OSC statement specifying the speed of the internal 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 ?

I dont have any knowledge of how external resonators work......Please help.



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 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 1
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

Raflex
- 4th November 2007, 06:31
Hello.

You need to use external oscillator on OSC1 and 2, or add this line to your code:

@ __CONFIG _CONFIG1H, _OSC_INTIO67_1H

This instruction configure your pic with the internal oscillator.

Change DEFINE OSC 20 to DEFINE OSC 8.

If you want to use internal osc to 20Mhz you need to use the PLL.

mackrackit
- 4th November 2007, 09:46
Can you post a schematic of you hook up or give a pin to pin description?

In you other thread you mentioned using four wires, well it does take four wires for the data but two more for "control".

You do not need an external OSC to use a LCD, but the configuration will need to be correct.

aggie007
- 5th November 2007, 19:04
Can you post a schematic of you hook up or give a pin to pin description?

In you other thread you mentioned using four wires, well it does take four wires for the data but two more for "control".

You do not need an external OSC to use a LCD, but the configuration will need to be correct.


Hi Mackrackit,

Here is the pin to pin description of my schematic:

PIC 18F4525 ------ LCD HD44780 (16X2)
B0-------- Pin4 -RS
B1-------- Pin6- Enable
B4-------- Pin11- D4
B5-------- Pin12- D5
B6-------- Pin13- D6
B7-------- Pin14- D7

LCD Pin3- connected to a 20K pot for contrast. The screen still shows black boxes !!!
LCD Pin5- R/W is connected to ground.

PIC Pin1- MCLR is not connected to anything. Is this a problem ?


Here is the code I am using:

DEFINE OSC 8

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

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 1
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50


@_CONFIG_CONFIG1H_OSC_INTIO67_1H

TRISB=0 'Set Port B as output



PAUSE 1000

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



Please Help !!!

Bruce
- 5th November 2007, 22:42
Check the data sheet for this PIC. Several PORTB pins are analog intputs at power-up, and
you'll need to write to OSCCON to configure it for 8MHz internal.

The default value in OSCCON at reset is for 1MHz.

aggie007
- 6th November 2007, 15:33
Check the data sheet for this PIC. Several PORTB pins are analog intputs at power-up, and
you'll need to write to OSCCON to configure it for 8MHz internal.

The default value in OSCCON at reset is for 1MHz.

I have defined Port B as output port in my code by using TRISB=0.

And by using the command:
@_CONFIG_CONFIG1H_OSC_INTIO67_1H

the internal oscillator is working fine at 8 MHz.

The LCD is now displaying text messages, but when I try to display a numerical value of a variable or a constant, it doesnt show anythin as the screen remains blank.

Please Help !!







DEFINE OSC 8

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

DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 1
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50


@_CONFIG_CONFIG1H_OSC_INTIO67_1H

TRISB=0 'Set Port B as output



PAUSE 1000

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

Raflex
- 6th November 2007, 18:08
Hello, you need to use DEC command, for example:

b0 var byte

b0=100

loop:
LCDOut $fe, 1
LCDOut "LCD TEST" 'Display line1
LCDOut $fe, $c0 'Move to line 2
LCDOut Dec b0 'Display b0 on LCD
Pause 500 'Wait .5 second
goto loop

end

Bruce
- 6th November 2007, 18:28
OK. Sorry. You're probably right, but give this a shot just for the heck of it.;o}

1. Edit your 18F4525.INC file in your PBP directory. Change this line;
__CONFIG _CONFIG1H, _OSC_XT_1H

to this; __CONFIG _CONFIG1H, _OSC_INTIO67_1H

Save the file.

Note this line: __CONFIG _CONFIG3H, _PBADEN_OFF_3H saves you from having to
manually disable A/D for several PORTB pins. Just FYI.

2. Change your code to something like this;



DEFINE OSC 8

'******Setting up the LCD display******
DEFINE LCD_DREG PORTB
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTB
DEFINE LCD_RSBIT 0
DEFINE LCD_EREG PORTB
DEFINE LCD_EBIT 1
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 50

'@_CONFIG_CONFIG1H_OSC_INTIO67_1H ; this does nothing & it is not a command

TRISB=0 'Set Port B as output
OSCCON = %01110010

a VAR BYTE

Loop:
LCDOUT $FE,1,"PIC - LCD Test "
PAUSE 1000
FOR a = 0 TO 255
LCDOUT $FE, $C0," A = ", #a
PAUSE 1000
NEXT a
GOTO Loop

END
Does it work now?