myPinState = port_pin_read(myPort, myPin);
port_pin_set()
Description: Sets a pin in a port to 1.
Syntax: port_pin_set(uint8_t PORTx, uint8_t pin)
Parameters:
uint8_t PORTx: The port as identified in io.h.
uint8_t pin: The pin number 0 to 7.
Returns: Nothing.
Example:
// if myPin is clear, set myOtherPin
if (port_pin_read(myPort, myPin) )
port_pin_set(myPort, myOtherPin);
port_pin_clear()
Description: Clears a pin in a port to 0.
Syntax: port_pin_clear(uint8_t PORTx, uint8_t pin)
Parameters:
Returns: Nothing.
Example:
// if myPin is set, clear myOtherPin
if (port_pin_read(myPort, myPin) )
port_pin_set(myPort, myOtherPin);
port_pin_activate_pullup()
Description: Activates the pull-up resistor for a pin in
a port.
Syntax: port_pin_activate_pullup(uint8_t ddrx, uint8
_t pin)
Parameters:
uint8_t ddrx: The port as identified in io.h.
uint8_t pin: The pin number 0 to 7.
Returns: Nothing.
Example:
// Activate the pullup on PORTB pin 5
port_pin_activate_pullup(DDRB, 5)
port_pin_deactivate_pullup()
Description: Deactivates the pull-up resistor for a pin
in a port.
Syntax: port_pin_deactivate_pullup(uint8_t ddrx,
uint8_t pin)
Parameters:
uint8_t ddrx: The port as identified in io.h.
uint8_t pin: The pin number 0 to 7.
Returns: Nothing.
Example:
// Deactivate the pullup on PORTB pin 5
port_pin_deactivate_pullup(DDRB, 5)
port_pin_toggle()
Description: Toggles (if 0, sets to 1; if 1, sets to 0) the
state of a pin in a port.
Syntax: port_pin_toggle(uint8_t PORTx, uint8_t pin)
Parameters:
Returns: Nothing.
Example:
// Force pin 5 to change state regardless of state
port_pin_toggle(PORTB, 5)
Applying Digitalio —
Simple Chaser Lights
Last month, we showed how to set up the hardware
for the AVR Butterfly and the Arduino to use the Arduino
■ FIGURE 8. Arduino port/pins for DIP switch and LEDs.
52
November 2011