Shop OBEX P1 Docs P2 Docs Learn Events
Sending string to VFD but cannot send $00 — Parallax Forums

Sending string to VFD but cannot send $00

chetw77cruiserchetw77cruiser Posts: 12
edited 2012-10-15 17:12 in Propeller 1
Hello, I am working on a trip computer for automotive use and I am using a serial VFD (vacuum florescent display) for the output. So far I have everything working for the most part.

I have run into a problem with sending a string to a serial VFD. I am using the full duplex serial object to send data but I can not send a character that is something other than 1 to 255, i.e., ZERO. Maybe I am missing something but I am stumped.

Here is a string I am trying to send:
 vfd.str(string($1f, $28, $67, $03,$00))

Or this:
vfd.str(string($1f,$24,$01,$00,$06,$00))

Apparently the string function does not like anything less than 1. If I cannot get this to work, I will need to find a new way of transmitting commands to the vfd. Any ideas?

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-10-14 17:10
    Hello, I am working on a trip computer for automotive use and I am using a serial VFD (vacuum florescent display) for the output. So far I have everything working for the most part.

    I have run into a problem with sending a string to a serial VFD. I am using the full duplex serial object to send data but I can not send a character that is something other than 1 to 255, i.e., ZERO. Maybe I am missing something but I am stumped.

    Here is a string I am trying to send:
     vfd.str(string($1f, $28, $67, $03,$00))
    

    Or this:
    vfd.str(string($1f,$24,$01,$00,$06,$00))
    

    Apparently the string function does not like anything less than 1. If I cannot get this to work, I will need to find a new way of transmitting commands to the vfd. Any ideas?

    Strings in most languages are a string of characters terminated by a null. That is, the null or 00 is a terminator and not a character of the string. You must send this character separately as a character using vfd.tx.
  • chetw77cruiserchetw77cruiser Posts: 12
    edited 2012-10-14 17:24
    I was trying to avoid sending each command separately. Oh well, sometimes you have to learn the hard way.
  • Prophead100Prophead100 Posts: 192
    edited 2012-10-14 17:58
    I was trying to avoid sending each command separately. Oh well, sometimes you have to learn the hard way.

    Except for the power, the VFDs are nice for retro projects and dimming displays. You don't mention which VFD you use but I have always used the individual ascii for commands. When I want to simplify the code, I write short methods to avoid cluttering up the main code. You can even drop it into an objects as a library. It also gives you opportunities to modify the functions. For example, to provide a variety of screen clearing options I use this method with a Noritake GU144X16D-7053B :

    Pub Clear_Screen(Style)

    case Style

    3,4:'Quick Clear
    serial.tx($1B)
    serial.tx($40)
    2:'Quick Scroll Clear
    serial.tx($1F)
    serial.tx($28)
    serial.tx($61)
    serial.tx($10)
    serial.tx($08) 'wl width of byte scrolled, odd caused bounce up and down
    serial.tx($00) 'wh
    serial.tx($2F) 'cl number of times a width is moved
    serial.tx($00) 'ch
    serial.tx($02) 's speed at which byte is moved

    1:'Slow Scroll Clear
    serial.tx($1F)
    serial.tx($28)
    serial.tx($61)
    serial.tx($10)
    serial.tx($08) 'wl width of byte scrolled, odd caused bounce up and down
    serial.tx($00) 'wh
    serial.tx($2F) 'cl number of times a width is moved
    serial.tx($00) 'ch
    serial.tx($04) 's speed at which byte is moved

    0:'Bouncing Clear
    serial.tx($1F)
    serial.tx($28)
    serial.tx($61)
    serial.tx($10)
    serial.tx($08) 'wl width of byte scrolled, odd caused bounce up and down
    serial.tx($00) 'wh
    serial.tx($20) 'cl number of times a width is moved
    serial.tx($00) 'ch
    serial.tx($0A) 's speed at which byte is moved
    waitcnt(cnt+clkfreq)

    waitcnt(cnt+clkfreq*3)



    return
  • ChrisGaddChrisGadd Posts: 310
    edited 2012-10-15 08:25
    Another common workaround is to use some other value, such as $FF, in place of 0 in strings, and have the code recognize the substitution and send 0. This assumes of course that you never want the send the substituted value.
    CON
    _clkmode = xtal1 + pll16x
    _xinfreq = 5_000_000
    tx_pin   = 30
    Baud     = 19_200
    
    PUB Main
    
      dira[tx_pin]~~
      outa[tx_pin]~~
    
      repeat
        str(string($FF,"A","B","C"))		' Send 0 (cls), "A", "B", "C" to serial terminal at 19,200bps
        waitcnt (cnt + 8_000_000)
    
    PUB str(stringptr)				' Replace the str method in full-duplex serial with this one
    
      repeat strsize(stringptr)
        if byte[stringptr] == $FF		' $FF is the substitute for 0
          tx(0)					
          stringptr++
        else
          tx(byte[stringptr++])
    
    PUB tx(tx_byte) | t
    
      tx_byte := (tx_byte | $100) << 1
      t := cnt
    
      repeat 10
        outa[tx_pin] := tx_byte & 1
        waitcnt (t += clkfreq / baud)
        tx_byte := tx_byte >> 1
      outa[tx_pin]~~
    
  • Prophead100Prophead100 Posts: 192
    edited 2012-10-15 11:50
    I like Chris's approach. Perhaps, you could place your hex commands in labeled lists in the DAT section where each line is a set of command characters terminated by a $FF (instead of '0') that can be send with the alternative string method. That way you don't have to keep repeating the strings in your main code.
  • JonnyMacJonnyMac Posts: 9,108
    edited 2012-10-15 17:12
    I've done something like this in the past so I don't have to worry about substitutions:
    dat
    
    Cmd1            byte    $05, $1f, $28, $67, $03, $00
    
    
    pub send_cmd(pntr) | len
    
      len := byte[pntr++]
    
      repeat len
        tx(byte[pntr++])
    


    It costs one extra byte per string, but with them being stored in a DAT section (versus inline), this may actually save a bit of space.
Sign In or Register to comment.