Need help sending a hex serial output


Closed Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,139


    Did you find this post helpful? Yes | No

    Default

    If you want ASCII Hex then every binary number in the range 0-9 should be added to 48 because ASCII 48 is character zero.

    But what about after 9?

    Well Melanie has posted a solution while back:

    Code:
    MyVar var word 
    ' Variable containg 16-bit value 
    ' MyVar's contents are destroyed on exit 
    MyData var byte (4) 
    ' Four byte Array containing ASCII HEX result 
    ' MSB is in MyData(3), LSB is in MyData(0) 
    CounterA var byte 
    ' General Purpose Counter 
    
    For CounterA=0 to 3 
    MyData(CounterA)=MyVar&$0F 
    MyData(CounterA)=MyData(CounterA)+48 
    If MyData(CounterA)>57 then 
    MyData(CounterA)=MyData(CounterA)+7 
    endif 
    MyVar=MyVar>>4 
    Next CounterA
    Hope this helps,
    Ioannis

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    So instead of this...

    SEROUT2 PORTB.2,19697,[COM_CODE[I]]

    ...you want to send four digits of HEX...

    SEROUT2 PORTB.2,19697,[HEX4 COM_CODE[I]]

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,139


    Did you find this post helpful? Yes | No

    Default

    Hi Melanie.

    Since he has an array, he needs a way to convert it before sending each array element.

    The solution of in-situ conversion I think will not help him.

    Also as kamikaze47 stated his array should be word instead of byte.

    So the example of yours code I gave is really for byte and needs some modification.

    Ioannis

Similar Threads

  1. Serial Output - for an ASM numb
    By scomi85 in forum Serial
    Replies: 0
    Last Post: - 1st March 2009, 10:13
  2. PIC18F4680 to PC via MAX232 (RS232 serial) no output
    By opticsteam1 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th April 2008, 20:39
  3. Serious Serial Situation Setbacks...
    By Dansdog in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th February 2007, 03:46
  4. HSEROUT Newbie question/problem
    By Mark Scotford in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 11th July 2006, 14:44
  5. Replies: 2
    Last Post: - 20th January 2006, 21:09

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