Menu

Using Word Variables in Subroutines

Help
2007-03-27
2013-05-30
  • Nobody/Anonymous

    Been playing around with sending a word variable to an EEPROM and then retreiving it.  Can get the high and low bytes read back as expected.  But when reassembling the word variable, and then trying to pass on to a sub, there are problems.  Any sort of high byte manipulation, like multiplying by 256, or; dividing the word variable by a 1000, returns a zero.

    There seems to be some sort math limitation here, but not sure of the rules.

    Thanks for any help.

    Kent

    The code would go something like:
    Dim logtemp As Word
    Dim LCDValue As Word
    ...
    ...
    ...
    address = 1
    addrl = address
    addrh = address_h
    for count = 1 to 2
    if count = 1 then logtempl =  eeprom_receive(addrh,addrl)
    address = address + 1
    addrl = address
    addrh = address_h
    wait 1 sec
    if count = 2 then logtemph = eeprom_receive(addrh,addrl)
    wait 1 sec
    Next
    logtemp = logtempl
    logtemp_h = logtemph
    '***No problems to this point***
    Mod (logtemp As Word)
    LCD_Rst
    goto Main

    sub Mod(LCDValue As Word)#NR 
    SERMIL = 0
    SERCEN = 0
    SERDEC = 0
    SERUN = 0
    LCDValueTemp = 0
    IF LCDValue >= 1000 then
    LCDValueTemp = LCDValue / 1000
    SERMIL = LCDValueTemp + 48
    TransmitSerial(SERMIL)
    LCDValue = LCDValue - LCDValueTempA * 1000
    End if
    IF LCDValueTemp >0 Or LCDValue >= 100 then 
    LCDValueTemp = LCDValue / 100
    SERCEN = LCDValueTemp + 48
    TransmitSerial(SERCEN)
    LCDValue = LCDValue - LCDValueTemp * 100
    end if
    IF LCDValueTemp > 0 or LCDValue >= 10 then
    LCDValueTemp = LCDValue / 10
    SERDEC = LCDValueTemp + 48
    TransmitSerial(SERDEC)
    TransmitSerial_Print(".")
    LCDValue = LCDValue - LCDValueTemp * 10
    end if
    SERUN = LCDValue + 48
    TransmitSerial(SERUN)
    TransmitSerial_Print(" ")
    end sub 

     
    • Nobody/Anonymous

      Of course the subroutine(variable as word) works!  Needed to expand the decimal to ascii (i.e. SERInt routine) to handle SERDECMIL, SERMIL.  Also forgot to make sure LCDValueTemp was Dim as a word, too.

      Regards,
      Kent

      sub ascii(LCDValue as Word)#NR 
      SERDECMIL = 0
      SERMIL = 0
      SERCEN = 0
      SERDEC = 0
      SERUN = 0
      LCDValueTemp = 0
      IF LCDValue >= 10000 then
      LCDValueTemp = LCDValue / 10000
      SERDECMIL = LCDValueTemp + 48
      TransmitSerial(SERDECMIL)
      LCDValue = LCDValue - LCDValueTemp * 10000
      End if
      If LCDValue >= 1000 Then
      LCDValueTemp = LCDValue / 1000
      SERMIL = LCDValueTemp + 48
      TransmitSerial(SERMIL)
      LCDValue = LCDValue - LCDValueTemp * 1000
      End if
      etc.
      etc.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.