Simple questions
ThePenguinMaster
Posts: 89
Ok I have what I’m sure is not a difficult question, but I am having difficulty understanding the concept by reading the propeller manual.
What I would like to do is have a byte and simply access one bit from the byte.
An example of this is if you were to have a function that has a single parameter for a byte, and it takes the byte and sets a pin on the prop to a specific position in the byte. This is really just like shifting out a byte through a serial interface. I know there are already objects that will handle serial communication, but what if I wanted to simply check a single bit? The end result will be to send a byte through a pin using SCI, but I would like to have a better understanding on how the byte is shifted and a single bit is output. Looking through the existing objects provides some examples, but it is difficult for me to fully understand how it works. I could simply copy and paste the code, but that won’t get me anywhere in the long run. If there is any reference that you would recommend, I would greatly appreciate it. I have spent some time searching for keywords, but have not turned up many results that fully explain the process.
What I would like to do is have a byte and simply access one bit from the byte.
An example of this is if you were to have a function that has a single parameter for a byte, and it takes the byte and sets a pin on the prop to a specific position in the byte. This is really just like shifting out a byte through a serial interface. I know there are already objects that will handle serial communication, but what if I wanted to simply check a single bit? The end result will be to send a byte through a pin using SCI, but I would like to have a better understanding on how the byte is shifted and a single bit is output. Looking through the existing objects provides some examples, but it is difficult for me to fully understand how it works. I could simply copy and paste the code, but that won’t get me anywhere in the long run. If there is any reference that you would recommend, I would greatly appreciate it. I have spent some time searching for keywords, but have not turned up many results that fully explain the process.
Comments
Read the descriptions of these bit operators and shift operations in the Propeller Manual:
& logical and
| logical or
^ logical exclusive or
! bit complement
>> shift right
<< shift left
To set a bit in a variable, use "|" (like a := a | %100).
To clear a bit in a variable, use "&" and "!" (like a := a & !%100).
To test a bit, use "&" (like IF a & %100).
outa[noparse][[/noparse]SDA] := (data <-= 1) & 1
This example is what I was looking at and it is clear now. The result of 1 and the data is sent out to the port. This is done in a loop, and only the result of the first bit & 1 is sent. The data byte is also using a bit rotating to move to the next bit (from what I am interpreting.)
Showing your example with the binary value was a good reminder to push me in the right direction here. Seeing "1" and seeing a binary value kind of reminded me that it is a binary comparison.
Yeah, a tutorial isn’t really what I was looking for. I know it is a simple concept, but most of my programming experience is application programming and scripting. Thanks for pointing me in the right direction.