PDA

View Full Version : Reset risetime seems to upset LCD on 18f4550



VaughnS
- 9th February 2011, 15:04
I am trying to drive a 4x20 LCD on port D of an 18f4550. If the circuit is started by switching on the power (risetime about 300 µsec) everything works fine but if the circuit is reset from an electronic signal from the programmer, the watchdog timer or mechanical switch with a risetime in the nano second region,the lcd is very confused. LCD is not reset from the PIC MCLR line.
I have tried the circuit on the EasyPIC4 board from Mikroelektronika (horrors - the opposition !nice board but I dont like the compiler except for floating point) as well as a board I made myself with exactly the same LCD circuit . Also have tried 3 chips and all combinations do the same. When the LCD gets confused a few characters are missing at the start of the first line, the second line gets printed somewhere outside the display area, the third line is printed in the right place and the fourth line is printed on top of line one.
If the program is put in a loop to repeat the four display lines it repeats the patern that it starts with. That is if it starts ok it repeats the display correctly but if it starts in the confused state all subsequent loops of the program are similarly confused.
The program was run without the watchdog being enabled and then when enabled the ASM code was inserted to cause it to timeout.
Any suggestions would be greatfully accepted.

Sorry about cutting and pasting program, attach didnt seem to work.
' PICBASIC PRO program to demonstrate operation of an LCD in 4-bit mode
'PROCESSOR = 18F4550
' LCD should be connected as follows:
' LCD PIC
' DB4 PortD.4
' DB5 PortD.5
' DB6 PortD.6
' DB7 PortD.7
' RS PortD.2 (add 4.7K pullup resistor to 5 volts)
' E PortD.3 AS IN EASYPIC4
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo 20K potentiometer (or ground)
' DB0-3 No connect
DEFINE OSC 8
DEFINE LCD_DREG LATD
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG LATD
DEFINE LCD_RSBIT 2
DEFINE LCD_EREG LATD
DEFINE LCD_EBIT 3
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 150

trisa = 0
TRISD = 0
Pause 1800 ' Wait for LCD to startup
mainloop:

PORTA = 7
PAUSE 500 'flash led
PORTA = 0

Lcdout $fe, 1 'CLEAR
Lcdout $fe, $0C 'CURS OFF
Lcdout $fe, 2 'HOME
lcdout "Hello WORLD" ' WRITE
PAUSE 500
lcdout $fe,192, "second line"
PAUSE 500
Lcdout $fe, 148, "third line "
PAUSE 500
LCDOUT $FE,212, "FOURTH LINE"
PAUSE 500
'THE FOLLOWING FOUR LINES INSERTED TO FORCE WATCHDOG TO TIMEOUT FOR TEST
Asm
NOP
GoTo ($-2)
EndAsm
Goto mainloop ' Do it forever

END

Archangel
- 11th February 2011, 04:35
try what this thread is about:
http://www.picbasic.co.uk/forum/showthread.php?t=8193
also bypass your LCDpower pins with a .01 µ F cap.

VaughnS
- 11th February 2011, 06:53
Thanks Joe S

The power is very well bypassed so I tried the FLAGS = 0 command and it worked but not without a bit of fiddling.
I reasoned that if any reset occurrs the software would be reinitialised but I must be wrong.
I first put the FLAGS command at the start of the program but that didnt work.
I then put it after the clearing and home commands with a pause before continuing as below.

Lcdout $fe, 1 'CLEAR
Lcdout $fe, $0C 'CURS OFF
Lcdout $fe, 2 'HOME
flags = 0
pause 2000
lcdout "Hello WORLD" ' WRITE

It was also neccessary to adjust the timing parameters quite carefully as below
DEFINE LCD_COMMANDUS 3000
DEFINE LCD_DATAUS 150

It now works from any kind of reset.
I have used literally hundreds of these displays with several PICS and 8051 types but never battled like this before!

Thanks again for the suggestion.