Shop OBEX P1 Docs P2 Docs Learn Events
Translating from BS2 to BS1 coding styles — Parallax Forums

Translating from BS2 to BS1 coding styles

Buck RogersBuck Rogers Posts: 2,187
edited 2015-03-31 14:52 in BASIC Stamp
Hello!
I'm in the process of sorting out how to translate one of my BS2 programs who when running displays its thoughts on a Parallax display.
This is the fragment that needs solving:
  X VAR Word
  Z VAR Word
  Z1 VAR Word
  SEROUT TX,LcdBaud,[LcdBLon]
  SEROUT TX,LcdBaud,[LcdCls]
  Z = 16
  FOR X=32 TO 127
  SEROUT TX,LcdBaud, [X]                'PIN 12
  PAUSE 750
  SEROUT PL1,LcdBaud,[X]                'PIN 1
  PAUSE 375
  PULSIN PL2, Z, Z1                     'PIN 2
  PULSIN PL5, Z, Z1                     'PIN 5
  SEROUT TX, LcdBaud, [Z1]              'PIN 12
  PULSOUT PL3, Z1                       'PIN 3
  PULSOUT PL4, Z1                       'PIN 4
  PULSOUT PL0, 7                        'PIN 0
  SEROUT TX,LcdBaud,[65]
  PAUSE 100
  SEROUT TX,LcdBaud,[66]
  PAUSE 100
  SEROUT TX,LcdBaud,[67]
  PAUSE 175
  SEROUT TX,LcdBaud,[32]
'  DEBUG X
 NEXT
  SEROUT TX,LcdBaud,[LcdBLoff]
  SEROUT TX,LcdBaud,[LcdCls]
  PAUSE 5
'   GOTO Main
  END

The whole idea of initializing the variables that the program needs is what is confusing the stamp's tokenizing process.


And this is the full program that came from:
' =========================================================================
'
'   File...... Serial_LCD_Template.BS2
'   Purpose... Template for Parallax Serial LCD
'   Author.... (c) Parallax, Inc. -- All Rights Reserved
'   E-mail.... support@parallax.com
'   Started...
'   Updated... 11 FEB 2005
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

TX              PIN     15               ' serial output to LCD
PL0             PIN     0
PL1             PIN     1                ' To the PAL
PL2             PIN     2                ' From the PAL
PL3             PIN     3
PL4             PIN     4
PL5             PIN     5
' -----[ Constants ]-------------------------------------------------------

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T9600       CON     84
    T19K2       CON     32
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T9600       CON     240
    T19K2       CON     110
#ENDSELECT

LcdBaud         CON     T2400

LcdBkSpc        CON     $08             ' move cursor left
LcdRt           CON     $09             ' move cursor right
LcdLF           CON     $0A             ' move cursor down 1 line
LcdCls          CON     $0C             ' clear LCD (use PAUSE 5 after)
LcdCR           CON     $0D             ' move pos 0 of next line
LcdBLon         CON     $11             ' backlight on
LcdBLoff        CON     $12             ' backlight off
LcdOff          CON     $15             ' LCD off
LcdOn1          CON     $16             ' LCD on; cursor off, blink off
LcdOn2          CON     $17             ' LCD on; cursor off, blink on
LcdOn3          CON     $18             ' LCD on; cursor on, blink off
LcdOn4          CON     $19             ' LCD on; cursor on, blink on
LcdLine1        CON     $80             ' move to line 1, column 0
LcdLine2        CON     $94             ' move to line 2, column 0

LcdCC0          CON     $F8             ' define custom char 0
LcdCC1          CON     $F9             ' define custom char 1
LcdCC2          CON     $FA             ' define custom char 2
LcdCC3          CON     $FB             ' define custom char 3
LcdCC4          CON     $FC             ' define custom char 4
LcdCC5          CON     $FD             ' define custom char 5
LcdCC6          CON     $FE             ' define custom char 6
LcdCC7          CON     $FF             ' define custom char 7


' -----[ Variables ]-------------------------------------------------------


' -----[ EEPROM Data ]-----------------------------------------------------


' -----[ Initialization ]--------------------------------------------------

Reset:
  HIGH TX                               ' setup serial output pin
  PAUSE 100                             ' allow LCD to initialize
  HIGH PL1                              'PIN 1
 ' LOW  PL1
  LOW  PL2                              'PIN 2
  LOW  PL3                              'PIN 3
  LOW  PL4                              'PIN 4
  LOW  PL5                              'PIN 5
' -----[ Program Code ]----------------------------------------------------

Main:
    ' your code here
  X VAR Word
  Z VAR Word
  Z1 VAR Word
  SEROUT TX,LcdBaud,[LcdBLon]
  SEROUT TX,LcdBaud,[LcdCls]
  Z = 16
  FOR X=32 TO 127
  SEROUT TX,LcdBaud, [X]                'PIN 12
  PAUSE 750
  SEROUT PL1,LcdBaud,[X]                'PIN 1
  PAUSE 375
  PULSIN PL2, Z, Z1                     'PIN 2
  PULSIN PL5, Z, Z1                     'PIN 5
  SEROUT TX, LcdBaud, [Z1]              'PIN 12
  PULSOUT PL3, Z1                       'PIN 3
  PULSOUT PL4, Z1                       'PIN 4
  PULSOUT PL0, 7                        'PIN 0
  SEROUT TX,LcdBaud,[65]
  PAUSE 100
  SEROUT TX,LcdBaud,[66]
  PAUSE 100
  SEROUT TX,LcdBaud,[67]
  PAUSE 175
  SEROUT TX,LcdBaud,[32]
'  DEBUG X
 NEXT
  SEROUT TX,LcdBaud,[LcdBLoff]
  SEROUT TX,LcdBaud,[LcdCls]
  PAUSE 5
'   GOTO Main
  END

It is the framework for the whole Idea I started up with back a good many years after buying from RS an LCD display that Parallax had designed the daughterboard for it. When running the program passes data out to a connected programmable logic chip, and then displays its response. It works well enough on the BS2 device I have here, but I wanted to translate it to the recently arrived BS1 device.

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-03-31 01:57
    The BS1 uses "SYMBOL" to declare both variables and constants. The constants don't appear to use any memory. I think the compiler just inserts the number defined into any locations where the constant name appears.
    ' {$STAMP BS1}
    ' {$PBASIC 1.0}
    
    SYMBOL LcdBaud = T2400 ' value 0
    SYMBOL TX = 15
    SYMBOL X = W1
    SYMBOL Z = W2
    SYMBOL Z1 = W3
    SYMBOL LcdBLon = $11             ' backlight on
    SYMBOL LcdCls = $0C             ' clear LCD (use PAUSE 5 after)
    SYMBOL LcdBLoff = $12             ' backlight off
    SYMBOL PL0 = 0
    SYMBOL PL1 = 1
    SYMBOL PL2 = 2
    SYMBOL PL3 = 3
    SYMBOL PL4 = 4
    SYMBOL PL5 = 5
    ' -----[ Initialization ]--------------------------------------------------
    
    Reset:
      HIGH TX                               ' setup serial output pin
      PAUSE 100                             ' allow LCD to initialize
      HIGH PL1                              'PIN 1
     ' LOW  PL1
      LOW  PL2                              'PIN 2
      LOW  PL3                              'PIN 3
      LOW  PL4                              'PIN 4
      LOW  PL5                              'PIN 5
    
    ' -----[ Program Code ]----------------------------------------------------
    
    Main:
        ' your code here
    
      SEROUT TX,LcdBaud,(LcdBLon)
      SEROUT TX,LcdBaud,(LcdCls)
      Z = 16
      FOR X=32 TO 127
      SEROUT TX,LcdBaud, (X)                'PIN 12
      PAUSE 750
      SEROUT PL1,LcdBaud,(X)                'PIN 1
      PAUSE 375
      PULSIN PL2, Z, Z1                     'PIN 2
      PULSIN PL5, Z, Z1                     'PIN 5
      SEROUT TX, LcdBaud, (Z1)              'PIN 12
      PULSOUT PL3, Z1                       'PIN 3
      PULSOUT PL4, Z1                       'PIN 4
      PULSOUT PL0, 7                        'PIN 0
      SEROUT TX,LcdBaud,(65)
      PAUSE 100
      SEROUT TX,LcdBaud,(66)
      PAUSE 100
      SEROUT TX,LcdBaud,(67)
      PAUSE 175
      SEROUT TX,LcdBaud,(32)
    '  DEBUG X
     NEXT
      SEROUT TX,LcdBaud,(LcdBLoff)
      SEROUT TX,LcdBaud,(LcdCls)
      PAUSE 5
    '   GOTO Main
      END
    

    I think the serial constant is correct but the values used in the "PAUSE" commands will need to be changed to compensate for the slower clock on the BS1.
  • JonnyMacJonnyMac Posts: 9,157
    edited 2015-03-31 13:02
    Remember that PULSIN units on the BS1 are 10uS (versus 2 on the BS2). The max baud rate for the BS1 is 2400. Looks like Duane has your sorted.
  • Buck RogersBuck Rogers Posts: 2,187
    edited 2015-03-31 14:52
    JonnyMac wrote: »
    Remember that PULSIN units on the BS1 are 10uS (versus 2 on the BS2). The max baud rate for the BS1 is 2400. Looks like Duane has your sorted.

    And I'm inclined to agree. I remember your efforts regarding translating a BS2 program that would talk to a TI Calculator, to a BS1 version.

    Naturally I tried out both versions. I found that the BS1 version ran faster as applied to the BS2 version.

    I changed the flag from "unsolved" to "solved" simply because Duane's translation looks perfect both in here and on the IDE tools.
Sign In or Register to comment.