PDA

View Full Version : LCD with PIC16F687



jblackann
- 26th June 2006, 19:16
I am new to using the PICBASIC but I have background experience with PIC microcontrollers. I am trying to learn how to use an LCD with a PIC16F687. I have tried to copy the example that I found on the MELABS website but it does not seem to functioning. The program will compile just fine but when the micro does not seem to be doign anything when powered up. I am using a scope and it appears that the Data bit pins are just cycling on and off about every 500 ms. I am not sure what I am supposed to be looking at. I would assume that the pins would be switching at a fast rate but I am not seeing that happen. I modified my program to use the PORTC instead of PORTA for the data bits. No other pins are changing. Any suggestions? Thanks for the help.

Below is the code.

DEFINE OSC 4

DEFINE LCD_DREG PORTC 'set LCD DATA port
DEFINE LCD_DBIT 4 'set starting DATA bit (0 or 4) if 4-bit
DEFINE LCD_RSREG PORTB ' Set LCD Register Select port
DEFINE LCD_RSBIT 4 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTB ' Set LCD Enable port
DEFINE LCD_EBIT 6 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us

'CMCON = 7
ADCON1 = 7
ANSEL = %00000000
TRISA = %00000000
TRISB = %00000000
TRISC = %00000000
PORTA = %00000000
PORTB = %00000000
PORTC = %00000000

Pause 500 ' Wait for LCD to startup

loop: Lcdout $fe, 1 ' Clear LCD screen
Lcdout "Hello" ' Display Hello
Pause 500 ' Wait .5 second

Lcdout $fe, 1 ' Clear LCD screen
Lcdout "World"
Pause 500 ' Wait .5 second

Goto loop ' Do it forever

schu4647
- 26th June 2006, 19:35
I had a similiar problem. Turned out I was configuring registers wrong. I notice some of the pins that you are using can also be analog. You need to make them digital for the LCD command to work. Try making ANSEL = %11111111. I can't remember if %00000000 is analog or digital, but I thought it was analog.

schu4647
- 26th June 2006, 19:42
You also need to make anselh=%00001111. Anselh is the analog register for port C while ansel is the register for port A. Like I said though I may have the 0's and 1's backwards. I always get confused and have to experiment. The four 0s at the beginning are don't cares.

jblackann
- 26th June 2006, 20:31
Apparently that was what I needed to do. I did not have the ANSELH register set. To set each pin to the Digital function, each bit must be set to a "0", so ANSELH = %00000000. Thanks.

My LCD works now and gives me the Hello World example that I have seen in numerous examples. Thanks.

jblackann
- 26th June 2006, 21:11
Would you have any advice for setting the configuration bits? Now I am manually changing them before I load the program into the microcontroller.

I want to disable the watchdog timer and master reset to be internal.

Thanks.

mister_e
- 26th June 2006, 23:16
read the FAQ, there's a huge thread about that http://www.picbasic.co.uk/forum/showthread.php?t=543