Shop OBEX P1 Docs P2 Docs Learn Events
BS2 and LCD problem — Parallax Forums

BS2 and LCD problem

ScooterScooter Posts: 11
edited 2012-07-04 01:21 in BASIC Stamp
Hello everybody,
After some successfully project i tried some programming experiments with lcd, but i am experiencing a strange behaviour with this code.
The source of the program comes from the Stamp Works manual and i made some change to suit my needs.
The lcd connected to the BS2 simply should display text strings (wich are stored in eeprom with DATA command) on 20 characters/two lines display.
As you can see in the code i have 14 strings which are displayed on first and second line each message and everything works fine from string m1 to string m12, then when it should be displayed the 7th message the string m13 (first line) is displayed truncated and in the second line is displayed the m1 string again.
I just can't figure it out why, if someone will help me to understand i'll be very glad

Thanks
Scooter
' {$STAMP BS2}
' {$PBASIC 2.5}
' ------------------------------------------------------------------------------
' Program Description
' ------------------------------------------------------------------------------
' This program demonstrates essential character LCD control.
'
' The connections for this program conform to the BS2p LCDIN and LCDOUT
' commands. Use this program for the BS2, BS2e or BS2sx. There is a separate
' program for the BS2p.
' ------------------------------------------------------------------------------
' I/O Definitions
' ------------------------------------------------------------------------------
E CON 0 ' LCD Enable pin (1 = enabled)
RS CON 3 ' Register Select (1 = char)
LCDbus VAR OUTB ' 4-bit LCD data bus
' ------------------------------------------------------------------------------
' Constants
' ------------------------------------------------------------------------------
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
Sld CON $C0 ' second line of LCD
' ------------------------------------------------------------------------------
' Variables
' ------------------------------------------------------------------------------
char VAR Byte  ' character sent to LCD
index VAR Byte ' loop counter
msg VAR Byte
reps VAR Word
' ------------------------------------------------------------------------------
' Initialization
' ------------------------------------------------------------------------------
Initialize:
DIRL = %11111101 ' setup pins for LCD
LCD_Init:
PAUSE 500 ' let the LCD settle
PULSOUT E, 1
LCDbus = %0010 ' 4-bit mode
PULSOUT E, 1
char = %00001100 ' disp on, crsr off, blink off
GOSUB LCD_Command
char = %00000110 ' inc crsr, no disp shift
GOSUB LCD_Command
'--------------------------------------------------------------------------------
' EEPROM DATA
'--------------------------------------------------------------------------------
 m1 DATA "Collaudo VFG_ISA_C  ", 1
 m2 DATA "OK -> inizia        ", 1
 m3 DATA "Verifica leds accesi", 1
 m4 DATA "AD AS CD CS PD PS   ", 1
 m5 DATA "Verifica leds accesi", 1
 m6 DATA "PD PS               ", 1
 m7 DATA "Premi AD e verifica ", 1
 m8 DATA "led AD acceso 7 sec.", 1
 m9 DATA "Premi AS e verifica ", 1
m10 DATA "led AS acceso 7 sec.", 1
m11 DATA "Premi CD e verifica ", 1
m12 DATA "led CD acceso 7 sec.", 1
m13 DATA "Premi CS e verifica ", 1
m14 DATA "led CS acceso 7 sec.", 1
' ------------------------------------------------------------------------------
' Program Code
' ------------------------------------------------------------------------------
'step 1 : welcome ed attesa start
char = ClrLCD
GOSUB LCD_Command
PAUSE 500
index = m1
GOSUB Read_Char
char = Sld
GOSUB LCD_Command
PAUSE 500
index = m2
GOSUB Read_Char
PAUSE 500
'---------------------------------------------------------------
'step 2 : verifica led AD AS PCD CS PD PS accesi
char = ClrLCD
GOSUB LCD_Command
PAUSE 500
index = m3
GOSUB Read_Char
char = Sld
GOSUB LCD_Command
PAUSE 500
index = m4
GOSUB Read_Char
PAUSE 500
'----------------------------------------------------------------
'step 3 : verifica led PD PS accesi
char = ClrLCD
GOSUB LCD_Command
PAUSE 500
index = m5
GOSUB Read_Char
char = Sld
GOSUB LCD_Command
PAUSE 500
index = m6
GOSUB Read_Char
PAUSE 500
'----------------------------------------------------------------
'step 4 : attesa pulsante AD e verifica led AD 7 sec.
char = ClrLCD
GOSUB LCD_Command
PAUSE 500
index = m7
GOSUB Read_Char
char = Sld
GOSUB LCD_Command
PAUSE 500
index = m8
GOSUB Read_Char
PAUSE 500
'----------------------------------------------------------------
'step 5 : attesa pulsante AS e verifica led AS 7 sec.
char = ClrLCD
GOSUB LCD_Command
PAUSE 500
index = m9
GOSUB Read_Char
char = Sld
GOSUB LCD_Command
PAUSE 500
index = m10
GOSUB Read_Char
PAUSE 500
'----------------------------------------------------------------
'step 6 : attesa pulsante CD e verifica led CD 7 sec.
char = ClrLCD
GOSUB LCD_Command
PAUSE 500
index = m11
GOSUB Read_Char
char = Sld
GOSUB LCD_Command
PAUSE 500
index = m12
GOSUB Read_Char
PAUSE 500
'----------------------------------------------------------------
'step 7 : attesa pulsante CS e verifica led CS 7 sec.
char = ClrLCD
GOSUB LCD_Command
PAUSE 500
index = m13
GOSUB Read_Char
END
char = Sld
GOSUB LCD_Command
PAUSE 500
index = m14
GOSUB Read_Char
PAUSE 500
END
' ------------------------------------------------------------------------------
' Subroutines
' ------------------------------------------------------------------------------
LCD_Command:
LOW RS ' enter command mode
'-------------------------------------------------------------------------------
LCD_Write:
LCDbus = char.HIGHNIB ' output high nibble
PULSOUT E, 1 ' strobe the Enable line
LCDbus = char.LOWNIB ' output low nibble
PULSOUT E, 1
HIGH RS ' return to character mode
RETURN
'-------------------------------------------------------------------------------
Read_Char:
READ index, char ' get character from EEPROM
IF (char = 1) THEN Msg_Done ' if 0, message is complete
GOSUB LCD_Write ' write the character
index = index + 1 ' point to next character
GOTO Read_Char ' go get it
'-------------------------------------------------------------------------------
Msg_done:
RETURN

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2012-07-03 05:18
    Scooter,

    It almost sounds like some buffer is filling up and then wrapping around to the beginning.

    Just as a test, modify your program so m11, m12 are not called, just to check if m13, m14 will be displayed correctly.

    The Stamp certainly would have enough space for your data (assuming your program doesn't have 500-600 extra lines of code somewhere) so it must be a buffer in the display. Is there a command to clear the display buffer?

    Cheers,
  • ScooterScooter Posts: 11
    edited 2012-07-03 06:03
    Hi stamptrol,
    Thanks for you suggestion,
    i checked the memory usage of the BS2 and is 30% used so i'm assuming that the problem is not into the Bs2 itself
    i modified the program remarking the lines that calls m11 and m12, but no change,
    i think that you're right about the lcd buffer, now i will try to find some more info about the LCD.

    cheers
    Scooter
  • ScooterScooter Posts: 11
    edited 2012-07-03 07:22
    Found the manual and the commands table but i still can't figure out what is wrong in the code ...
  • stamptrolstamptrol Posts: 1,731
    edited 2012-07-03 08:06
    If all instructions were written like that, I think I'd go sell hot dogs on some beach somewhere!

    It certainly isn't clear (to me anyway) how your problem could be occuring. Section 8 seems to be reasonably clear where the data will arrive and where it will show on the display.

    Perhaps you could (as a test anyway) clear the registers before sending new data to see if that helps.

    For what its worth, I usually use displays with a serial interface, where a small on-board processor takes care of the mechanics of dealing with the display hardware. Really helps in speeding development.

    Cheers,
  • SapphireSapphire Posts: 496
    edited 2012-07-03 17:04
    Scooter,

    The problem is index is a byte, but you have more than 255 characters in all your messages. Make index a word variable and it should work.
  • ScooterScooter Posts: 11
    edited 2012-07-04 01:21
    Hi Sappire, good shooting, you are right, the problem was there, changed from byte to word and everything is OK now.
    Many thanks
    Scooter
Sign In or Register to comment.