Shop OBEX P1 Docs P2 Docs Learn Events
Redirect DEBUG (Sout) to attached LCD? — Parallax Forums

Redirect DEBUG (Sout) to attached LCD?

Matt NowinskiMatt Nowinski Posts: 5
edited 2005-11-15 07:19 in BASIC Stamp
Hello All!

I've got a parallel LCD attached and working with my BoeBot. Currently, I am using the code provided by the generous folks at Parallax in which the output strings intended for the LCD are contained in EEPROM via the DATA command. When I first thought about installting the LCD, it was my hope to use it to accept debugging data. Now, I'm not exactly sure how to make this happen...

Can I build char arrays manually (easily) to send to the LCD?

Could I redirect DEBUG output (Sout) to another pin and use the SERIN command to build that char array?

Any ideas?

Thanks,

matt

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2005-11-14 14:36
    DEBUG is set up for you primary Serial Port, while the LCD is parrallel.

    This is similar to comparing going to San Francisco on a train with going to New York on an airplane.

    You have different destinations and different vehicles.

    The good news is that you start out with the same starting point and the same material to transport.

    In sum, yes you can do it, but it certainly isn't DEBUG. And your LCD routine depends on which BasicStamp you are using.
    The newer models can run a special LCD routine, while the older ones require more code to first intialize the LCD and to actually transport the code.

    Additionally, the LCD has some choices and limitations of formating that are not the same as DEBUG. Obviously, you cannot have a whole screen of output, but you also cannot have more than a limited length of lines. This will lead you to think more carefully about how you format messages and data. Abbreviatons and frequent refreshing of the screen may offer solutions.

    Anyone else want to comment?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-14 16:38
    You could do it by using Conditional Compilation.· First, you define a conditional switch:

    #DEFINE __DEBUG_Mode = 1

    Then in your program you would have conditional blocks like this:

    #IF __DEBUG_Mode #THEN
    · ' send data to to Debug terminal with DEBUG
    #ELSE
    · ' send dat to LCD with appropriate commands
    #ENDIF

    When you want to use the LCD you change the #DEFINE line to:

    #DEFINE __DEBUG_Mode = 0

    Conditional Compilation takes a litte bit of time to get use to, but it's tremendously powerful when you do.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Matt NowinskiMatt Nowinski Posts: 5
    edited 2005-11-15 02:53
    Kramer and Jon,

    Thanks so much for the replies. Unfortunately, as usual, I think I have complicated the answer by not asking a clear question.

    Here's my attempt to do better:

    I am currently using the code found here to send messages to the LCD:

    http://www.parallax.com/detail.asp?product_id=603-00006

    (thanks Parallax!)
    (the code is attached below)

    What I am really interested in is what is the easiest way to send variable strings to this routine (rather than a static one from EEPROM). How can I avoid pre-loading all of my messages? I thought about building a char array, but is there a way to do it other than one letter at a time? That's where my idea to redirect DEBUG (connect Sout to another Pin, e.g. Px) came from - because I know that SERIN can build such an array from NULL-terminated input. However, maybe this is way off - I'm not sure. Any help is sincerely appreciated.

    Thanks again,

    matt

    ' =========================================================================
    ' File...... Parallel_LCD_2X16.bs2
    ' Purpose... Parallel LCD Display Demo
    ' Author.... Parallax, Inc.
    ' E-mail.... support@parallax.com
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    [noparse][[/noparse] Program Description ]
    ' This program demonstrates using a Hitachi-compatible Parallel LCD Display
    ' This code works with the BS2, BS2e and BS2sx
    '
    [noparse][[/noparse] I/O Definitions ]
    E PIN 0 ' Enable Pin For LCD
    RW PIN 2 ' R/W Pin For LCD
    RS PIN 3 ' LCD Register Select
    ' 0 = Instruction, 1 = Text
    '
    [noparse][[/noparse] Variables ]
    char VAR Byte ' Character To Send To LCD
    inst VAR char ' Induction To Send To LCD
    index VAR Word ' Character Pointer
    temp VAR Byte ' Temp Variable
    '
    [noparse][[/noparse] EEPROM Data ]
    DATA "Hello, this is the LCD demo." ' Message To Send To LCD
    '
    [noparse][[/noparse] Initialization ]
    Initialize:
    LOW RW ' Set LCD To Write Mode
    OUTS = %0000000000000000 ' Set All Output Low
    DIRS = %0000000011111111 ' Set I/O Direction
    GOSUB Init_Lcd ' Initialize The LCD Display
    '
    [noparse][[/noparse] Program Code ]
    Main:
    FOR temp = 0 TO 27 ' 28 Characters
    IF temp = 15 THEN ' Check For End Of Line
    GOSUB Next_Line ' Jump To Next Line
    ENDIF
    READ temp, char ' Read Next Character From EEPROM
    GOSUB Send_Text ' Send Character To LCD Display
    NEXT
    END
    '
    [noparse][[/noparse] Subroutines ]
    Init_Lcd:
    PAUSE 200
    OUTS = %00110000 ' Reset The LCD
    PULSOUT E,1 ' Send Command Three Times
    PAUSE 10
    PULSOUT E,1
    PAUSE 10
    PULSOUT E,1
    PAUSE 10
    OUTS = %00100000 ' Set To 4-bit Operation
    PULSOUT E,1
    Inst = %00101000 ' Function Set (2-Line Mode)
    GOSUB Send_Inst
    Inst = %00001110 ' Turn On Cursor
    GOSUB Send_Inst
    Inst = %00000110 ' Set Auto-Increment
    GOSUB Send_Inst
    Inst = %00000001 ' Clears LCD
    GOSUB Send_Inst
    Inst = 14 ' Set Cursor To Underline
    GOSUB Send_Inst
    RETURN
    Send_Inst:
    LOW RS ' Set Instruction Mode
    OUTB = Inst.HIGHNIB ' Send High Nibble
    PULSOUT E,1
    OUTB = Inst.LOWNIB ' Send Low Nibble
    PULSOUT E,1
    HIGH RS ' Set LCD Back To Text Mode
    RETURN
    Send_Text:
    OUTB = Char.HIGHNIB ' Send High Nibble
    PULSOUT E,1
    OUTB = char.LOWNIB ' Send Low Nibble
    PULSOUT E,1
    PAUSE 100
    RETURN
    Next_Line:
    Inst = 128+64 ' Move Cursor To Line 2
    GOSUB Send_Inst
    RETURN
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-11-15 07:19
    Matt -

    Let me answer your question in a non-technical, indirect manner, just to show you something you may not realize. I suspect you may be able to answer your own question in the end. Please don't take anything I say personally! Accept that "you" is in the generic third person.

    Based on what you've said, you would like to use an inexpensive type of LCD (very general description of a parallel interfaced LCD - $4.00 and up) and its interface, both for input and output purposes (asking quite a bit from an inexspensive solution), you'd like to be able to use the canned code you already have (thus putting in little to no effort yourself), which was not designed for anything but embedded messages, to output any type of message of any finite length (adding some pretty extreme flexibility to a canned routine which was designed for general purpose use), and yet you add "What I am really interested in is what is the easiest way to send variable strings to this routine" implying that this be simple too.

    When stated as I did, that's asking a bit much, don't you think?

    How about we just change one criteria? We don't demand that it be a parallel interface, thus saving us a WHOLE bunch of Stamp pins in the process! If that were the case, then input and output might look like this (this is just sample code and is neither correct nor proper for any particular 2 x 16 LCD):

    SEROUT lcdpin, baudmode, [noparse][[/noparse]POSN0, TAB, "Variable 1 ", " Variable 2 ", " Variable 3 "] 'Line 1
    SEROUT lcdpin, baudmode, [noparse][[/noparse]POSN17,"data is: ", var1, var2, var3, var4] 'Line 2
    PAUSE 200
    SEROUT lcdpin, baudmode, [noparse][[/noparse]CLS]
    SEROUT lcdpin, baudmode, [noparse][[/noparse]POSN0, "Enter compensation adjustment (nn)?
    SERIN lcdpin, baudmode, [noparse][[/noparse]comp_adj] 'Fetch input data

    That gives you all the ease of use you could want, and you can output any kind of data the Stamp is capable of handling, as you see fit. Generally, LCD line positioning commands are available, as well as line feed and carriage return type functions. Often one has the ability to add custom characters as well. How about the cost of all this flexability, and all these features?

    The most often heard criticism about using a serially accessed LCD's is the cost. That all depends on how you implement it, I suppose. There are many fine, inexpensive, surplus, parallel acessed LCD's available which use the Hitachi HD44780 interface (or equivalent). You can figure anywhere from $5.00 to $15.00 for that part of the expense, depending on your needs. Then just use a serial-to-parallel LCD support chip with keypad input capability. Figure about $14.00 for the support chip portion of the expense. The raw total is now in the neighborhood of $20.00 to $25.00 (plus or minus) to get the kind of flexibilty you seem to want. You would have to add to that the price of a surplus, standard matrix keypad at $5.00 to $10.00. Similar, pre-built solutions, will probably cost a bit more. Parallax offers a top of the line, serial accessed, 2 x 20 LCD with serial input capability for $79.95 here:
    http://www.parallax.com/detail.asp?product_id=30057

    I should have more information about a nice serial-to-parallel LCD support chip with I/O capabilities tomorrow, in the price range noted, if that interests you.

    Regards,

    Bruce Bates

    Post Edited (Bruce Bates) : 11/15/2005 7:26:13 AM GMT
Sign In or Register to comment.