The main way an microcontroller talks to the outside world is through the use of so call port pins. They can be used to send or receive a signal from a different component. This can be an output like a led, or an input like a button.
The arduino has 3 ports you can use called PORTB, PORTC and PORTD. PORTB has 7 pins it can set the signal for, port C has 6 pins and PORTD has 7 pins.
The main way of controlling the port pins in software is though the PORT, PIN and DDR registers.
The DDR register determins the direction of the different pins. These can be input (0), or output (1).
The PORT register is used to communicate the state of the pin. This can be low (0), or high (1).
If the direction of the pin is input, the value is taken from the component connected to the pin. If the direction of the pin is output, the value is written to the component.
The PIN register is used to determine the actual state of the pin, and is read-only.
Using the emulare emulator the state of the pins is immediately visible on the pins screen:
If the state of the pin is an input, you can select the wanted value from the combo boxes. This will then be visible in the corresponding PORT register.
If the state of the pin is an output, you cannot selected the value from the combo boxes. Instead the value you write in the PORT register will be visible in the combo boxes. Further more a grey square will indicate the value of the pin is low. A red square will indicate the value is high.
© COPYRIGHT 2010 Imre Leber