PDA

View Full Version : Pic18f452 with 20x4 LCD Help



djmachine
- 6th November 2008, 15:20
Hi I am trying to initialize a CFA2004ATMIJP 20x4 LCD using a Pic18f452 @ 10MHz with PicBasic Pro. After compiling and uploading the hex file the screen stays blank. I have a 10K pot on VO and have it at around 4.2V. The LCD backlight is lit and I have used this code for an 8x2 Optrex LCD with no problems. The only modifications to the code for this LCD are setting the amount of lines to 4 lines instead of 2, and using different DDRAM Addresses such as 0x00, 0x40, 0x14, 0x54 for the LCDOUT commands. Can anyone see where I am going wrong? Thanks!

I have verified with my dmm that all of the connections to the lcd and the pic are good and there are no shorts.

0.1uF cap acrosss (Vss and Vdd)

Vss = Gnd
Vdd = 4.96V
Vo = 4.2V
RS = PORTE.0
R/W = Gnd
E = PORTE.1

DB4 = PORTD.4
DB5 = PORTD.5
DB6 = PORTD.6
DB7 = PORTD.7

The Code
===========================

' PicBasic program to demonstrate operation of an LCD in 4-bit mode
'

DEFINE OSC 10

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


'Force LCD init
FLAGS=0
Lcdout $fe, 1 'Clear LCD screen
'LCD set-up time
PAUSE 2000
Lcdout $fe, 1 'Clear LCD screen


ASM

MOVLF macro literal,dest
movlw literal
movwf dest
endm

Initial
MOVLF B'10001110',ADCON1 ;Enable PORTA & PORTE digital I/O pins
MOVLF B'11100001',TRISA ;Set I/O for PORTA
MOVLF B'11011100',TRISB ;Set I/O for PORTB
MOVLF B'11010000',TRISC ;Set I/0 for PORTC
MOVLF B'00001111',TRISD ;Set I/O for PORTD
MOVLF B'00000000',TRISE ;Set I/O for PORTE
MOVLF B'10001000',T0CON ;Set up Timer0 for a looptime of 10 ms
MOVLF B'00010000',PORTA ;Turn off all four LEDs drssiven from PORTA
ENDASM


PORTA.4 = 0


loop:
LCDOUT $fe, $00, "LCD TEST" ' Display PULSVARs
LCDOUT $fe, $40, "THIS SCREEN" ' Display PULSVARs
LCDOUT $fe, $14, "IS 20 BY 4" ' Display PULSVARs
LCDOUT $fe, $54, "CHARACTERS BIG" ' Display PULSVARs

PAUSE 1000

TOGGLE PORTA.4 ;Heartbeat LED

Goto loop ' Do it forever

End

duncan303
- 6th November 2008, 15:42
Hi I am trying to initialize a CFA2004ATMIJP 20x4 LCD using a Pic18f452 @ 10MHz with PicBasic Pro. After compiling and uploading the hex file the screen stays blank. I have a 10K pot on VO and have it at around 4.2V. The LCD backlight is lit and I have used this code for an 8x2 Optrex LCD with no problems. The only modifications to the code for this LCD are setting the amount of lines to 4 lines instead of 2, and using different DDRAM Addresses such as 0x00, 0x40, 0x14, 0x54 for the LCDOUT commands. Can anyone see where I am going wrong? Thanks!


End

Hi
cannot find any datasheet for your lcd.

but this may help:
PBP supports
LCD modules with a Hitachi 44780 controller or equivalent. These LCDs
usually have a 14- or 16-pin single- or dual-row header at one edge.

______

Darrel Taylor
- 6th November 2008, 16:36
LCDOUT $fe, $00, "LCD TEST" ' Display PULSVARs
LCDOUT $fe, $40, "THIS SCREEN" ' Display PULSVARs
LCDOUT $fe, $14, "IS 20 BY 4" ' Display PULSVARs
LCDOUT $fe, $54, "CHARACTERS BIG" ' Display PULSVARs

Those are the correct addresses, but they have to be sent with a "Set DDRAM Address" command ($80).

So $40 becomes $C0, and $14 is $94 etc..

$80, $C0, $94, $D4
<br>

djmachine
- 6th November 2008, 22:38
I changed the addresses and also adjusted my Vo to 0.5V with reference to ground. But still nothing appears on the screen. Thanks for the replies.

mister_e
- 6th November 2008, 22:43
Forget the LCD for now, use the same code but try a Serial communication test to your PC or use HPWM and measure the frequency.. what happen???