> Well, I was mistaken. PIC only offers assembler and C. There are other
> tools available, but not directly available from them.
>
> Unless things get very complicated you are better off with the PICAXE IMHO.
>
> Doc Custer
> Retired Software Engineer and sometime Audiologist
>
> I agree Doc. I am a bit disappointed in the lack of in line
> assembler code. PICAXE brush it off as bad programming.
>
> Do you know how to convert a 4 character ASCII decimal number
> into a 16 bit binary number in PICAXE BASIC?
>
> I can do it in ASM by masking the high 4 bits, shifting left
> the lower four bits and anding the digits.
>
> This is for the heading auto pilot that gets in heading info
> from the GPS in ASCII characters. 189.1 degrees for an example.
> Here is the ASCII binary codes. I need a binary number to control
> the aileron servo.
>
> Dec Binary Hex ASCII
> 48 00110000 30h 0
> 49 00110001 31h 1
> 50 00110010 32h 2
> 51 00110011 33h 3
> 52 00110100 34h 4
> 53 00110101 35h 5
> 54 00110110 36h 6
> 55 00110111 37h 7
> 56 00111000 38h 8
> 57 00111001 39h 9
>
> BTW the PICAXE would make a great waste gate or boost controller for
> all those turbo guys out there. An intake air temp sensor as well
> as the MAP sensor could be used to back off on the boost when
> the intake air temp. gets over 140 degrees F to prevent detonation.
>
> Paul Lamar ...No rotor no motor.
> I can do it in ASM by masking the high 4 bits, shifting left
> the lower four bits and anding the digits.
Not quite so simple. You also need to change from base 10 to base 2.
If you just shift and add, there will be holes in the binary sequence.
For example 8, 9, 10 with shift and add would be 0000 1000, 0000 1001,
0001 0000. You need 0000 1000, 0000 1001, 0000 1010. One method would
be to first mask off the high bits and put the least significant digit
into a register. Take the next digit and decrement it to zero.
On each decrement, add 1010 (10 decimal) to the register. Next digit
decrement and add 0110 0100 (100 decimal) to the register. For the last
digit, decrement and add 0011 1110 1000 (1000) decimal. When you get
done, the register will hold the binary equivalent of your heading to a
resolution of 0.1 deg.
I've written ascii to binary or hex routines in Basic, C, and
assembler, but it was 30-40 years ago. :)
Bob W.
Not the way I see it. Mask first.
Shift left 3 times for MSD (1)
Shift left 2 times for next digit (8)
Shift once for the next digit (9)
No shift for the last digit. (1)
Ignore the decimal point.
The character numbers are always less than 9. No tens involved.
1 8 9 1
0001 1000 1001 0001
Viola 16 bit binary number.
I think we are saying the same thing :)
--
Paul Lamar ...No rotor no motor.
I don't think so. The number you are displaying is a binary
representation of a decimal (base 10) number (BCD). It's not a binary
number. As earlier noted with your shift method, 9 = 0000 1001 and 10
= 0001 0000. Do a binary subtraction and you don't get 0000 0001.
Actually Paul, I thought you would get this immediately and only
explained it in as much detail as I did for the less computer
literate. :) You can do all the math in BCD but the math routines
will be more complex and if you need binary out, the base will still
have to be changed.
Bob W.
--
N93BD - Rotary Powered BD-4 -
http://www.bob-white.com
First Flight: 11/23/2006 7:50AM - 3.3 Hours Total Time
Cables for your rotary installation -
http://www.roblinphoto.com/shop/
Right packed BCD my mistake. I forgot.
I used to use packed BCD all the time I fell into the packed BCD mode.
The 6502 could do packed BCD math. Ok I'll dig up the ASM commands.
BTW here is what some of the guys on the forum came
up with doing it in BASIC.
BeanieBots Posted - 1 March 2007 15:57
The ASCII value is the numeric value plus $30. So simply reverse it.
3 digit number ABC value=(A-$30)*100+(B-$30)*10+(C-$30)*1
hippy Posted - 1 March 2007 16:28
And optimised, for 4-digit ABCD w0 = A*10+B*10+C*10+D-53328
Paul Lamar ...No rotor no motor.
The Rotary Engine NewsLetter. Powered by Linux.
ACRE NL web site.
http://www.rotaryeng.net
Copyright 1998-2006 All world wide rights reserved.