Hi guys, I was just composing a reply, when Rob his message came in, which contains most of what I was about to say. Just want to add that JAL has a way to name individual (or multiple) bits within a byte, which could be usefull in this case.
This: var byte reg ; your input value var bit reg_0 at reg:0 var bit reg_1 at reg:1 Defines a single byte, and creates names for the lower two bits of this bytes - so this are the same bits (see 'at' in the definition). Next: reg = 1 puts 0b00000001 in reg, so reg_0 becomes one (true) and reg1 becomes zero (false). You can use these values to define pins like: pin_b0 = reg_0 pin_b3 = reg_1 Hope this helps (and does not contain too much typos - I have not compiled the code before posting). Joep 2012/8/29 Rob Hamerling <[email protected]>: > > 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. > -- 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.
