STR function blues...


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2004
    Posts
    81

    Default STR function blues...

    O.K., well I got my pulse count problems solved... Now the only problem is: Does anyone have a good routine on how to convert a number to a string? This is for odometer: so if say I have a mile count of 95,285 miles, I need to display "095285.0" on my display. (and before any one sugests it, using serout will not work: I have to store the string in an array...)

    Mean while I'll keep searching the net.

  2. #2
    Join Date
    May 2004
    Posts
    81


    Did you find this post helpful? Yes | No

    Default Never Mind...

    Perfect example of RTFM here... but incase anyone else ever runs into the same problem, the key is the DIG Modefier. Here is the code I came up with:


    For lcount = 0 to 9
    MsgBuff[9 - Lcount] = OdCountL dig lcount + 48
    Next


    MsgBuff is an array where I store the VFD messages (kind of like a buffer)

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi bearpawz,

    Along with RTFM, there's UTFM. Because, along with reading it, you have to Understand it.

    The largest DIG you can use is 4. This is because the largest number you can have is 65535, which has only 5 digits. So, DIG 9 is out of the question.

    Which begs the question, how are you storing mileage of 7 digits (6 + 1 decimal) "095285.0"? It's going to take more than just a word variable.

    It can be done, but just not the way you've shown.

    Best regards,
    Darrel

  4. #4
    Join Date
    May 2004
    Posts
    81


    Did you find this post helpful? Yes | No

    Default

    Your absolutly right about that. One of the graces I have found with DIG is if the digit does not exest (like Dig 9), it returns a 0.. So so far everything looks fine until the word variably I have maxs out at 65535.

    Since a 16 bit word is not big enough I have to store half in one word variable and the other half in another.




    Some simple code:

    OdCountL = OdCountL + 1 ' Increment Low Word Count
    If OdCountL = 10000 then ' Roll Over at 9999 (999.9)
    OdCountH = OdCountH + 1 ' Increment High Word Count
    If OdCountH = 1000 Then ' Roll Over at 999 (999 + 999.9)
    OdCountH = 0 ' Zero the High Word Counter
    Endif
    OdCOuntL = 0 ' Zero the low word counter
    Endif

    ....

    For lcount = 0 to 3
    MsgBuff[9 - Lcount] = OdCountL dig lcount + 48
    Next
    For lcount = 0 to 2
    MsgBuff[5 - Lcount] = OdCountH dig lcount + 48
    Next

Similar Threads

  1. Single button function
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 40
    Last Post: - 4th April 2020, 18:33
  2. SLOW Serin2 and Serout2
    By dragons_fire in forum General
    Replies: 3
    Last Post: - 26th June 2009, 02:38
  3. ATAN2(,) function
    By vk2tds in forum PBP Wish List
    Replies: 0
    Last Post: - 25th November 2005, 02:52
  4. Serin2 and STR Modifier
    By _Ian in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 22nd June 2005, 16:25
  5. Random function - How to limit it ??
    By martarse in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 30th November 2004, 14:05

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