Step 5Going Further
Basically, what happens when you tell a pin to go high or low is that you modify a 8-bit register. (Remember how the pins go from A0-A7, B0-B7? 8 pins per letter, so those 8 pins are toggled by that one register). A register holds 8 bits (Each bit can be 0 or 1).
When you execute the command to put a pin high, the appropriate bit in the register is set to 0. (1 would be low).
Having 8 pins toggled by one register can also have its advantages, mainly that you can toggle any of the 8 pins nearly simultaneously.
For example, if I wanted to turn pins C0 through C6 high and C7 low, the command would be:
PORTC = 0b10000000;
Note how the first pin number coming after the "b" is pin 7, and it goes down from there until pin 0.
0b10000000 is an 8-bit binary number, you can convert it to hex for a cleaner look. Doing it manually is a pain (but useful knowledge), an easier method would be to google "0b10000000 to hex", which results in "0x80".
PORTC = 0x80;
For further reading, see here:
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=37871
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230286016
(thanks gmoon and westfw for the links)
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|







































