I'm a beginner, I have an Atmel STK500 AVR development board.
EDIT: I didn't explain what the code does, sorry :S When I press a button on the board, the corresponding LED lights up until I release the button!
I've manipulated code I found on the internet into this:
That code works fine. I wanted to try to write the same thing another way. Here's what I have so far:Code:#include <avr/io.h> // avr header file for IO ports int main(void){ DDRA = 0x00; // set PORTA for input DDRB = 0xFF; // set PORTB for output PORTB = 0x00; // turn ON all LEDs initially while(1){ PORTB = PINA; } return 1; }
This code builds and compiles but when I run the program on my development board the LEDs just stay lit and the buttons do nothing. I want to achieve the same results as I do with the first code, just written differently. I also noticed that my second code doesn't have a loop, does it need one? Any help? Thank you!Code:#include <avr/io.h> // avr header file for IO ports int main(void){ DDRA = 0x00; // set PORTA for input DDRB = 0xFF; // set PORTB for output PORTB = 0x00; // turn ON all LEDs initially if(PORTA == 0){ PORTB = 0; } else PORTB = 1; return 1; }