LCD and 18F8722

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
garryp4
Posts: 125
Joined: Mon May 21, 2007 7:18 am
Location: Loveland, CO USA

LCD and 18F8722

Post by garryp4 » Sat Mar 10, 2012 5:54 pm

I am having trouble with an LCD on an 18F8722 on PORTA. If I comment out the line #option LCD_DATA = PORTA.0, the rest of the program executes, get serial message on hterm and LED's flash. If the line is not commented out nothing happens. I am pretty sure the A/D is disabled. Hopefully I don't make this mistake any longer. Here is the code and thanks for any help


Code: Select all

// device and clock...                                                                                                                                                                                                                                         
Device = 18F8722
Clock  = 32

// LCD...
#option LCD_DATA = PORTA.0
#option LCD_RS   = PORTA.4
#option LCD_EN   = PORTA.5

// import modules...
Include "USART.bas"
Include "USART2.bas"
Include "convert.bas"
Include "UTILS.BAS"
Include "LCD.bas"

// declare ports
Dim 
  green         As PORTJ.1,             ' Green LED output
  red           As PORTJ.2              ' Red LED output
 
'****************************************************************
Private Sub LED()
  High(red)
  DelayMS(30)
  Low(red)
  High(green)
  DelayMS(30)
  Low(green)
End Sub  
'****************************************************************

OSCCON  = $FC
OSCTUNE = $C0
ADCON0  = $00
ADCON1  = $0F
HLVDCON = $00

USART.SetBaudrate(br9600)
USART2.SetBaudrate(br9600)

Low(green)
Low(red)

LED                                    ' Do something

LCD.Cls
LCD.WriteAt(1,1,"I'M ALIVE")

USART2.Write("I'M ALIVE",10,13)
DelayMS(2)

'****************************************************************
MAIN:

  while true                           ' Do nothing
  wend
  
  GoTo MAIN

User avatar
Senacharim
Posts: 139
Joined: Tue Aug 10, 2010 5:19 pm
Location: Ventura, CA

Post by Senacharim » Tue Mar 13, 2012 3:39 pm

So, which pin are you using for data out to the LCD?

It looks like you're using the USARTs to do so...

In which case, why are you using the LCD module?

Or... which LCD display are you using; that way somebody experienced with that particular device can give more/better feedback.

Also, are you 100% that your clock is configured and working correctly (eg can you correctly receive 9600 baud off the usarts with a different device?)
Surviving Member
Bermuda Triangle Battalion
from 2026 to 1992

Voted "Most likely to time travel"--Class of 2024.

garryp4
Posts: 125
Joined: Mon May 21, 2007 7:18 am
Location: Loveland, CO USA

Post by garryp4 » Tue Mar 13, 2012 9:04 pm

So, which pin are you using for data out to the LCD?

Code: Select all

#option LCD_DATA = PORTA.0 
Data pins are porta.0 - porta.3.


It looks like you're using the USARTs to do so...
I have the same message go out to hypertem so I know the device and code are running. Also flash the LED.

What I do not understand is if the line "#option LCD_DATA = PORTA.0 " is commented out the message goes out to hyperterm and the LED's flash. If it is not commented out nothing happens. I have put an LCD on most of my projects and have just recycled the schematic and layout with no problem. I did one on an 18F668o with the exact same connections that works fine.

Thanks for the help.

User avatar
Senacharim
Posts: 139
Joined: Tue Aug 10, 2010 5:19 pm
Location: Ventura, CA

Post by Senacharim » Tue Mar 13, 2012 9:54 pm

The '#OPTION' is a precompiler tag; it allows you to change something in a module to something other than the default.

At present, you're telling the module to specifically use porta.0, porta.4, and porta.5 for its functions. If those 3 pins are not the ones you've connected to your LCD, then you need to change the text of your #OPTION tags.

Have you looked at the code in the module itself?
In the module it states it "Supports Hitachi HD44780 LCD controller"
Have you verified the LCD module is compatible with the LCD you're using?

Also, if you've commented out the options, it instead uses its default pins:
#option LCD_DATA = PORTB.4
#option LCD_RS = PORTB.3
#option LCD_EN = PORTB.2
Surviving Member
Bermuda Triangle Battalion
from 2026 to 1992

Voted "Most likely to time travel"--Class of 2024.

Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Wed Mar 14, 2012 10:57 am

Something to check... on that chip pin RA4 is an open-drain output, so it would require a pullup resistor for the LCD_RS to work.

Not sure what that would have to do with the data lines or why that would stop the other things from functioning, though.

User avatar
Senacharim
Posts: 139
Joined: Tue Aug 10, 2010 5:19 pm
Location: Ventura, CA

Post by Senacharim » Wed Mar 14, 2012 2:29 pm

Also, if/when you solve this; please post what you've learned so others in the future can learn something as well.
Surviving Member
Bermuda Triangle Battalion
from 2026 to 1992

Voted "Most likely to time travel"--Class of 2024.

garryp4
Posts: 125
Joined: Mon May 21, 2007 7:18 am
Location: Loveland, CO USA

Post by garryp4 » Thu Mar 15, 2012 12:00 pm

Solved. Got out the circuit with the 18f6680 and loaded the same code and the LCD worked fine on port A. Broke out the scope to see if could find anything and saw that the 5vdc was about 5.3vdc. I was using a generic wall wort with a 7805 and 2 caps. Swapped in the 5vdc switcher and worked fine.

Also, using RA.4 with no pull up resistor worked just fine on both circuits. But good call Jerry.

Anyway, thanks for the help.

Post Reply