Shop OBEX P1 Docs P2 Docs Learn Events
lcd display help — Parallax Forums

lcd display help

blackniteblacknite Posts: 4
edited 2011-06-12 01:46 in BASIC Stamp
I have a 4x16 lcd display that I got to display the "Hello, this is the LCD demo." text using the code from parallax. but now i want it to display a variable now. Also this variable constantly changes so I don't believe i can write it to the eeprom. Any help on how to display my variable.

Comments

  • vaclav_salvaclav_sal Posts: 451
    edited 2011-06-09 19:04
    Welcome to the forum.
    Your “Hello word...” is most likely in DATA memory in you sample program and from there written to LCD memory. The LCD controller takes it from there and displays it.
    You need to find the LCD memory addresses ( it should be in your sample program) and simply write your variable to it from the code itself.
    I would suggest you look at the LCD spec to became familiar with how the LCD interacts with the microprocessor. You may find some extra RAM usable as an additional storage for your future programs in the LCD itself.
    If you have difficulty finding the LCD address , post your code here.
    Cheers Vaclav
  • blackniteblacknite Posts: 4
    edited 2011-06-09 19:35
    vaclav_sal wrote: »
    Welcome to the forum.

    You need to find the LCD memory addresses ( it should be in your sample program) and simply write your variable to it from the code itself.

    If you have difficulty finding the LCD address , post your code here.
    Cheers Vaclav

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    E PIN 0
    RW PIN 2
    RS PIN 3
    CS PIN 13
    CLK PIN 14
    DataOutput PIN 15
    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
    adcBits VAR Byte
    v VAR Byte
    r VAR Byte
    v2 VAR Byte
    v3 VAR Byte
    '
    [ EEPROM Data ]
    DATA "Hello, this is the lcd demo" ' Message To Send To LCD
    '
    [ 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
    '
    [ Program Code ]
    Main:
    DO
    GOSUB ADC_Data
    GOSUB Calc_Volts
    GOSUB Display
    GOSUB Init_Lcd
    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
    'DO
    GOSUB Send_Text ' Send Character To LCD Display
    NEXT
    LOOP
    END

    '
    [ 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
    ADC_Data:
    HIGH CS
    LOW CS
    LOW CLK
    PULSOUT CLK, 210
    SHIFTIN DataOutput,CLK,MSBPOST,[adcBits\8]
    RETURN
    Calc_Volts:
    v = 5 * adcBits / 255
    r = 5 * adcBits // 255
    v2 = 100 * R / 255
    RETURN
    Display:
    DEBUG HOME
    DEBUG "8-bit binary value: ", BIN8 adcBits
    DEBUG CR, CR, "Decimal value: ", DEC3 adcBits
    DEBUG CR, CR, "DVM Reading: "
    DEBUG DEC1 v, ".", DEC2 v2, " Volts"
    RETURN
  • blackniteblacknite Posts: 4
    edited 2011-06-09 20:44
    the code should eventually display the voltage read from the a/d converter and display it on the lcd as fast as it can
  • RDL2004RDL2004 Posts: 2,554
    edited 2011-06-10 10:07
    You have to put your V2 variable in the char variable then send to the LCD

    Check this post where Chris has a couple of demo programs attached:

    http://forums.parallax.com/showthread.php?109408-Writing-variables-to-parallel-LCD.
  • vaclav_salvaclav_sal Posts: 451
    edited 2011-06-11 10:00
    You probably figured it out by now, but here as some pointers.
    The LCD RAM address is initialized in your Init_LCD to the base address. You need to read the LCD spec to find that out. But I find it easier to work with offset from the base address. See bellow.

    Your Init_LCD is set to auto increment so each time you do Send_text (char) it bumps this RAM address internally in LCD controller .

    When you switch to second line in Next_Line you change the LCD RAM by 128+64.
    That is relative to current RAM which you still do not know – again need the spec.

    To output your V2 variable you could reinitialize the LCD and just do Send_Text with V2 = char.
    That will put it in first displayable location on the LCD.

    Than you can add offsets ( line plus the “invisible RAM” in LCD ) and put the value wherever.
    I would recommend to you to take a look at HD4470 Hitachi LCD document. It will explain the mechanics of LCD controller better that I can.

    Have fun moving blinking characters around the LCD.
  • blackniteblacknite Posts: 4
    edited 2011-06-12 01:46
    Thanks for all the help guys. I needed this for a robotics competition yesterday (june 11) but wasnt able to get the screen working in time. Although i now know more for next year. Really appreciate the help. I knew absolutely nothing about a/d converters and lcd displays monday or programming them. And i haven't touched a basic stamp in three years. So your help was valueable. Thank you.
Sign In or Register to comment.