Are the numbers coming in as 34,56,78..... or are they coming in individually?Originally Posted by Lotondo
Are the numbers coming in as 34,56,78..... or are they coming in individually?Originally Posted by Lotondo
To pack single hex digits into a hex byte, just shift the first digit left four times, then add it to the second digit.
Ron
OK, I just try to make the situation clear...
You receive 8 ASCII-Characters "3", "4", "5", "6", ....
Then you want to pack 2 digits in 1 Byte and write them to the eeprom.
Yust try:
Chars Var byte[8] ;here are the 8 digits
For I=0 to 3 ;generate 4 bytes
;cut off unused bits and pack 2 of them
Dummy=(Chars[I<<1]<<4)|(Chars[(I<<1)+1] & $F)
Write I,Dummy
next I
(Very quick and quite dirty!)
PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2
Hi BigWumpus,
I know you did it real quick, but I think something's missing.
Dummy=((Chars[I<<1]-"0")<<4)|((Chars[(I<<1)+1]-"0") & $F)
Darrel
Thanks for answering, I believe you got me the solution.
I'll try and in case I'm not getting the correct result I'll
come back to you.
Regards
Lotondo
Hi Darrel,
I dont subtract the $30 because
-while shifting it 4 bits to the left, they drop out of the PIC ;-)
-while & $F they where masked out ;-)
try it smart !
PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2
BigWumpus,
Oh yeah. Your right!
That'll change the way I convert ascii numbers in the future. Thanks.
<br>
DT
Although the topic is quite old I am interested to solve a similar problem for which will really appreciate your support / expertise.
On short, I am receiving serially 16 ASCII-Characters, say "3", "B", "5", "A", "7", "F","1", "D", "2", "2", "4", "F","E", "E", "A", "6".
Then I need to pack 2 digits in 1 Byte and write them to the EEPROM. The final result should be: 2B 5A 7F 1D 22 4F EE A6.
Any clue or tip with regard to algorithm or conversion formula will be highly appreciated. Have a happy and prosperous New Year !
Bookmarks