PDA

View Full Version : LCD works at 4MHz, but not 12 or 16MHz



Max Power
- 10th June 2008, 21:16
Hello helpful people!

I wrote (well..copied, pasted, and hacked) a program to simply spit out some messages to a LCD. It works great with the internal or external 4MHz clock. But when I try to use a faster clock, there are some good characters, but also some garbage displayed on the LCD.

I'd like to increase the clock speed because eventually I would like to interface with a RFID reader Ic where the Rx data transmission rate is 15625 baud async. So I picked some 12MHz and 16MHz resonators to play with.

The LCD is a 14 pin, 16x4 character LCD from OPTREX. I assume it's compatable with the common Hitachi LCD controller. The only wierd thing about the LCD was that when I used the "move cursor to beginning of x line" commands, the cursor was a couple of spaces off, so I played with it until it looked right.

Here is my code, it's for a 16F628A, using PBP in MPLAB and MPASM



' PicBasic program to demonstrate operation of an LCD in 4-bit mode
'
' LCD should be connected as follows:
' LCD PIC
' DB4 PortA.0
' DB5 PortA.1
' DB6 PortA.2
' DB7 PortA.3
' RS PortA.4 (add 4.7K pullup resistor to 5 volts)
' E PortB.3
' RW Ground
' Vdd 5 volts
' Vss Ground
' Vo (ground)
' DB0-3 No connect

'
' PIC Configuration
' =================
' @ __CONFIG _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON

@ __CONFIG _XT_OSC & _MCLRE_OFF & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ON

'
' Hardware configuration
' ======================

DEFINE OSC 12
CMCON=7 ' disable internal comparator
TRISA=0 ' Set all PORTA capable i/o to output
TRISB=0 ' Set all PORTB i/o to output

'
' Hardware initialisation
' =======================

DEFINE LCD_LINES 4

Pause 1000 '1 second for LCD initialisation
LCDOUT $FE, 1 ' clear LCD
'

Start:
LCDOUT $FE,2, " WELCOME "
LCDOUT $FE,$C0," TO THE "
LCDOUT $FE,$90," ELECTRICAL "
LCDOUT $FE,$D0," DEPARTMENT "


Pause 3000


LCDOUT $FE,2, " "
LCDOUT $FE,$C0," Please have "
LCDOUT $FE,$90," a seat "
LCDOUT $FE,$D0," "



Pause 3000

LCDOUT $FE,2, " someone will "
LCDOUT $FE,$C0," be with "
LCDOUT $FE,$90," you "
LCDOUT $FE,$D0," shortly "


Pause 3000



Goto Start




Thanks for looking.

skimask
- 10th June 2008, 21:18
Look in the PBP manual in the LCDOUT section for commandus and dataus delays and try increasing them a bit.
Also, are you changing your oscillator from XT to HS?

Max Power
- 10th June 2008, 21:40
Its working now. That was it. I added this:

DEFINE LCD_COMMANDUS 2000
DEFINE LCD_DATAUS 100

thank you so much, this forum is so helpful.

...yeah, I had to change XT_osc to HS_osc in order to get my 16MHz resonator to work at all. 12MHz seems to be ok with just XT_osc. Is there a frequency where you should start to use HS_osc?

thanks again.

skimask
- 11th June 2008, 01:23
...yeah, I had to change XT_osc to HS_osc in order to get my 16MHz resonator to work at all. 12MHz seems to be ok with just XT_osc. Is there a frequency where you should start to use HS_osc?

It's in the datasheets for your particular PIC.