Shop OBEX P1 Docs P2 Docs Learn Events
word hex counter — Parallax Forums

word hex counter

Mike WMike W Posts: 105
edited 2006-11-21 23:33 in General Discussion
I have been working on displaying word variables and I am having trouble with this Hex counter. It only displays two digits the right most digit counts (0 – F) as I expected but the left most digit only advances every 256 counts. I cannot get it to display four digits. What am I missing.
·
·Mike W


DEVICE········· SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
' IO Pins
'
Lcdout········· VAR···· RA.0··················· ' output to Parallax LCD
'
' Constants
'
LcdBaud·········· CON···· "T19200"········· ' or T2400, or T9600
LcdCls·············CON······ ·$0C············ ·' clear LCD (need 5 ms delay)
LcdCR············· CON····· ·$0D············ ·' move pos 0 of next line
LcdOn1··········· CON·······$16············ ·' LCD on; no crsr, no blink
LcdLine0Pos0··· CON····· ·$80············ ·' move to line 0, position 0
LcdLine1Pos0··· CON····· ·$94············ ·' move to line 1, position 0
'
' Variables
'
temp1·········· VAR···· ·Byte···················
counter········ VAR····· Word
wTemp1······· VAR····· Word
wTemp2······· VAR····· Word
wTemp3······· VAR····· Word
wTemp4······· VAR····· Word

'
' Subroutine DECLARATIONS
'
GET_HEX ·SUB·1, 3············· ' print using HEXx format
LCD_OUT········ SUB···· 1, 2···' send to LCD
' =========================================================================
' Program Data
' =========================================================================
· PROGRAM Start
' =========================================================================
'
' Program Code
'
Start:
· PLP_A = %0001································ ' pull up unused pins
· PLP_B = %00000000
· PLP_C = %00000000
· HIGH Lcdout ··································· ' make lcd output pin high
· pause 100······································· ' let LCD initialize
·· LCD_OUT LcdCls
·· LCD_OUT LcdOn1
· pause 5

Main:
· for counter = 0 to 65535
··· if counter = 65535 then
···· end
··· endif
·· LCD_OUT LcdLine1Pos0
·· GET_HEX counter, 4
···
pause 250
· next
goto Main
'
' Subroutines / Jump Table
'
LCD_OUT:
· temp1 = __PARAM1··································· ' digit to send
· SEROUT Lcdout, LCDBaud, temp1················· ' send the digitacter
·
· RETURN
'
GET_HEX:
· wTemp2 = __WPARAM12······························' copy output value
· IF __PARAMCNT = 2 THEN
··· IF __WPARAM23 = 1 THEN Low_Nib
· ENDIF
· SWAP wTemp2·········································· ' move high nib
· wTemp3 = wTemp2 & $0F·························· ·' make pointer
· READ Hex_Digit + wTemp3, wTemp1·········· ····' get NIB1 digit
· LCD_OUT wTemp1··································· ·· ' print it
· SWAP wTemp2·········································· ' restore low nib
Low_Nib:
· wTemp3 = wTemp2 & $0F··························· ' make digit pointer
· READ Hex_Digit + wTemp3, wTemp1·············· ' get NIB0 digit
· LCD_OUT wTemp1····' print it
· RETURN
' =========================================================================
Hex_Digit:
· WDATA·"0123456789ABCDEF"
'

Comments

  • BeanBean Posts: 8,129
    edited 2006-11-21 13:41
    Mike,
    I think the problem is how you are using __PARAMCNT.
    __PARAMCNT holds the number of bytes being passed to the subroutine. So if you pass a word (as you are) that will make __PARAMCNT = 2 (since a word is two bytes).

    Also, when you SWAP a word variable, it swaps the high and low BYTES. If you want to swap the nibbles you need to add the _LSB or _MSB postfix.
    SWAP wTemp2_LSB

    Terry

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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

    "People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
    ·
  • Mike WMike W Posts: 105
    edited 2006-11-21 22:51
    Thanks Bean
    ·
    Although I am still confused here is what I did.
    ·
    I removed the lines·················· IF· __PARAMCNT = 2 THEN
    ·················································· IF __WPARAM23 = 4 THEN Low_Nib
    ················································ ENDIF
    ·
    Then changed GET_HEX as shown below
    I now get three digits but cannot figure out why I cannot get four
    ·

    ·
    ·
    GET_HEX:
    · wTemp2 = __WPARAM12
    ·············································
    · wTemp4 = wTemp2_MSB & $0F············· ···········
    ·· READ Hex_Digit + wTemp4, wTemp1·········· ···········
    · LCD_OUT wTemp1·········· ······················· ···········
    ·
    SWAP wTemp2_LSB·························································
    · wTemp3 = wTemp2_LSB & $0F·····································
    ·· READ Hex_Digit + wTemp3, wTemp1···························
    · LCD_OUT wTemp1························································
    · SWAP wTemp2_LSB······················································
    ·
    Low_Nib:
    · wTemp3 = wTemp2_LSB & $0F·····································
    · READ Hex_Digit + wTemp3, wTemp1·····························
    · LCD_OUT wTemp1·························································
    ·
    · RETURN


    Mike W
  • BeanBean Posts: 8,129
    edited 2006-11-21 23:05
    Here ya go...

     
    DEVICE          SX28, OSCXT2, TURBO, STACKX, OPTIONX
    FREQ            4_000_000
    ' -------------------------------------------------------------------------
    ' IO Pins
    ' -------------------------------------------------------------------------
    Lcdout          PIN RA.0 OUTPUT             ' output to Parallax LCD
    ' -------------------------------------------------------------------------
    ' Constants
    ' -------------------------------------------------------------------------
    LcdBaud           CON     "T19200"          ' or T2400, or T9600
    LcdCls             CON        $0C              ' clear LCD (need 5 ms delay)
    LcdCR              CON       $0D              ' move pos 0 of next line
    LcdOn1            CON       $16              ' LCD on; no crsr, no blink
    LcdLine0Pos0    CON       $80              ' move to line 0, position 0
    LcdLine1Pos0    CON       $94              ' move to line 1, position 0
    ' -------------------------------------------------------------------------
    ' Variables
    ' -------------------------------------------------------------------------
    temp1         VAR      Byte                    
    counter       VAR      Word
    wTemp1        VAR      Word
    
    ' -------------------------------------------------------------------------
    ' Subroutine DECLARATIONS
    ' -------------------------------------------------------------------------
    GET_HEX  SUB 2      ' print using HEXx format
    LCD_OUT  SUB 1, 2   ' send to LCD
    ' =========================================================================
    ' Program Data
    ' =========================================================================
      PROGRAM Start
    ' =========================================================================
    ' -------------------------------------------------------------------------
    ' Program Code
    ' -------------------------------------------------------------------------
    Start:
      PLP_A = %0001                                 ' pull up unused pins
      PLP_B = %00000000
      PLP_C = %00000000
      HIGH Lcdout                                     ' make lcd output pin high
      pause 100                                        ' let LCD initialize
       LCD_OUT LcdCls
       LCD_OUT LcdOn1 
      pause 5 
     
    Main:
      for counter = 0 to 65535
        if counter = 65535 then 
         end
        endif
       LCD_OUT LcdLine1Pos0
       GET_HEX counter, 4
        
    pause 250
      next
    goto Main
    ' -------------------------------------------------------------------------
    ' Subroutines / Jump Table
    ' -------------------------------------------------------------------------
    LCD_OUT:
      temp1 = __PARAM1                                    ' digit to send
      SEROUT Lcdout, LCDBaud, temp1                  ' send the digitacter
      
      RETURN
    ' -------------------------------------------------------------------------
    GET_HEX:
      wTemp1 = __WPARAM12                              ' copy output value
     
      temp1 = wTemp1_MSB >> 4
      READ Hex_Digit + temp1, temp1
      LCD_OUT temp1
      
      temp1 = wTemp1_MSB & $0F
      READ Hex_Digit + temp1, temp1
      LCD_OUT temp1
      
      temp1 = wTemp1_LSB >> 4
      READ Hex_Digit + temp1, temp1
      LCD_OUT temp1
      
      temp1 = wTemp1_LSB & $0F
      READ Hex_Digit + temp1, temp1
      LCD_OUT temp1
      
      RETURN
    ' =========================================================================
    Hex_Digit:
      DATA "0123456789ABCDEF"
    ' -------------------------------------------------------------------------
    
    

    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

    "People who are willing to trade their freedom for·security deserve neither and will lose both." Benjamin Franklin
    ·
  • Mike WMike W Posts: 105
    edited 2006-11-21 23:33
    Thanks



    It would have been a while before I got to shifting

    I am picking apart·posted·code in an attempt to better understand SX/B I started playing with word variables and got a little stuck. Thanks for the gimmy

    Mike W
Sign In or Register to comment.