input digital signal
Following code is for setting port DDRB as output and DDRD is input.
PORTB1 will be high depending on PORTD2.
A pulldown resistoris required at PORTD2.
Similarly pullup resistor will be required at output PORTB1.
#include <avr/io.h>
int main (void)
{
DDRB = 0xFF;// set all pins on PORTB for output
DDRD &= ~(1 << PD2); // set Port PD2 low
while (1)
{
if (PIND & (1<<PD2)) // check whether PD2 is high (or low)
PORTB |= (1<<PB1); // set Port PB1 low
else // if it is low
PORTB &= ~(1<<PB1); // set Port PB1 low
}
return 0;
}