avr-c digital pin read write

avr-c digital pin read write
  1. Arduino UNO
#include <avr/io.h> #include <util/delay.h> //#include <Arduino.h> /* The following code turns pin 5 of port b high: PORTB |= (1<<PORTB5); And to turn the output low: PORTB &= ~(1<<PORTB5); */ /* if( !(PIND & (1<<PD0)) ) PORTB |= (1 << PB0); else PORTB &= ~(1 << PB0); */ int main(void) { //Serial.begin(9600); DDRB = 0xFF; DDRD = 0x00; while (1) { byte val = PORTB; if ((PIND & (1<<PD2)) != 0) { val |= (1<<PB0); } else { val &= ~(1<<PB0); } if ((PIND & (1<<PD3)) != 0) { val |= (1<<PB1); } else { val &= ~(1<<PB1); } if ((PIND & (1<<PD4)) != 0) { val |= (1<<PB2); } else { val &= ~(1<<PB2); } if ((PIND & (1<<PD5)) != 0) { val |= (1<<PB3); } else { val &= ~(1<<PB3); } if ((PIND & (1<<PD6)) != 0) { val |= (1<<PB4); } else { val &= ~(1<<PB4); } if ((PIND & (1<<PD7)) != 0) { val |= (1<<PB5); } else { val &= ~(1<<PB5); } PORTB = val; //Serial.print("PORTD: ");Serial.println(PORTD, BIN); _delay_ms(50); } }