-3

How to write C program in atmel studio to read and write to same port B. I want to read from port B pin 4 and write to the same port B but on pin 5. I have the following:


#include 


int main(void)
{
    DDRB = 0b00100000;

    while(1)
    { 
        PORTB = PINB;
    }
}

ofcourse not working, cannot find a tutorial on that on the net.

thanks

  • 2
    Tons of tutorials on the web... Like [this one](http://www.elecrom.com/avr-tutorial-2-avr-input-output/) – LPs Mar 17 '17 at 08:12
  • 'ofcourse not working' hahah thats the best. If it is so obvious why didn't you put more effort in searching for a tutorial. -.- – ckruczek Mar 17 '17 at 08:19

1 Answers1

0

Something fast:

int main() {
    //....
    //Init your pins and so on
    //....
    while (1) {
        if ((PINB & (1 << 4))) {
            PORTB |= 1 << 5;
        } else {
            PORTB &= ~(1 << 5);
        }
    }
}
unalignedmemoryaccess
  • 7,246
  • 2
  • 25
  • 40