RP6 ROBOT SYSTEM - 4. RP6 CONTROL M256 WIFI Library
4.1.7. I/O Ports
As the RP6 CONTROL M256 features in total 60 free I/O ports, we will describe here
how I/O ports of an AVR can be accessed in general. We will NOT describe hardware
modules like timer capture, output modulator and others in detail. Please refer to the
data sheet on how to use these modules.
The ATMEGA2560 has 9 I/O ports of 8 bit each plus one with 6 bit. Every port is con -
trolled via 3 registers. One register is for the “direction” of the 8 I/O pins (DDRx) i.e.
input or output, one register for writing (PORTx) and one register for reading (PINx).
If you want to use an I/O pin as an output e.g. to switch a LED, the relevant bit in the
DDRx register must be set to 1, 'x' being the name of the port (A, B, C, … up to L
(there is no PORTI)).
Example:
DDRL |= IO_PL5_OC5C; // PL5 is now an output
DDRL = IO_PL5_OC5C | IO_PL4_OC5B | IO_PL0_ICP4; // PL5, PC4, PC0 are now out-
puts, all other pins of PortL are inputs!
DDRE |= IO_PE2_XCK0_AIN0 | IO_PE4_OC3B_I4; // PE2, PE4 are now outputs
Via the PORTx register, the output can be set to high or low level.
Example:
PORTL |= IO_PL5_OC5C; // High
PORTL &= ~IO_PL5_OC5C; // Low
If a bit in the DDRx register is set to 0, the relevant pin is an input.
Example:
DDRD &= ~IO_PD7_T2; // PD7 is now an input
PINx register shows the status of the pin, i.e. if a high or a low level is applied to the
pin.
if(PINC & IO_PC6)
writeString_P("PC6 is HIGH!\n");
else
writeString_P("PC6 is LOW!\n");
The built-in pullup resistors can be activated if the bits in PORTx register are set (only
applicable if the port is configured as an input).
The ADC channels can also be used as I/O pins. Please note the different spellings
compared to the names above (ADC_7 vs. ADC7)!
IO_ADC7, IO_ADC6,...
The definition of all I/O pins is in the header file RP6M256.h of the RP6M256Lib. Basic-
ally it is possible to use only numbers but names are often easier to identify.
Instead of e.g. IO_PE6_T3_I6 you can also write (1 << PINE6). This is identical and
only defined like this in header RP6M256.h of the library.
By the way, after a reset, the bootloader configures all I/O ports on the expansion
connectors as INPUT with pullup resistor. The only exception are the ports of the LCD
connector. Those become only inputs if the display output of the bootloader has been
deactivated. Please note: These are defined as outputs in the normal library! You
might have to change this!
- 33 -