Multi-digit word variable to string


Closed Thread
Results 1 to 40 of 44

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Dear all,

    i have some problem regarding the conversion of a variable to string.

    I have the following code.


    Code:
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                         VAR for IR to LCD          '
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    IRCS         var byte       ' this is the checksum for the IR required in external display command
    TEMP         var word       ' this is the word variable for TEMP 
    temperature  var word       ' for result and output to lcd 
    TEMPIR       var word       ' set a variable tempir 
    Remainder    var word       ' Get the remainder = tempir//50
    
    '------------------------------------------------------------------------------*
    '                    Measure IR object temp sent to uLCD                          *
    '------------------------------------------------------------------------------*
    object:
    
    reg    = $07             ' based on the datasheet $07 is the object's temp
    addr   = %10110100       ' $B4  binary value: %10110100
    i2cwrite SDA, scl, addr  ' send write command, shift the address B4, 8 bits where LSB is W = 0
    i2cwrite sda, scl, reg   ' register is $07
    
    addr   = %10110101       ' $B5  Binary value: %10110101
    i2cwrite sda, scl, addr  ' sends read command, shift the address B5, 8 bits where LSB is R = 1, clock idles low
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte] ' reg = $07
    
    
    tempir = (temp.highbyte << 8) + temp.lowbyte
    
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    remainder    = (tempir*2)//100   ' multiply x 2 and get the remainder //100
    
    pause 100
    gosub display
    return
    
    '------------------------------------------------------------------------------*
    '                    IR  Display 1 the parameters                              *
    '------------------------------------------------------------------------------*
    display: ' IR TEMP 
    hserout2 [$73,$00,$02,$12,$00,$ff,"IR TEMP:",00]
    Hserin2  timeout,error,[wait(6)]
    hserout2 [$73,$08,$02,$12,$F8,$00,dec2 temperature,".",dec2 remainder,"*C",00] 'this one works on display 1 which doesnt require CS 
    Hserin2  timeout,error,[wait(6)]
     
    
    gosub checksum2    
    hserout [$01,$0F,$00,temperature,remainder,IRCS]   ' this one doent work, i get random numbers on the display. 
    Hserin  timeout,error,[wait(6)]
    return
    
    '------------------------------------------------------------------------------|
    '                               CHECKSUM IR                                    |
    '------------------------------------------------------------------------------|
    checksum2:
    IRCS = 0
    IRCS = $01 ^ $0F ^ $00 ^ temperature
    IRCS = IRCS ^ remainder
    return

    One i do the CS calculation, and returning from checksum2 the following is not working as expectred.

    Code:
    hserout [$01,$0F,$00,temperature,remainder,IRCS]   ' this one doent work, i get random numbers on the display. 
    Hserin  timeout,error,[wait(6)]
    return
    even if i try the following.

    Code:
    hserout [$01,$0F,$00,dec2 temperature,dec remainder,IRCS]   ' this one doent work, i get random numbers on the display. 
    Hserin  timeout,error,[wait(6)]
    return
    Is there a way to convert the variable to string ourside from a preset command like the HSEROUT?

    for example is there a way to make something like this in PBP?

    temperature = #temperature.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    If your variable is ranging from 0 to 65536 (the maximum that word can hold) obviously the HSEROUT command cannot handle that. With HSEROUT you can use only ascii values.

    So, as you have already find out, the dec2 temperature does work. Maybe your value is beyond 2 decimals so you have to use dec5 to be sure and cover all temperature values?

    Ioannis

  3. #3
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Ioanni,

    i do write the following for me to understand.

    i have the var TEMPIR which gives a value for example of 14450.

    Then i do have an other VAR which is temperature.

    If i devide
    Code:
    temperature = TEMPIR / 50
    we get
    Code:
    289
    .

    then for getting the temp value we do
    Code:
    temperature = temperature - 273
    , which gives to us 16. But we do not get the remainder value.

    The remainder value is
    Code:
    Remainder = TEMPIR*2//100
    , which the result is 9 for our example of 14450.

    Now i have an LCD that requires a CS value to be added in a command.

    Name:  command.png
Views: 3867
Size:  15.3 KB

    Thats why i gosub to find and calculate the CS value of the overal command.

    I think that i need somehow to calculate and convert the variable to string, ourside from the HSEROUT command.

    Apparently the DEC5 didnt work.

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    The msb and lsb in your display string what are exactly? Ascii values or binary?

    And being msb and lsb, I understand that these two construct a word value. For what purpose? Your display for example, can display on screen a binary word value of %0000000000000001 as plain 1?

    Ioannis

  5. #5
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    According to the manual of the display and the VISI GENIE OS.

    The following is an example.

    Name:  command2.png
Views: 4002
Size:  81.8 KB

    I'm missing something, because right now as the code is, returning from the Checksum calculation, the HSEROUT command is set right. But i do get HEX result. Right?

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,172


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    The number is just the same either hex, binary or decimal. 128 is the same as %10000000 or $80. You show it in different way.

    The trackbar object, what exactly is?

    Ioannis

  7. #7
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Trackbar is only an object ID in VISI GENIE OS for the Display like the following.

    Name:  command3.png
Views: 3569
Size:  54.5 KB

    in our case we do use the LEDDIGITS which the OBJECT ID is $0F

    Name:  command4.png
Views: 3328
Size:  37.8 KB

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts