Convert long binary number to ASCII Decimal


Closed Thread
Results 1 to 7 of 7

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Code:
    ' 
    
    Variables
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    
    W               var Word [8]      ' words array
    Tcount          var Word          ' timer count
    Ocount          var word          ' OverFlow timer count
    
    A0              var byte          ' general purpose variable
    
    '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    
    
    W[0] = (Ocount * 5) + Tcount dig 4
    W[1] = (Ocount * 3) + Tcount dig 3 + W[0] dig 1
    W[2] = (Ocount * 5) + Tcount Dig 2 + W[0] dig 2 + W[1] dig 1
    W[3] = (Ocount * 5) + Tcount Dig 1 + W[0] dig 3 + W[1] dig 2 + w[2] dig 1
    W[4] = (Ocount * 6) + Tcount Dig 0 + W[1] dig 3 + W[2] dig 2 + W[3] dig 1
    W[5] = W[2] dig 3 + W[3] dig 2 + W[4] dig 1
    W[5] = W[3] dig 3 + W[4] dig 2 + W[5] dig 1
    W[6] = W[4] dig 3 + W[5] dig 2 + W[6] dig 1
    W[7] = W[5] dig 3 + W[6] dig 2 
    
    
    For A0 = 7 to 0 step -1
    'Display W[A0] Dig 0
    Next A0
    This code (not tested) should add up (overflow number x 65535) and timer counter and distribute the result into the array in position 0 the number (digit) to be displayed.

    Just run a for/next cycle with W[x] Dig 0 and you should display your number on your 8 digits display.

    If you need the ascii value then you have to add 48 to every single digit in the for/next loop.

    Al.
    Last edited by aratti; - 9th July 2009 at 11:03.
    All progress began with an idea

  2. #2
    Join Date
    Aug 2006
    Posts
    65


    Did you find this post helpful? Yes | No

    Default

    Thanks all!

    Aratti, I ended up using your algorithm, but I fixed a few errors to make it work. Here's the code I ended up with:

    W[0] = (Ocount * 6) + Tcount dig 0
    W[1] = (Ocount * 3) + Tcount dig 1 + W[0] dig 1
    W[2] = (Ocount * 5) + Tcount Dig 2 + W[0] dig 2 + W[1] dig 1
    W[3] = (Ocount * 5) + Tcount Dig 3 + W[0] dig 3 + W[1] dig 2 + w[2] dig 1
    W[4] = (Ocount * 6) + Tcount Dig 4 + W[1] dig 3 + W[2] dig 2 + W[3] dig 1
    W[5] = W[2] dig 3 + W[3] dig 2 + W[4] dig 1
    W[6] = W[3] dig 3 + W[4] dig 2 + W[5] dig 1
    W[7] = W[4] dig 3 + W[5] dig 2 + W[6] dig 1

    Thanks again
    Joe

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    I was sure some adjustment was going to be necessary since I didn't tested it.


    Al.
    Last edited by aratti; - 9th July 2009 at 15:18.
    All progress began with an idea

Similar Threads

  1. How to convert binary to decimal?
    By Cabomba in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 13th October 2007, 02:27
  2. hex ascii help please
    By ffr58kk90 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 29th December 2006, 22:09
  3. Decimal to Binary Conversion
    By schlaray in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 23rd December 2006, 15:58
  4. Decimal to binary conversion
    By Demon in forum Code Examples
    Replies: 9
    Last Post: - 25th February 2005, 21:05
  5. Convert a word variable to decimal
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 4th December 2004, 21:02

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