Shop OBEX P1 Docs P2 Docs Learn Events
Ds1620 demo for Propeller — Parallax Forums

Ds1620 demo for Propeller

Jeff WeberJeff Weber Posts: 2
edited 2013-03-25 07:41 in Propeller 1
I know this is a dumb question and I have searched for a solution for it but have come up empty. I am trying to run the ds1620 demo by Jon Williams and when I go to compile it, I get an error message that says "ERROR: expected subroutine name" It is highlighting start in the line if lcd.start(3, 19200, 2). It looks like I have all the needed objects. Thanks in advance for any help.

Jeff

Comments

  • JonnyMacJonnyMac Posts: 9,191
    edited 2013-03-24 18:19
    If you archive the code I'll look at it and fix it. I would suggest looking inside the LCD object. There was a time when I didn't use .start() and .stop() as to not cause confusion with I2C objects -- I'm past that now. The LCD. cod may be older and have a method called .init() instead of start (if it was written by me).

    JonnyMac == The Artist Formerly Known as Jon Williams
  • Jeff WeberJeff Weber Posts: 2
    edited 2013-03-24 20:44
    This is the main code:

    DS1620 Demo
    '' -- Jon Williams, Parallax
    '' -- 28 MAR 2006
    ''
    '' Uses 2x16 Serial LCD (Parallax) to display temperature

    CON
    _clkmode = xtal1 + pll16x ' use crystal x 16
    _xinfreq = 5_000_000

    OBJ
    lcd : "serial_lcd"
    temp : "ds1620"
    delay : "timing"
    num : "simple_numbers"

    PUB main | tc, tf
    if lcd.start(3, 19200, 2)
    lcd.putc(lcd#LcdOn1) ' no cursor
    lcd.custom(0, @DegSym) ' create degrees symbol
    lcd.cls ' setup screen
    lcd.str(string("TEMP"))
    lcd.backlight(1) ' backlight on
    temp.start(0, 1, 2) ' initialize DS1620
    repeat
    delay.pause1ms(1000) ' wait one second

    lcd.putc(lcd#LcdLine0 + 9)
    tc := temp.gettempc
    lcd.str(num.decf(tc / 10, 3))
    lcd.putc(".")
    lcd.str(num.dec(tc // 10))
    lcd.putc(0)
    lcd.putc("C")
    lcd.putc(lcd#LcdLine1 + 9)
    tf := temp.gettempf
    lcd.str(num.decf(tf / 10, 3))
    lcd.putc(".")
    lcd.str(num.dec(tf // 10))
    lcd.putc(0)
    lcd.putc("F")

    DAT
    DegSym byte $0E, $0A, $0E, $00, $00, $00, $00, $00


    This is the object LCD SERIAL.SPIN:''****************************************
    ''* Parallax Serial LCD Driver v1.2 *
    ''* Authors: Jon Williams, Jeff Martin *
    ''* Copyright (c) 2006 Parallax, Inc. *
    ''* See end of file for terms of use. *
    ''****************************************
    ''
    '' Driver for Parallax Serial LCDs (#27976, #27977, #27979)
    ''
    '' v1.2 - March 26, 2008 - Updated by Jeff Martin to conform to Propeller object initialization standards.
    '' v1.1 - April 29, 2006 - Updated by Jon Williams for consistency.
    ''
    ''
    '' Serial LCD Switch Settings for Baud rate
    ''
    '' ┌─────────┐ ┌─────────┐ ┌─────────┐
    '' │ O N │ │ O N │ │ O N │
    '' │ ┌──┬──┐ │ │ ┌──┬──┐ │ │ ┌──┬──┐ │
    '' │ │[]│ │ │ │ │ │[]│ │ │ │[]│[]│ │
    '' │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
    '' │ │ │[]│ │ │ │[]│ │ │ │ │ │ │ │
    '' │ └──┴──┘ │ │ └──┴──┘ │ │ └──┴──┘ │
    '' │ 1 2 │ │ 1 2 │ │ 1 2 │
    '' └─────────┘ └─────────┘ └─────────┘
    '' 2400 9600 19200

    CON
    LCD_BKSPC = $08 ' move cursor left
    LCD_RT = $09 ' move cursor right
    LCD_LF = $0A ' move cursor down 1 line
    LCD_CLS = $0C ' clear LCD (follow with 5 ms delay)
    LCD_CR = $0D ' move pos 0 of next line
    LCD_BL_ON = $11 ' backlight on
    LCD_BL_OFF = $12 ' backlight off
    LCD_OFF = $15 ' LCD off
    LCD_ON1 = $16 ' LCD on; cursor off, blink off
    LCD_ON2 = $17 ' LCD on; cursor off, blink on
    LCD_ON3 = $18 ' LCD on; cursor on, blink off
    LCD_ON4 = $19 ' LCD on; cursor on, blink on
    LCD_LINE0 = $80 ' move to line 1, column 0
    LCD_LINE1 = $94 ' move to line 2, column 0
    LCD_LINE2 = $A8 ' move to line 3, column 0
    LCD_LINE3 = $BC ' move to line 4, column 0
    #$F8, LCD_CC0, LCD_CC1, LCD_CC2, LCD_CC3
    #$FC, LCD_CC4, LCD_CC5, LCD_CC6, LCD_CC7

    VAR
    long lcdLines, started

    OBJ
    serial : "simple_serial" ' bit-bang serial driver

    PUB init(pin, baud, lines): okay
    '' Qualifies pin, baud, and lines input
    '' -- makes tx pin an output and sets up other values if valid
    started~ ' clear started flag
    if lookdown(pin : 0..27) ' qualify tx pin
    if lookdown(baud : 2400, 9600, 19200) ' qualify baud rate setting
    if lookdown(lines : 2, 4) ' qualify lcd size (lines)
    if serial.init(-1, pin, baud) ' tx pin only, true mode
    lcdLines := lines ' save lines size
    started~~ ' mark started flag true
    return started

    PUB finalize
    '' Finalizes serial object, disable LCD object
    if started
    serial.finalize
    started~ ' set to false

    PUB putc(txByte)
    '' Transmit a byte
    serial.tx(txByte)

    PUB str(strAddr)
    '' Transmit z-string at strAddr
    serial.str(strAddr)

    PUB cls
    '' Clears LCD and moves cursor to home (0, 0) position
    if started
    putc(LCD_CLS)
    waitcnt(clkfreq / 200 + cnt) ' 5 ms delay

    PUB home
    '' Moves cursor to 0, 0
    if started
    putc(LCD_LINE0)

    PUB gotoxy(col, line) | pos
    '' Moves cursor to col/line
    if started
    if lcdLines == 2 ' check lcd size
    if lookdown(line : 0..1) ' qualify line input
    if lookdown(col : 0..15) ' qualify column input
    putc(LinePos[line] + col) ' move to target position
    else
    if lookdown(line : 0..3)
    if lookdown(col : 0..19)
    putc(LinePos[line] + col)

    PUB clrln(line)
    '' Clears line
    if started
    if lcdLines == 2 ' check lcd size
    if lookdown(line : 0..1) ' qualify line input
    putc(LinePos[line]) ' move to that line
    repeat 16
    putc(32) ' clear line with spaces
    putc(LinePos[line]) ' return to start of line
    else
    if lookdown(line : 0..3)
    putc(LinePos[line])
    repeat 20
    putc(32)
    putc(LinePos[line])

    PUB cursor(type)
    '' Selects cursor type
    '' 0 : cursor off, blink off
    '' 1 : cursor off, blink on
    '' 2 : cursor on, blink off
    '' 3 : cursor on, blink on
    if started
    case type
    0..3 : putc(DispMode[type]) ' get mode from table
    other : putc(LCD_ON3) ' use serial lcd power-up default

    PUB displayOff
    '' Blank the display (without clearing)
    if started
    putc(LCD_OFF)

    PUB displayOn
    '' Restore the display (with cursor hidden)
    if started
    cursor(0)


    PUB custom(char, chrDataAddr)
    '' Installs custom character map
    '' -- chrDataAddr is address of 8-byte character definition array
    if started
    if lookdown(char : 0..7) ' make sure char in range
    putc(LCD_CC0 + char) ' write character code
    repeat 8
    putc(byte[chrDataAddr++]) ' write character data

    PUB backLight(status)
    '' Enable (true) or disable (false) LCD backlight
    '' -- works only with backlight-enabled displays
    if started
    status := status <> 0 ' promote non-zero to -1
    if status
    putc(LCD_BL_ON)
    else
    putc(LCD_BL_OFF)
    else
    status := false
    return status

    DAT
    LinePos byte LCD_LINE0, LCD_LINE1, LCD_LINE2, LCD_LINE3
    DispMode byte LCD_ON1, LCD_ON2, LCD_ON3, LCD_ON4

    {{
    ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    │ TERMS OF USE: MIT License │
    ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
    │Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │
    │files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │
    │modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│
    │is furnished to do so, subject to the following conditions: │
    │ │
    │The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│
    │ │
    │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │
    │WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │
    │COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
    │ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
    └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
    }}

    This is the object Simple_serial:

    ''* Simple Asynchronous Serial Driver v1.3 *
    ''* Authors: Chip Gracey, Phil Pilgrim, Jon Williams, Jeff Martin *
    ''* Copyright (c) 2006 Parallax, Inc. *
    ''* See end of file for terms of use. *
    ''*******************************************************************
    ''
    '' Performs asynchronous serial input/output at low baud rates (~19.2K or lower) using high-level code
    '' in a blocking fashion (ie: single-cog (serial-process) rather than multi-cog (parallel-process)).
    ''
    '' To perform asynchronous serial communication as a parallel process, use the FullDuplexSerial object instead.
    ''
    ''
    '' v1.3 - May 7, 2009 - Updated by Jeff Martin to fix rx method bug, noted by Mike Green and others, where uninitialized
    '' variable would mangle received byte.
    '' v1.2 - March 26, 2008 - Updated by Jeff Martin to conform to Propeller object initialization standards and compress by 11 longs.
    '' v1.1 - April 29, 2006 - Updated by Jon Williams for consistency.
    ''
    ''
    '' The init method MUST be called before the first use of this object.
    '' Optionally call finalize after final use to release transmit pin.
    ''
    '' Tested to 19.2 kbaud with clkfreq of 80 MHz (5 MHz crystal, 16x PLL)

    VAR
    long sin, sout, inverted, bitTime, rxOkay, txOkay

    PUB init(rxPin, txPin, baud): Okay
    {{Call this method before first use of object to initialize pins and baud rate.
    • For true mode (start bit = 0), use positive baud value. Ex: serial.init(0, 1, 9600)
    For inverted mode (start bit = 1), use negative baud value. Ex: serial.init(0, 1, -9600)
    • Specify -1 for "unused" rxPin or txPin if only one-way communication desired.
    • Specify same value for rxPin and txPin for bi-directional communication on that pin and connect a pull-up/pull-down resistor
    to that pin (depending on true/inverted mode) since pin will set it to hi-z (input) at the end of transmission to avoid
    electrical conflicts. See "Same-Pin (Bi-Directional)" examples, below.
    EXAMPLES:

    Standard Two-Pin Bi-Directional True/Inverted Modes Standard One-Pin Uni-Directional True/Inverted Mode
    Ex: serial.init(0, 1, ±9600) Ex: serial.init(0, -1, ±9600) -or- serial.init(-1, 0, ±9600)
    ┌────────────┐ ┌──────────┐ ┌────────────┐ ┌──────────┐
    │Propeller P0├─────────────┤I/O Device│ │Propeller P0├───────────────┤I/O Device│
    │ P1├─────────────┤ │ └────────────┘ └──────────┘
    └────────────┘ └──────────┘

    Same-Pin (Bi-Directional) True Mode Same-Pin (Bi-Directional) Inverted Mode
    Ex: serial.init(0, 0, 9600) Ex: serial.init(0, 0, -9600)
     ┌────────────┐ ┌──────────┐
    │ │Propeller P0├─────┳─────┤I/O Device│
     4.7 kΩ └────────────┘ │ └──────────┘
    ┌────────────┐ │ ┌──────────┐  4.7 kΩ
    │Propeller P0├─────┻─────┤I/O Device│ │
    └────────────┘ └──────────┘ 
    }}
    finalize ' clean-up if restart

    rxOkay := rxPin > -1 ' receiving?
    txOkay := txPin > -1 ' transmitting?
    sin := rxPin & $1F ' set rx pin
    sout := txPin & $1F ' set tx pin
    inverted := baud < 0 ' set inverted flag
    bitTime := clkfreq / ||baud ' calculate serial bit time

    return rxOkay | TxOkay

    PUB finalize
    {{Call this method after final use of object to release transmit pin.}}

    if txOkay ' if tx enabled
    dira[sout]~ ' float tx pin
    rxOkay := txOkay := false

    PUB rx: rxByte | t
    {{ Receive a byte; blocks caller until byte received. }}
    if rxOkay
    dira[sin]~ ' make rx pin an input
    waitpeq(inverted & |< sin, |< sin, 0) ' wait for start bit
    t := cnt + bitTime >> 1 ' sync + 1/2 bit
    repeat 8
    waitcnt(t += bitTime) ' wait for middle of bit
    rxByte := ina[sin] << 7 | rxByte >> 1 ' sample bit
    waitcnt(t + bitTime) ' allow for stop bit
    rxByte := (rxByte ^ inverted) & $FF ' adjust for mode and strip off high bits

    PUB tx(txByte) | t
    {{ Transmit a byte; blocks caller until byte transmitted. }}
    if txOkay
    outa[sout] := !inverted ' set idle state
    dira[sout]~~ ' make tx pin an output
    txByte := ((txByte | $100) << 2) ^ inverted ' add stop bit, set mode
    t := cnt ' sync
    repeat 10 ' start + eight data bits + stop
    waitcnt(t += bitTime) ' wait bit time
    outa[sout] := (txByte >>= 1) & 1 ' output bit (true mode)

    if sout == sin
    dira[sout]~ ' release to pull-up/pull-down

    PUB str(strAddr)
    {{ Transmit z-string at strAddr; blocks caller until string transmitted. }}
    if txOkay
    repeat strsize(strAddr) ' for each character in string
    tx(byte[strAddr++]) ' write the character
    {{

    ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
    │ TERMS OF USE: MIT License │
    ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
    │Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │
    │files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │
    │modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│
    │is furnished to do so, subject to the following conditions: │
    │ │
    │The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│
    │ │
    │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │
    │WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │
    │COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │
    │ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
    └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
    }}

    Thanks for any help
  • JonnyMacJonnyMac Posts: 9,191
    edited 2013-03-25 07:41
    In future, it would be better to attach listings as a file instead of copy-and-paste -- especially without formatting (you can use [ code ] and [ /code ] without the spaces to fix that).

    I've attached an update I use to that object, which renames init() to start(), and finalize() to stop() per standard conventions. It also adds a right-justified decimal method which I tend to use a lot in displays.

    Note that I'm using a single object, jm_serial_lcd, which does not rely on simple_serial.
Sign In or Register to comment.