PDA

View Full Version : SOUND makes LCD quit working



jderson
- 18th April 2008, 05:43
I am using PORT B to supply power to the LCD and generate a tone.
In the code below, when the SOUND command executes, the LCD goes blank.
If I comment out the SOUND command, the LCD stays on. What's going on?

TRISC = %00000000
TRISA = %101100
TRISB = %10000000

@ DEVICE pic16f689,wdt_off

HIGH PORTB.4 'Turn on power to LCD

Define LCD_DREG PORTC 'Set LCD data port
DEFINE LCD_DBIT 0 'Set LCD starting data bit
DEFINE LCD_RSREG PORTC 'Set LCD register select port
DEFINE LCD_RSBIT 4 'Set LCD register select bit
DEFINE LCD_EREG PORTC 'Set LCD enable port
DEFINE LCD_EBIT 5 'Set LCD enable bit
DEFINE LCD_BITS 4 'Set LCD bus size
DEFINE LCD_LINES 2 'Set LCD number of lines

OPTION_REG = %00111000
ANSEL = 0
CM1CON0 = %00000000

LCDOUT $fe,1
LCDOUT DEC 9999

PAUSE 1000

SOUND PORTB.6,[118,200]

END

Thank you for your help.

Rob
- 18th April 2008, 11:27
Hi,

I'm not sure if that's your whole code or not. You should really have a small delay before your program starts to allow the Power supply to settle properly. There should also be a delay for the lcd to initialise properly before sending data to it. These are unlikely to be the cause of your problem but it's good practice. Try placing a PAUSE 500 before you send PORTB.4 high. 500ms delay before writing to the LCD should be enough time for the majority of LCDs to intialise correctly.

When you say power the LCD from PORTB you're not talking about the backlight as well are you? The PIC pins can only supply 25mA and some LCDs can take a lot more than that to light.

Just to check, PORTB.6 is not accidentally connected to one of the LCD pins is it?

Cheers

Rob

mister_e
- 18th April 2008, 13:42
at the end of your program, you should or finish by a STOP command or with an endless loop, unless your PIC may behave in a weird way.

Here: GOTO Here

You may also need to check if ALL ADCs and comparators are disabled. Here i see 2 missing lines

ANSELH = 0
CM2CON0 = 0

And then what you drive and how, may help us to go deeper in our understanding.

HTH

jderson
- 18th April 2008, 14:12
Thanks for the help! The ANSELH = 0 line fixed the problem! This is a small part of my program. As I use PORTC to control the LCD, it's a wonder this hasn't caused more problems before now. I thought I RTFDS enough, but apparently not! Thanks again.