PDA

View Full Version : PIC16F684 + 8*2 LCD module



xnihilo
- 4th March 2008, 23:03
Hi guys,

I'm trying to use a Hitachi 44780 compatible LCD module with a pic16F684 but it does not work.

All I see is a peristent row of black blocks.

I connected:

LCD to PIC
----------
RS (pin 4) to PIC RA4
E (pin 6) to PIC RA5
R/W to GND
D4 to RC0
D5 to RC1
D6 to RC2
D7 to RC3
D8 to RC4

Of course I connected the Pin1 (vss) to GND and VDD to +5V and VO (pin3) to a trimmer to adjust the contrast.
I connected pin 16 (backlight GND) to a transistor to PIC pin RC4 in order to control backlight in software. Pin 15 (+5V) is connected to +5V.

My code is:

' Set LCD Data port
DEFINE LCD_DREG PORTC

' Set starting Data bit (0 or 4) if 4-bit bus = portC bit 0 for LCD Data bit 4
DEFINE LCD_DBIT 0

' Set LCD Register Select port
DEFINE LCD_RSREG PORTA

' Set LCD Register Select bit
DEFINE LCD_RSBIT 4

' Set LCD Enable port
DEFINE LCD_EREG PORTA

' Set LCD Enable bit
DEFINE LCD_EBIT 5

' Set LCD bus size (4 or 8 bits)
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




CLEAR



CMCON0 = %00000111 'comparators OFF, val = 7

ANSEL = %00000000 'choose digital i/o, val = 0


OPTION_REG = %01111111 'enable internal porta weak pullups resistors

WPUA = %010000 'enable weak pull ups for RS bit

TRISA = %000000
TRISC = %000000

PORTA = %000000
PORTC = %000000





Pause 2000 ' Wait for LCD to startup


START:

FLAGS = 0

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

pause 2000

HIGH PORTC.5 'turn on backlight
LOW PORTC.5 'turn of backlight

Goto loop ' Do it forever



END











CAN SOMEONE HELP ME PLEASE

Archangel
- 5th March 2008, 02:34
Hello xnihilo
shut down the analog stuff on port A and follow the instructions on the thread below.
http://www.picbasic.co.uk/forum/showthread.php?t=543
Doh . . . analog . . .so far down I missed it. As skimask always tells people, add a temporary blinky so as to know your PIC is working.

mackrackit
- 5th March 2008, 04:33
Can you post a schematic?
Looks like you have 7 connections from the display to the PIC.
Should be 6.


LCD to PIC
----------
RS (pin 4) to PIC RA4
E (pin 6) to PIC RA5
R/W to GND
D4 to RC0
D5 to RC1
D6 to RC2
D7 to RC3
D8 to RC4


D8 is confusing me:)

xnihilo
- 5th March 2008, 23:38
Sorry I mistyped it I use 4 higher data bits of the LCD.

I could make it work at last just before going to sleep yesterday.

here is the code for a PIC16F684, hope it can be of help:

' Set LCD Data port
DEFINE LCD_DREG PORTC

' Set starting Data bit (0 or 4) if 4-bit bus = portC bit 0 for LCD Data bit 4
DEFINE LCD_DBIT 0

' Set LCD Register Select port
DEFINE LCD_RSREG PORTA

' Set LCD Register Select bit
DEFINE LCD_RSBIT 4

' Set LCD Enable port
DEFINE LCD_EREG PORTA

' Set LCD Enable bit
DEFINE LCD_EBIT 5

' Set LCD bus size (4 or 8 bits)
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




CLEAR



CMCON0 = %00000111 'comparators OFF, val = 7

ANSEL = %00000000 'choose digital i/o, val = 0


OPTION_REG = %01111111 'enable internal porta weak pullups resistors

WPUA = %010000 'enable weak pull ups for RS bit

TRISA = %000000
TRISC = %000000

PORTA = %000000
PORTC = %000000





Pause 2000 ' Wait for LCD to startup


START:

FLAGS = 0

loop:

WPUA = %010000 'enable weak pull ups for RS bit


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

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

pause 2000

HIGH PORTC.5 'turn on backlight
HIGH PORTC.4
LOW PORTC.5 'turn of backlight
LOW PORTC.4




Goto loop ' Do it forever



END