Shop OBEX P1 Docs P2 Docs Learn Events
is it possible to change SX/B 8 bit Commands into 16 bit? — Parallax Forums

is it possible to change SX/B 8 bit Commands into 16 bit?

Capt. QuirkCapt. Quirk Posts: 872
edited 2007-02-12 13:31 in General Discussion
I was trying to use Ken Gracy's .bs2 mill example into SX/B code and ran into a problem with "LOOKDOWN" requiring only 8 bit variables and so I was thinking maybe by combining RB & RC ports to "RBC".

Would that allow 16 bit variables then? and would that work across the board for other commands that require a 0 - 255, 8 bit variable.

Thanks

Comments

  • Clock LoopClock Loop Posts: 2,069
    edited 2007-02-11 00:14
    I know you can specify the higher byte or lower byte of a word variable by doing something like

    If you declared the variable

    wordvariable WORD

    and then did this

    RB = word_LSB

    this would output the LOWER BYTE of the word to the port RB

    and

    RC = word_MSB

    this would output the UPPER BYTE of the word to the port RC

    this feature is not documented well in the help sections.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Meh. Nothing here, move along.
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-02-11 01:02
    I need to use a whole word variable though, thanks.

    "Lookdown" requires a Byte variable·or a number value between 0 - 255 and so do a lot of other commands like RCTIME, PULSOUT, etc. If you need a variable like 10,000 and declare it as a word, SX/B returns an error declaring a "expected Byte varible".

    With some of the Commands you can use multipliers to prevent this, but others you can't. Thats why I thought RBC may fix that.

    Post Edited (Capt. Quirk) : 2/11/2007 1:47:14 AM GMT
  • Clock LoopClock Loop Posts: 2,069
    edited 2007-02-11 04:18
    There may be other ways to do what you want without passing a word variable to a command that can only use a byte.

    Got a link to your code?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Meh. Nothing here, move along.
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-02-11 06:40
    Here you go

    ' Write right-justified value at cursor position
    ' -- move cursor to left-most position of field
    ' -- put field width if 'width' (1 to 5)
    ' -- put value in 'value'

    '
    'EXAMPLE FROM HELP SECTION
    ' idx = 3
    'LOOKUP idx, $00, $01, $02, $04, $08, $10, $20, $40, $80, LEDs
    '

    LCD_Put_RJ_Value:
    · LOOKDOWN value, >=[noparse][[/noparse]10000, 1000, 100, 10, 0], pad ········ 'Gives error #11 "Byte Variable Expected"
    · pad = pad - (5 - width)················································ 'All 7 errors are within this routine
    · IF (pad > 0) THEN······················································· 'I was planing on checking this version with
    ··· char = " "····························································'SX-Key Debug and compare results with the actual
    ··· FOR idx = 1 TO pad·················································· 'BS2 program
    ····· GOSUB LCD_Write
    ··· NEXT
    · ENDIF
    · FOR idx = (width - pad - 1) TO 0
    ··· char = value DIG idx + "0"
    ··· GOSUB LCD_Write
    · NEXT
    · RETURN



    ·The actual program

    ' =========================================================================
    '
    '·· File...... Mill_Speedo.SX/B
    '·· Purpose... Wabeco CC-1210 Milling RPM Measurement
    '·· Author.... K. Gracy?
    '·· E-mail....
    '·· Started...04 JUN 2004
    '·· Modified by..Bill Mazzacane
    '·Updated... 10 FEB 2007
    '
    ' =========================================================================
    ' =========================================================================


    '
    ' Program Description
    '
    'In the process of changing it over to SX/B

    '
    ' Device Settings
    '

    DEVICE········· SX28, OSCHS2, TURBO, STACKX, OPTIONX
    FREQ··········· 20_000_000
    ID············· "SXB 1.50"


    '
    ' IO Pins
    '

    E·············· PIN···· RB.1························ ' LCD Enable
    RW············· PIN···· RB.2······················ ' Read/Write\
    RS············· PIN···· RB.3······················· ' Reg Select (1 = char)
    LcdDirs········ VAR···· RB···'DIRB···············' dirs for I/O redirection
    LcdBus········· VAR···· RB···'OUTB
    SpeedIn········ PIN···· RC.0····················· ' Melexis 90217 output

    '
    ' Constants
    '
    '#DEFINE Lcd = 1·································· ' set to 0 for VFD
    '#DEFINE BarGraph = 1··························· ' set to 0 for no graph


    LcdCls········· CON···· $01······················ ' clear the LCD
    LcdHome········ CON···· $02···················· ' move cursor home
    LcdCrsrL······· CON···· $10······················ ' move cursor left
    LcdCrsrR······· CON···· $14······················ ' move cursor right
    LcdDispL······· CON···· $18······················ ' shift chars left
    LcdDispR······· CON···· $1C······················ ' shift chars right

    LcdDDRam······· CON···· $80···················· ' Display Data RAM control
    LcdCGRam······· CON···· $40···················· ' Character Generator RAM
    LcdLine1······· CON···· $80······················ ' DDRAM address of line 1
    LcdLine2······· CON···· $C0······················ ' DDRAM address of line 2
    A····CON··10_000
    B····CON··1_000
    D····CON··100
    R····CON··10
    F····CON··0

    '
    ' Variables
    '
    char··········· VAR···· Byte···················· ' for LCD
    addr··········· VAR···· Word··················· ' ee pointer (for DATA)
    pulses········· VAR···· Word··················· ' input pulses from motor
    rpm············ VAR···· Word··················· ' motor RPM ###### Needs to be a byte ############
    percent········ VAR···· Byte··················· ' % of max speed (7500)
    fldPos········· VAR···· Byte····················· ' field position
    value·········· VAR···· WORD··················· ' value to print #########Needs to be a byte #######
    width·········· VAR···· Byte····················· ' width of print field
    pad············ VAR···· Byte······················' spaces for rj printing
    idx············ VAR···· Byte······················ ' loop counter
    cols··········· VAR···· Byte······················ ' total graph colums
    blox··········· VAR···· Byte····················· ' whole blocks for graph


    '
    · INTERRUPT
    '

    ISR_Start:
    · ' ISR code here

    ISR_Exit:
    · RETURNINT ' {cycles}································


    ' =========================================================================
    · PROGRAM Start
    ' =========================================================================
    '
    [noparse][[/noparse] EEPROM Data ]

    Banner1:········
    ·DATA·· "·· KEN GRACEY·· ", 0
    Banner2:········
    ·DATA··· "MILL SPEEDOMETER", 0

    DefaultL1:······
    ·DATA·· "·· 0 RPM···· 0 %", 0

    '#IF Lcd #THEN
    · 'CC0·········· DATA·· $10, $10, $10, $10, $10, $10, $10, $00
    · 'CC1·········· DATA·· $18, $18, $18, $18, $18, $18, $18, $00
    · 'CC2·········· DATA·· $1C, $1C, $1C, $1C, $1C, $1C, $1C, $00
    · 'CC3·········· DATA·· $1E, $1E, $1E, $1E, $1E, $1E, $1E, $00
    · 'CC4·········· DATA·· $1F, $1F, $1F, $1F, $1F, $1F, $1F, $00
    '#ENDIF


    '
    ' Subroutine Declarations
    '
    Show_RPM····SUB
    Show_Percent···SUB
    LCD_Put_String···SUB
    LCD_Put_RJ_Value··SUB
    LCD_Command····SUB
    LCD_Write····SUB
    '
    ' Program Code
    '

    Start:
    · TRIS_B = %11111101····························· ' setup pins for LCD
    · LOW RW

    LCD_Init:
    · ·PAUSE 500·········································· ' let the LCD settle
    · ·LcdBus = %0011··································· ' 8-bit mode
    · ·PULSOUT E, 1·
    ·PAUSE 5
    · ·PULSOUT E, 1
    ·PAUSE 0
    · ·PULSOUT E, 1
    ·PAUSE 0
    · ·LcdBus = %0010································ ·' 4-bit mode
    ··PULSOUT E, 1
    · ·char = %00101000······························ ' multi-line mode
    · ·GOSUB LCD_Command
    · ·char = %00001100······························ ' disp on, no crsr, no blink
    · ·GOSUB LCD_Command
    · ·char = %00000110······························ ' inc crsr, no disp shift
    · ·GOSUB LCD_Command

    'NOT REQUIRED

    'DL_Characters:
    '#IF Lcd #THEN
    'char = LcdCGRam································· ' point to CG RAM
    'GOSUB LCD_Command··························· ' prepare to write CG data
    ' FOR idx = CC0 TO (CC4 + 7)·················· ' build 5 custom chars
    ' READ idx, char···································· ' get byte from EEPROM
    ' GOSUB LCD_Write································ ' put into LCD CG RAM
    'NEXT
    '#ENDIF

    Banner:
    · char = LcdCls
    · GOSUB LCD_Command
    ·· DO
    ··· READ Banner1 + addr, char
    ··· addr = addr + 1
    ··· IF char = 0 THEN EXIT
    ··· GOSUB LCD_Write
    · LOOP
    · GOSUB LCD_Put_String
    · char = LcdLine2
    · GOSUB LCD_Command
    ·· DO
    ··· READ Banner2 + addr, char
    ··· addr = addr + 1
    ··· IF char = 0 THEN EXIT
    ··· GOSUB LCD_Write
    · LOOP
    · GOSUB LCD_Put_String
    · PAUSE 3000
    · char = LcdCls
    · GOSUB LCD_Command



    Main:
    · addr = DefaultL1
    · GOSUB LCD_Put_String
    · COUNT SpeedIn, 1000, Pulses
    · RPM = Pulses * 60
    · GOSUB Show_RPM
    · 'percent = rpm / 75
    · GOSUB Show_Percent
    · GOTO Main



    '
    ' Subroutine Code
    '
    Show_RPM:
    · char = LcdLine1
    · GOSUB LCD_Command
    · width = 4
    · value = rpm
    · GOSUB LCD_Put_RJ_Value
    · RETURN


    Show_Percent:
    · char = LcdLine1 + 11
    · GOSUB LCD_Command
    · width = 3
    · value = percent
    · GOSUB LCD_Put_RJ_Value

    ' NOT REQUIRED
    ·
    '#IF BarGraph #THEN
    'char = LcdLine2······························· ' position cursor
    'GOSUB LCD_Command
    'cols = percent */ 205······················· ' x 0.8 (100% = 80 pixels)
    'blox = cols / 5································ ·' calculate whole blocks
    'IF (blox > 0) THEN
    'char = 4
    'FOR idx = 1 TO blox.
    ' GOSUB LCD_Write
    ' NEXT
    'ENDIF
    ' LOOKUP (cols // 5), [noparse][[/noparse]" ", 0, 1, 2, 3], char····· ' partial block
    'GOSUB LCD_Write
    'char = " "
    ' FOR idx = 0 TO (16 - blox)························· ' clear end of graph display
    ' GOSUB LCD_Write
    ' NEXT
    ' #ENDIF

    'RETURN


    ' Writes stored (in DATA statement) zero-terminated string to LCD
    ' -- position LCD cursor
    ' -- point to 0-terminated string (first location in 'addr')

    LCD_Put_String:
    · DO
    ··· READ addr, char
    ··· addr = addr + 1
    ··· IF char = 0 THEN EXIT
    ··· GOSUB LCD_Write
    · LOOP
    · RETURN


    ' Write right-justified value at cursor position
    ' -- move cursor to left-most position of field
    ' -- put field width if 'width' (1 to 5)
    ' -- put value in 'value'

    '
    'EXAMPLE FROM HELP SECTION
    ' idx = 3
    'LOOKUP idx, $00, $01, $02, $04, $08, $10, $20, $40, $80, LEDs
    '

    LCD_Put_RJ_Value:
    · LOOKDOWN value, >=[noparse][[/noparse]10000, 1000, 100, 10, 0], pad ···· 'Gives error #11 "Byte Variable Expected"
    · pad = pad - (5 - width)············································ 'All 7 errors are within this routine
    · IF (pad > 0) THEN··················································· 'I was planing on checking this version with
    ··· char = " "·················································· 'SX-Key Debug and compare results with the actual
    ··· FOR idx = 1 TO pad··············································· 'BS2 program
    ····· GOSUB LCD_Write
    ··· NEXT
    · ENDIF
    · FOR idx = (width - pad - 1) TO 0
    ··· char = value DIG idx + "0"
    ··· GOSUB LCD_Write
    · NEXT
    · RETURN


    ' Send command to LCD
    ' -- put command byte in 'char'

    LCD_Command:·············································· ·' write command to LCD
    · LOW RS

    ' Write character to current cursor position
    ' -- but byte to write in 'char'

    LCD_Write:
    · LcdBus = char················································· ' output high nibble
    · PULSOUT E, 3
    · SWAP char······················································' strobe the Enable line
    · LcdBus = char················································· ' output low nibble
    · PULSOUT E, 3
    · HIGH RS························································· ' return to character mode
    · RETURN


    ' =========================================================================
    ' User Data
    ' =========================================================================

    Pgm_ID:
    · DATA· "SX/B 1.50 Template", 0

    Thanks

    Bill


    Post Edited (Capt. Quirk) : 2/11/2007 6:50:20 AM GMT
  • BeanBean Posts: 8,129
    edited 2007-02-11 12:55
    Bill,
    · The way I did this for my HC4LED displays was to put the digits in an array. Then at the end figure out how many leading digits to blank.
    · If you don't need to blank leading digits, then you can just output them.
    DisplayValue:
      IF __PARAMCNT = 1 THEN
        tempWord = __PARAM1
      ELSE
        tempWord = __WPARAM12
      ENDIF
     
      isNegative = tempWord.15
      IF isNegative = 1 THEN
        tempWord = -tempWord
      ENDIF
     
      PUT segments, BLANK, BLANK, BLANK, BLANK
     
      DO WHILE tempWord >= 1000
        INC segments(3)
        tempWord = tempWord - 1000
      LOOP
     
      DO WHILE tempWord >= 100
        INC segments(2)
        tempWord = tempWord - 100
      LOOP
     
      DO WHILE tempWord >= 10
        INC segments(1)
        tempWord = tempWord - 10
      LOOP
     
      segments(0) = tempWord_LSB
      FOR cnt = 0 TO 3
        READ DigitSegs + segments(cnt), segments(cnt)
      NEXT
     
      IF isNegative = 1 THEN
        segments(3) = MINUS
        cnt = 2
      ELSE
        cnt = 3
      ENDIF
     
    BlankZeros:
        IF segments(cnt) = 126 THEN        ' IF digit is Zero...
          IF isNegative = 1 THEN
            PUT segments(cnt), MINUS, BLANK
          ELSE 
            segments(cnt) = BLANK          '   make it Blank
          ENDIF
        ELSE 
          cnt = 1                          ' Set counter to done value
        ENDIF
      DJNZ cnt,BlankZeros
     
      GOTO DisplayArray
    
    


    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman

    Post Edited (Bean (Hitt Consulting)) : 2/11/2007 12:59:54 PM GMT
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2007-02-12 11:17
    Bean,

    Me and array's don't get along, Would you mind going one step further and show me how you would declare that code



    Thanks
  • BeanBean Posts: 8,129
    edited 2007-02-12 13:31
    Try this...

    ' -------------------------------------------------------------------------
    ' Variables
    ' -------------------------------------------------------------------------
    
     
    digits          VAR     Byte (5)                 ' holds digits for display
     
    '---------------------------------------------------------------------------------
    LCD_Put_RJ_Value:
     
      ' Init digits to all zeros
      PUT digits, "00000"
     
      ' Convert value to ascii digits
      DO WHILE value >= 10000
        INC digits(0)
        value = value - 10000
      LOOP
      DO WHILE value >= 1000
        INC digits(1)
        value = value - 1000
      LOOP
      DO WHILE value >= 100
        INC digits(2)
        value = value - 100
      LOOP
      DO WHILE value >= 10
        INC digits(3)
        value = value - 10
      LOOP
      digits(4) = digits(4) + value_LSB 
     
      ' Blank leading zeros
      idx = 0
      DO WHILE idx < 4
        IF digits(idx) = "0" THEN        ' IF digit is Zero...
          digits(idx) = " "              '   make it Blank
        ELSE 
          idx = 4                        ' Set counter to done value
        ENDIF
        INC idx
      LOOP
     
      ' Send digits to LCD
      FOR idx = 0 TO 4
        char = digits(idx)
        GOSUB LCD_Write
      NEXT
     
      RETURN
     
    


    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman
Sign In or Register to comment.