Do you want hex or ASCII hex?
Ioannis
To send ascii 0 0 0 0 you would do this:
COM_CODE[0]="0"
COM_CODE[1]="0"
COM_CODE[2]="0"
COM_CODE[3]="0"
SEROUT2 PORTB.2,19697,[STR COM_CODE\4]
"I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams
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:
Hope this helps,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
Ioannis
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]]
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
Bookmarks