Download Print this page

NEX ROBOTICS Fire Bird V ATMEGA2560 Software Manual page 47

Robotic research platform
Hide thumbs Also See for Fire Bird V ATMEGA2560:

Advertisement

NEX Robotics
3.1 Registers for using PORTs of the ATMEGA2560 microcontroller
Each pin of the port can be addressed individually. Each pin individually can be configured as
input or as output. While pin is input it can be kept floating or even pulled up by using internal
pull-up. While pin is in the output mode it can be logic 0 or logic 1. To configure these ports as
input or output each of the port has three associated I/O registers. These are Data Direction
Register (DDRx), Port Drive Register (PORTx) and Port pins register (PINx) where 'x' is A to L
(except I) indicating particular port name.
A. Data Direction Register (DDRx)
The purpose of the data direction register is to determine which bits of the port are used for input
and which bits are used for output. If logic one is written to the pin location in the DDRx, then
corresponding port pin is configured as an output pin. If logic zero is written to the pin location
in the DDRx, then corresponding port pin is configured as an input pin.
DDRA = 0xF0;
//sets the 4 MSB bits of PORTA as output port and
//4 LSB bits as input port
B. Port Drive Register (PORTx)
If the port is configured as output port, then the PORTx register drives the corresponding value
on output pins of the port.
DDRA = 0xFF;
//set all 8 bits of PORTA as output
PORTA = 0xF0;
//output logic high on 4 MSB pins and logic low on 4 LSB pins
For pins configured as input, we can instruct the microcontroller to apply a pull up register by
writing logic 1 to the corresponding bit of the port driver register.
DDRA = 0x00;
//set all 8 bits of PORTA as input
PORTA = 0xF0;
//pull-up registers are connected on 4 MSB pins and 4 LSB pins are floating
C. Port pins register (PINx)
Reading from the input bits of port is done by reading port pin register
x = PINA;
//read all 8 pins of port A
DDRx
PORTx
0
0
0
1
1
0
1
1
www.nex-robotics.com
I/O
Pull-up
Input
No
Input
Yes
Output
No
Output
No
Table 3.2
Fire Bird V Software Manual
Comments
floating input
Will source current if externally pulled
low
Output Low (Sink)
Output High (source)
47

Advertisement

loading
Need help?

Need help?

Do you have a question about the Fire Bird V ATMEGA2560 and is the answer not in the manual?