Ateml AVR GPIO operations quick guide
Posted: Fri Apr 13, 2012 12:05 am
All port B pins as output (Direction register)
All port pins set to 1 (ON)
Set port D pin 2 as output
Set port D pin 2 as input
Set port B pin 2 to 1 (ON)
OR
OR
Set port B pin 2 to 0 (OFF)
OR
OR
Check if port D pin 3 equal to 1 (ON)
Check if port D pin 3 equal to 0 (OFF
Code: Select all
DDRB = 0xff;
Code: Select all
PORTB = 0xff;
Code: Select all
DDRB |= 1 << DDB2;
Set port D pin 2 as input
Code: Select all
DDRB &= ~(1 << DDB2);
Set port B pin 2 to 1 (ON)
Code: Select all
PORTB |= _BV(PB2);
Code: Select all
PORTB |= 1 << 2;
Code: Select all
PORTB |= 1 << PINB2;
Set port B pin 2 to 0 (OFF)
Code: Select all
PORTB &= ~_BV(PB2);
Code: Select all
PORTB &= ~(1 << 2);
Code: Select all
PORTB &= ~1 << PINB2;
Code: Select all
if (PIND & (1<<PIND3))
{
...
}
Check if port D pin 3 equal to 0 (OFF
Code: Select all
if (!(PIND & (1<<PIND3)))
{
...
}