A2D question


Results 1 to 11 of 11

Thread: A2D question

Threaded View

  1. #6
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default


    TxBuf var byte[3]

    'basicaly here i want to convert advar into 3 ascii numbers
    'representing advar
    'So a result like 936 would put
    '57 in txbuf[1]
    '51 in txbuf[2]
    '54 in txbuf[3]
    'Then call the serial output routine which adds a stx char, 2 digits
    'a period then the last digit followed by an ETX char
    Dave, with referece to your code please note that when you declare an array, the number you state is the real number of elements of your array. you stated 3 elements, so you will have the following bytes available:

    txbuf[0]
    txbuf[1]
    txbuf[2]

    Now since you are decoding a 10bits adc then the maximum reading you can obtain in adval is 1023, which are four digits so you will need a 4 bytes array for your data transfer.
    Hence, you have to declare:

    txbuf var byte [4]

    and you will have the following bytes available:

    txbuf[0]
    txbuf[1]
    txbuf[2]
    txbuf[3]

    Please read page 33 of PBP manual, you will find the DIG instruction that could help you in moving the single digits into your array. Here a snippet as an example:

    Code:
    A  var byte   ' used for the FOR/NEXT loop
    
    For A=0 to 3
    txbuf[A]= adval DIG A
    next A
    
    'assuming adval contains the value 1023 then your array will end up as follows:
    
    'txbuf[0]="3"
    'txbuf[1]="2"
    'txbuf[2]="0"
    'txbuf[3]="1"
    
    In case you want them the other way then
    
    For A=0 to 3
    txbuf[A]= adval DIG (3-A)
    next A
    
    
    'will yield:
    
    'txbuf[0]="1"
    'txbuf[1]="0"
    'txbuf[2]="2"
    'txbuf[3]="3"
    Al.
    Last edited by aratti; - 24th July 2010 at 15:05.
    All progress began with an idea

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