Shop OBEX P1 Docs P2 Docs Learn Events
Parallax 2x16 Serial LCD (Backlit) not working with SX — Parallax Forums

Parallax 2x16 Serial LCD (Backlit) not working with SX

Capt MagellanCapt Magellan Posts: 6
edited 2010-11-02 19:40 in General Discussion
Hi Guys,

I am loosing sleep over this....I am trying to get to work the Parallax 2x16 Serial LCD with my SX chip, which I am learning to use since yesterday. I am sure it is not a challenging problem but I simply cannot figure it out...I suspect something with the LCDBaud parameter as the LCD works in Demo mode or with any BasicStamp2 modules. Yes I have tried to set also different Baund parameter but no luck.

The code I am using is the one given for "SX/B Sample Code (.zip)" at the: http://www.parallax.com/Store/Accessories/Displays/tabid/159/CategoryID/34/List/0/SortField/0/Level/a/ProductID/50/Default.aspx

Any help very much appreciated.

BR/Dino

' =========================================================================
'
' File...... SERIAL_LCD_DEMO.SXB
' Purpose... Demonstrates the Parallax Serial LCD with SX/B
' Author.... (c) Parallax, Inc. -- All Rights Reserved
' E-mail.... support@parallax.inc
' Started...
' Updated... 13 NOV 2005
'
' =========================================================================


'
' Program Description
'


'
' Device Settings
'

DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ 4_000_000


'
' IO Pins
'

LcdTx VAR RA.0 ' LCD serial connection


'
' Constants
'

LcdBaud CON "T19200" ' or T2400, or T9600

LcdBkSpc CON $08 ' move cursor left
LcdRt CON $09 ' move cursor right
LcdLF CON $0A ' move cursor down 1 line
LcdCls CON $0C ' clear LCD (need 5 ms delay)
LcdCR CON $0D ' move pos 0 of next line
LcdBLon CON $11 ' backlight on
LcdBLoff CON $12 ' backlight off
LcdOff CON $15 ' LCD off
LcdOn1 CON $16 ' LCD on; no crsr, no blink
LcdOn2 CON $17 ' LCD on; no crsr, blink on
LcdOn3 CON $18 ' LCD on; crsr on, no blink
LcdOn4 CON $19 ' LCD on; crsr on, blink on
LcdLine1 CON $80 ' move to line 1, column 0
LcdLine2 CON $94 ' move to line 2, column 0

LcdCC0 CON $F8 ' define custom char 0
LcdCC1 CON $F9 ' define custom char 1
LcdCC2 CON $FA ' define custom char 2
LcdCC3 CON $FB ' define custom char 3
LcdCC4 CON $FC ' define custom char 4
LcdCC5 CON $FD ' define custom char 5
LcdCC6 CON $FE ' define custom char 6
LcdCC7 CON $FF ' define custom char 7


'
' Variables
'

idx1 VAR Byte ' loop control
idx2 VAR Byte
char VAR Byte
newChar VAR Byte
pos VAR Byte ' position

temp1 VAR Byte ' subroutine work vars
temp2 VAR Byte
temp3 VAR Byte
temp4 VAR Byte
temp5 VAR Byte


' =========================================================================
PROGRAM Start
' =========================================================================


'
' Subroutine Declarations
'

WAIT_MS SUB 1, 2 ' delay in milliseconds
LCD_OUT SUB 1, 2 ' send byte {+ count} to LCD
LCD_STR SUB 2 ' send string to LCD
LCD_CCHAR SUB 2 ' define custom character


'
' Program Code
'

Start:
PLP_A = %0001 ' pull up unused pins
PLP_B = %00000000
PLP_C = %00000000

HIGH LcdTx
WAIT_MS 100 ' let LCD initialize
LCD_CCHAR CC0 ' download custom characters
LCD_CCHAR CC1
LCD_CCHAR CC2
LCD_CCHAR Smiley


Main:
LCD_OUT LcdBLoff ' backlight off
LCD_OUT LcdOn1 ' no cursor or blink
LCD_OUT LcdCls ' clear the LCD
WAIT_MS 250
LCD_STR " PARALLAX SX/B "

' Scroll "chomper" animation across LCD line 2

Animation:
FOR idx1 = 0 TO 15 ' scroll across line
READ Msg2 + idx1, newChar ' read new character
FOR idx2 = 0 TO 4 ' animate a current position
LOOKUP idx2, 0, 1, 2, 1, newChar, char
pos = LcdLine2 + idx1
LCD_OUT pos
LCD_OUT char
WAIT_MS 75
NEXT
NEXT

' Flash LCD backlight (works only with backlit model)

Flash:
FOR idx1 = 1 TO 4
LCD_OUT LcdBLon
WAIT_MS 250, 3
LCD_OUT LcdBLoff
WAIT_MS 250
NEXT

GOTO Main


'
' Subroutine Code
'

' Use: WAIT_MS milliseconds {, multiplier }
' -- multiplier is optional

WAIT_MS:
temp1 = __PARAM1 ' get milliseconds
IF __PARAMCNT = 1 THEN ' if no multiplier
temp2 = 1 ' set to 1
ELSE ' else
temp2 = __PARAM2 ' get multiplier
ENDIF
IF temp1 > 0 THEN ' no delay if either 0
IF temp2 > 0 THEN
PAUSE temp1 * temp2 ' do the delay
ENDIF
ENDIF
RETURN

'

' Use: LCD_OUT theByte {, count }
' -- sends "theByte" to LCD [optional] "count" times
' -- "count" defaults to 1 if not specified

LCD_OUT:
temp1 = __PARAM1 ' save the byte
IF __PARAMCNT = 2 THEN ' "count" specified?
temp2 = __PARAM2 ' yes, save
ELSE
temp2 = 1 ' no, set to 1
ENDIF
DO WHILE temp2 > 0
SEROUT LcdTx, LcdBaud, temp1 ' transmit to LCD
DEC temp2
LOOP
RETURN

'

' Use: LCD_STR [ string | label ]
' -- "string" is an embedded literal string
' -- "label" is DATA statement label for stored z-String

LCD_STR:
temp3 = __PARAM1 ' get string offset
temp4 = __PARAM2 ' get string base
DO
READ temp4 + temp3, temp5 ' read a character
IF temp5 = 0 THEN EXIT ' if 0, string complete
LCD_OUT temp5 ' send the byte
INC temp3 ' point to next character
temp4 = temp4 + Z ' update base on overflow
LOOP
RETURN

'

' Use: LCD_CCHAR CharDef
' -- loads custom character definition into serial LCD
' -- "CharDef" is DATA table that holds character number and definition
' bytes

LCD_CCHAR:
temp3 = __PARAM1 ' get definition offset
temp4 = __PARAM2 ' get definition base
FOR idx1 = 0 TO 8
READ temp4 + temp3, temp5 ' read a byte
LCD_OUT temp5 ' send the byte
INC temp3 ' point to next
temp4 = temp4 + Z ' update base on overflow
NEXT
RETURN


' =========================================================================
' Program Data
' =========================================================================

CC0:
DATA LcdCC0, $0E, $1F, $1C, $18, $1C, $1F, $0E, $00

CC1:
DATA LcdCC1, $0E, $1F, $1F, $18, $1F, $1F, $0E, $00

CC2:
DATA LcdCC2, $0E, $1F, $1F, $1F, $1F, $1F, $0E, $00

Smiley:
DATA LcdCC3, $00, $0A, $0A, $00, $11, $0E, $06, $00

Msg2:
DATA "IS VERY COOL! ", 3, 0

Comments

  • ZootZoot Posts: 2,227
    edited 2010-11-02 19:40
    Certainly, I would try this:
    LcdTx	 PIN	RA.0	 ' LCD serial connection
    

    Second, I think you indicate that you copied these routines from some other source? I'm a bit tired, so maybe I'm missing something, but the way the Word addresses of literal or labeled strings/tables doesn't seem quite right in the subroutines, e.g.,

    my reading of the following snippet would not lead to a correct "read" from a data location (either labeled or embedded) because the address should be a WORD value, and when it gets split into tempX and tempY (as lowbyte and highbyte of the passed address), then ADDED, the address wouldn't be right. At least that's how it looks to me unless there is something I'm missing...
    ' Use: LCD_STR [ string | label ]
    ' -- "string" is an embedded literal string
    ' -- "label" is DATA statement label for stored z-String
    
    LCD_STR:
    temp3 = __PARAM1 ' get string offset
    temp4 = __PARAM2 ' get string base
    DO
    READ temp4 + temp3, temp5 ' read a character
    ' really you would want the above to be as if it were:
    ' READ ( temp4 << 8 ) + temp3
    ' but you can't do that in SX/B
    IF temp5 = 0 THEN EXIT ' if 0, string complete
    LCD_OUT temp5 ' send the byte
    INC temp3 ' point to next character
    temp4 = temp4 + Z ' update base on overflow
    LOOP
    RETURN
    

    So, if you had a word temp to use for addresses, that would seem to be more correct, e.g.,

    ' Use: LCD_STR [ string | label ]
    ' -- "string" is an embedded literal string
    ' -- "label" is DATA statement label for stored z-String
    
    tmpW1 VAR Word
    
    LCD_STR:
    tmpW1 = __WPARAM12 ' get string address
    DO
      READ tmpW1, temp5 ' read a character
      IF temp5 = 0 THEN EXIT ' if 0, string complete
      LCD_OUT temp5 ' send the byte
      INC tmpW1 ' point to next character
    LOOP
    RETURN
    
Sign In or Register to comment.