PDA

View Full Version : 16x2 parallel LCD help



Whelzorn
02-05-2005, 02:10 PM
Ok, my issue is: I have a 16x2 parallel LCD module. I have is wired like so:



Vss (GND)---------------------1 (GND), 3 (Vee), 5 (R/W)
Vdd (+5V)---------------------2 (+5V)
pin 0-------------------------11 (DB4)
pin 1-------------------------12 (DB5)
pin 2-------------------------13 (DB6)
pin 3-------------------------14 (DB7)
pin 4-------------------------4 (RS)
pin 5-------------------------6 (E)



(where as the left side is the BS2 pins and the right side is the LCD pins)

Ok, I am using the following code (example from www.weethet.nl/english/basicstamp2_lcdcontrol.php (http://www.weethet.nl/english/basicstamp2_lcdcontrol.php))




'{$STAMP BS2}
'{$PBASIC 2.5}

' -----[ Constants ]-------------------------------------------------------
' Ports used
RS CON 4 ' Register Select (1 = char)
E CON 5 ' LCD Enable pin (1 = enabled)

' LCD control characters
'
ClrLCD CON $01 ' clear the LCD
CrsrHm CON $02 ' move cursor to home position
CrsrLf CON $10 ' move cursor left
CrsrRt CON $14 ' move cursor right
DispLf CON $18 ' shift displayed chars left
DispRt CON $1C ' shift displayed chars right
DDRam CON $80 ' Display Data RAM control

' -----[ Variables ]-------------------------------------------------------
'
char VAR Byte ' character sent to LCD
index VAR Byte ' loop counter

' -----[ EEPROM Data ]-----------------------------------------------------
'
Msg DATA "BASIC Stamp 2 LCD in action" ' preload message

' -----[ Initialization ]--------------------------------------------------
'
Init: DirL = %00111111 ' set pins 0-5 as outputs
Outs = $0000 ' clear the pins

' Initialize the LCD (Hitachi HD44780 controller)
'
LCDinit: pause 500 ' Wait for LCD init
' =================================
' STANDARD HITACHI 44780 4-BIT INIT
' =================================
char=%00000011 ' Set 8-bit mode (1)
GOSUB LCDcmd
char=%00000011 ' Set 8-bit mode (2)
GOSUB LCDcmd
char=%00000011 ' Set 8-bit mode (3)
GOSUB LCDcmd
char=%00000010 ' Set 4-bit mode
GOSUB LCDcmd
char=%00101111 ' Set duty cycle 11xx = 5x11 matrix
GOSUB LCDcmd ' 10xx = 5x8 matric
char=%00000000 ' Display control mode
GOSUB LCDcmd
char=%00001000 ' Set display OFF, cursor OFF, blink OFF
GOSUB LCDcmd
char=%00000000 ' Display control mode
GOSUB LCDcmd
char=%00001111 ' Set display ON, cursor ON, blink ON
GOSUB LCDcmd ' 11CB -> C=1 cursor on, B=1 blink on
char=%00000000 ' Entry control mode
GOSUB LCDcmd
char=%00000110 ' Set cursor right, no display shift
GOSUB LCDcmd ' 01IS -> I=1 cursor right, S=1 shift display

char = ClrLCD ' Clear LCD
GOSUB LCDcmd

' -----[ Main Code ]-------------------------------------------------------
'
Start:
FOR index = 0 TO 39
READ Msg + index, char ' get character from memory
GOSUB LCDwr ' write it to the LCD
NEXT

PAUSE 1000 ' wait 2 seconds

char = ClrLCD ' clear the LCD
GOSUB LCDcmd

PAUSE 500
GOTO Start ' do it all over

' -----[ Subroutines ]-----------------------------------------------------
'
' Send command to the LCD
'
LCDcmd: LOW RS ' enter command mode

'
' Write ASCII char to LCD
'
LCDwr:
OutA = char.HIGHNIB ' output high nibble
PULSOUT E, 1 ' strobe the Enable line
OutA = char.LOWNIB ' output low nibble
PULSOUT E, 1
HIGH RS ' return to character mode
RETURN




So, my problem is, the first line displays "Basic Stamp 2 LC" and does not continue the remaining "D in action" in the next line. Is there anyone here who is experienced at all with LCD's who can help me?
the exact LCD I'm using is this one (http://jameco.com/webapp/wcs/stores/servlet/ProductDisplay?langId=-1&storeId=10001&catalogId=10001&productId=135760)

thank you very much,
Justin

Forrest
02-05-2005, 07:41 PM
First, let me say I'm NO LCD expert - I'm just a rank beginner here. But I recently connected a 16 x 2 line parallel LCD display to a BS2 and ran the program posted on Nuts and Volts issue #31 and it worked perfectly. Issue #32 also has more LCD information and programs. You can download the articles and programs here www.parallax.com/html_pages/downloads/nvcolumns/Nuts_Volts_Download_V1.asp (http://www.parallax.com/html_pages/downloads/nvcolumns/Nuts_Volts_Download_V1.asp)

I noticed some differences in your circuit and program, but I don't know if they're significant. Pins 7, 8, 9 and 10 on the LCD are all connected to ground on issue #31. Secondly, the initialization code is different - specifically there's a PAUSE 5 command in the middle of the 8-bit initialization routine.

Gadgetman
02-05-2005, 09:48 PM
Just one quick question....

Why is it looping for 40 iterations (0 to 39) when there's only 27 characters in the string?

Whelzorn
02-05-2005, 10:08 PM
ahhh. very nice code. Thank you forrest, that allows me to understand this LCD stuff quite a bit more, but it still doesn't really solve my problem. What I acyually want to do, is access the second line of my 16x2 display. I can do anything I want on the first line, but I have no idea how to display anything, or move the cursor to the bottom line of the display.

oh yeah, the reason it's looping for 40 iterations is because that's the demo code, the person was working with a larger display. In my modification of has code, I actually did change it.

Post Edited (Whelzorn) : 2/5/2005 3:12:34 PM GMT

Forrest
02-05-2005, 10:44 PM
Download Nuts and Volts #32 - there's a BS2 program that uses both lines on a 16 x 2 character LCD display.

Whelzorn
02-05-2005, 11:25 PM
Aah, ok, thank you very much. Works perfectly!