Shop OBEX P1 Docs P2 Docs Learn Events
HEX or Binary numbers to ASCII numbers — Parallax Forums

HEX or Binary numbers to ASCII numbers

ratothratoth Posts: 4
edited 2017-05-30 11:01 in General Discussion
I am currently working on a project for my instructor. I have designed a device that gives me the time between AC voltage and current (power Factor). I am using pulsin on the BS2 to measure the result and I would like to display these results on the Parallax serial display (2X16). All went fine untill I tried to send the display numbers after converting to degrees. I realize I need to convert these Hex or Binary numbers to their ASCII equivalent, for the display to understand them. I begin with a 16 bit word, 42 microseconds per degree, my results are 0 to 180 (Degrees) lead or lag. Do you have a routine that can help me? Any help you can offer is extremely appreciated. This device will be duplicated as a tool for all lab benches at Cuesta College, it is more than just a student project. Thank You for any and all help,

Robert Toth
ra-toth@hotmail.com

Comments

  • Here is a snippet of code from VB that might get you started
    Public Function hex2ascii(ByVal hextext As String) As String

    For y = 1 To Len(hextext)
    num = Mid(hextext, y, 2)
    Value = Value & Chr(Val("&h" & num))
    y = y + 1
    Next y

    hex2ascii = Value
    End Function
    Jim
  • The PBASIC DIG operator is your friend. Check out page 117 of the Stamp manual.

    value DIG n ' returns the nth decimal digit of value.
    debug DEC value DIG n + "0" prints the ascii value of the n'th digit.


  • Thank you both for your response, I will work with both solutions and evaluate my results. I truly appreciate all your help. Robert Toth.
  • I am more then grateful Parallax has put this site up. I am equally grateful for the people who have more knowledge than I, who take their time to respond with clear correct answers. Good job!

    Robert Toth
  • ratothratoth Posts: 4
    edited 2017-05-31 08:17
    Turns out this one line of code work great!

    SEROUT TX, LcdBaud, [DEC time, " ", "DEG"] ' send to LCD

    LcdBaud= Baud rate for the LCD.
    time= captured time from PULSIN

    Thanks again for all your help.

    Robert Toth
  • tomcrawfordtomcrawford Posts: 1,126
    edited 2017-05-31 16:17
    Next you can scale the PULSIN results so that it displays actual degrees.

    Edit. I take it back. I reread your original post and saw "after converting to degrees". My bad
Sign In or Register to comment.