I'm trying to read a value from an avr pin but it doesn't work.
I'm trying to read a value that is coming from a push button and this button is connected to 5V DC cell.
When I press the button the 5V should go to the atmega32 and reads it as 1, then the if statement becomes true and the led goes on.
However, when the value becomes true the led will turn on but its not.
bit 1 is the button bit 0 is the led
Code
#define DDRA (*((volatile unsigned char *)0x3A))
#define PORTA (*((volatile unsigned char *)0x3B))
#define PINA (*((volatile unsigned char *)0x39))
int main(void) {
DDRA |= 0b00000001; // pin 0 output
while (1) {
if ((PINA&0b00000010) == 1) { // button pressed
PORTA |= 0b00000001; // turn led on
}
}
}