Hi John,.

On 29-08-12 15:47, John in WI wrote:
First off, a big thank you to this group... it has answers to many of my
questions and I've learned a great deal. The jal libraries are fantastic.

Thanks!

I am trying to take a decimal formatted byte (sent serial from a PC) and
convert that to turning on/off individual pins.
My 8 pins are on different ports.... 4 on portb 4 portc. Other pins on C
and B ports are being used for other, non output purposes.

Often, when I program in basic or c++ there are functions to format a
decimal byte to a string of 0's and 1's..... then, using string
functions like MID I pick out each bit and get it's value that way.

That is a very inefficient way to do things (in a PIC)! You better learn how to handle individual bits in a byte! And it is not so difficult once you understand it. Example:

var byte x = "A"

In ASCII notation the bit-pattern of "A" is 0b0100_0001 and that of "a" is 0b0110_0001. So if you need to know if x contains a capital A or a lowercase a then you could do something like:

 if (x & 0b0010_0000) then      -- check if bit 5 is 1
    -- { whatever }
 end if

And if you want to be sure that x contains a lowercase letter regardless if it already uppercase or not then you could do

  x = x | 0b0010_0000           -- set bit 5 to 1

Note: bits in a byte are numbered right to left from 0 to 7.

Hope you understand this, once you do: there are more interesting bit-operations to learn!


I am not finding any way to format a decimal byte to a binary or ways to
pick out individual characters of a string with JAL.

The libraries 'Format' and 'Print' have conversion procedures.

Regards, Rob.

--
R. Hamerling, Netherlands --- http://www.robh.nl

--
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en.

Reply via email to