PDA

View Full Version : Pic16f690 and LCD



ross246
- 17th May 2010, 23:09
Hi again, I'm trying to do a simple "hello world" between my pic16f690 and a 2 line lcd screen based on the hd44780. I have connected it as follows:

LCD -----> PIC
4(RS) --- 12(RB5)
6(E) --- 11(RB6)
11(D4) --- 16(RC0)
12(D5) --- 15(RC1)
13(D6) --- 14(RC2)
14(D7) --- 7(RC3)

I have tied pins 1,3,5,16 to ground and got +5v on pins 2, 15.

After my own code failing I found some code by a moderator here called Joe S in a different thread which I am now using:


define OSC 4
DEFINE LCD_DREG PORTC 'Set port C for the data lines
DEFINE LCD_DBIT 4

DEFINE LCD_RSREG PORTB 'Set the RS Port and Pin
DEFINE LCD_RSBIT 5

DEFINE LCD_EREG PORTB 'Set LCD Enable bit and pin
DEFINE LCD_EBIT 6

DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
' Set command delay time in us
DEFINE LCD_COMMANDUS 2000
' Set data delay time in us
DEFINE LCD_DATAUS 50

ANSEL = 0
ANSELH = 0
CM1CON0 = 0
CM2CON0 = 0

Cnt VAR WORD

'Start Program
TRISC = 0
TRISB = 0

Pause 500

cnt=0
RPT:
HIGH PORTB.6
LCDOUT $FE,1 'CLEAR LCD SCREEN
pause 500
LCDOUT $FE,2,"CNT=", DEC CNT
Pause 1000
CNT=CNT+1
GOTO RPT
END

The program is running and not hanging as the led flashes, however on the lcd I just have a row of black blocks on the top and nothing on the bottom. I have gone over and redone my wiring many times, also tried a different bread board and a different lcd. Not sure what else I can change or try if anyone has any ideas.

Thanks

BobK
- 17th May 2010, 23:26
Hi Ross,

Take pin 3 of the LCD and connect it to the wiper on a 5K ohm potentiometer (pot) and then tie one side of the pot to ground and the other side to + 5volts. This controls the contrast of the display. Adjust the pot until you can see the characters. Once you know what resistance gives you
the correct view you could read the pot's resistance then just substitute a 1/2 watt resistor with the desired resistance OR you can just leave the pot in the circuit.

HTH,

BobK

ross246
- 17th May 2010, 23:30
I was just about to post saying I solved it (typical i work it out once I post this) I changed it to DEFINE LCD_DBIT 0 and its sorted it out however it works for the first few seconds (about 3) then the line gets filled with garbage characters and some of them turn to black blocks with characters barely visible inside them. Will swap the lcd. Thanks for the reply will do that too :) progress! lol

Darrel Taylor
- 17th May 2010, 23:41
Try removing the line ...
HIGH PORTB.6

B.6 is the Enable Line which is handled by the LCDOUT command.
You don't need to set it HIGH to enable the LCD.

ross246
- 17th May 2010, 23:47
Working perfectly now on a new lcd, not sure whether it was removing the HIGH Portb.6 or the new lcd :) thanks anyways though. I really appreciate it.