Shop OBEX P1 Docs P2 Docs Learn Events
LCD terminal AppMod — Parallax Forums

LCD terminal AppMod

LutamosLutamos Posts: 26
edited 2009-01-13 18:14 in BASIC Stamp
I bout this LCD because of the buttons thought I could use them for later uses. I am finding that it is harder to program and do what I want with this LCD than a serial LCD. I am studying the demo code for it trying to figure out how to get it to work and been scan the forums to see if there is someone with my issue. I am wanting to use the LCD for the debug terminal with the thermometer chip. If some one could post a url of some sample code or some code of how to get the stamp to send the debug info to this LCD be greatly welcomed.


Thank you
Lutamos

Comments

  • sylvie369sylvie369 Posts: 1,622
    edited 2009-01-10 16:31
    I had a hard time finding this thread, but here's my best effort at making this simpler:

    http://forums.parallax.com/showthread.php?p=771280

    I had to include my username in the search to find it, so I can see why you couldn't find it.

    The key parts of the code related to the buttons are these:

    (in the declarations[noparse]:)[/noparse]

    buttons VAR Nib
    btnA    VAR buttons.BIT0 ' left-most button
    btnB    VAR buttons.BIT1
    btnC    VAR buttons.BIT2
    btnD    VAR buttons.BIT3 ' right-most
    



    This declares a nibble-sized (that is, 4 bit) variable "buttons", and then names each of those 4 bits. The variables btnA, btnB, btnC and btnD are just the 4 bits that make up the variable "buttons".

    LCD_Get_Buttons:
    LcdDirs = %0000                    ' make LCD bus inputs
    buttons = %1111                    ' assume all pressed
    FOR scan = 1 TO 10
      buttons = buttons & LcdBusIn     ' make sure button held
      PAUSE 5                          ' debounce 10 x 5 ms
    NEXT
    LcdDirs = %1111                    ' return bus to outputs
    RETURN
    



    The comments for that part of the code make it pretty clear what's happening, I think.

    Since the same I/O lines are used to read the buttons and to send data to the LCD, those lines must be made into inputs before the buttons can be read, and then made back into outputs afterwards so that information can be sent to the LCD. Those are the first and last lines of the subroutine.

    Next you want to read the state of those four lines into the "buttons" variable. Simply reading it in once would give you the dreaded "bounce" problem, so instead there's a loop to ensure that a button is pressed for real. The 4 bits are all set to "1" at the start of that loop, and then inside of the loop, each bit is ANDed with the current state of its corresponding LcdBusIn line (that is, with its I/O line). If a button is not pressed, its line will be "0", and when you AND 1 with 0, you get 0. If a button is pressed, its line will be "1", and when you AND that with 1, you get 1. As a result, the 4 bits of the "buttons" variable will correspond to the 4 bits of the LcdBusIn at the end of that 50 ms loop.

    Earlier code uses the "buttons" variable to choose what to display on the LCD:

    FOR idx = 0 TO 3        ' display buttons
          IF buttons.LOWBIT(idx) THEN
            char = "A" + idx    ' button letter if pressed
          ELSE
            char = "-"          ' otherwise dash
          ENDIF
    



    This is a bit more cryptic (though efficient) than it might need to be for a demo program. When idx = 0, it looks at the lowest bit of the buttons variable (that is, btnA), and if that bit is set (=1), it displays the character defined by "A" + 0, which is simply "A". If that bit is 0, then it displays a dash.

    Then it goes on to idx = 1. It asks "Is the second lowest bit of the buttons variable set?". That is, buttons.LOWBIT(1), which is a reference to btnB (see how confusing it is?). If so, then it displays the character defined by "A" + 1, which is "B". What's going on there is that "A" gives you ascii 65, and you can simply treat "A" as though it were another way of saying 65, adding and subtracting numbers to it to your heart's content. "A" + 1 is simply 66, which is ascii "B", so char = 66, and when it's displayed, you get a "B". Clever, but cryptic for us newbies.

    Notice though that if he hadn't done it that way, there'd have to be a mess of IF-THENs with all of the different letters to display. It'd be easier to read, but much less efficient code.

    Post Edited (sylvie369) : 1/10/2009 4:50:32 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-01-12 19:26
    Sylvie,

    That code unfortunately does not display the value of numeric variables. To be honest I cannot believe we haven’t put something up. So what I have done is take the Stamp Works Experiment #11 code and remove the cursor animation and replace it with a simple counter loop that counts from 0 through 65535. This value is then displayed on line 2 of the Parallel LCD. There are two versions of the code and below is an explanation. I hope this helps and it will be listed on our Parallel LCD product page as well.

    Parallel LCD Vars Leave.bs2 – This program demonstrates how to display up to a 16-bit numeric variable on a parallel LCD using the StampWorks Parallel LCD code as framework. To use this code, connect your Parallel LCD as per the StampWorks Kit Experiment #11 and then download and run this code. This version leaves leading zeros in values printed. This can often help preserve display formatting when items are printed to the right of the variable.

    Parallel LCD Vars Strip.bs2 – This program demonstrates how to display up to a 16-bit numeric variable on a parallel LCD using the StampWorks Parallel LCD code as framework. To use this code, connect your Parallel LCD as per the StampWorks Kit Experiment #11 and then download and run this code. This version strips leading zeros in values printed.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-01-12 20:29
    After I posted the above message I realized you needed this specifically for the AppMod (I have been replying to more than one similar thread).· Okay, so the code for the AppMod version is below.· Let me know how this works out for you.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • LutamosLutamos Posts: 26
    edited 2009-01-13 17:15
    Thank you for both responding to my post. I was looking over the code you posted and I was wondering if I could display a temperature value , By using that (char = LcdLine 2) where debugs gos in the ds1620 example code? I suppose it is a bit more complicated than that though. I attached the example code for the DS1620 so you know what I am looking at.


    Thank, you
    Lutamos
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-01-13 18:14
    Char = LcdLine2 sets the command for telling the LCD to jump to the address where line 2 starts. The GOSUB then calls the routine that send that command. In my code example what is printing the values is loading the variable ‘counter’ and the using GOSUB Write_Var. The variable ‘counter’ can contain a value from 0 – 65535. In the code you posted the output is sent to the DEBUG Screen using signed decimal formatting, however there are ways you can make this work, or you can use DS1620 code that prints the temp as an integer. There are several such codes available for the DS1620, including a Digital Thermostat program I posted in the forums a few times. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
Sign In or Register to comment.