0
votes

I have the folloving code:

#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>

int main(void) {
    DDRB = 0xFF;//B output
    DDRD = 0x00;//D input
    PORTB = 0x00;//LED off
    PORTD = 0xFF;//Pull-ups activated
    while(1) {
    if(PIND.4==0) {
        PORTB &= ~(1<<PB0); /* LED on */
        _delay_ms(100);
        PORTB |= 1<<PB0; /* LED off */
        _delay_ms(100);
    }}
    return 0;
}

However, when trying to build it in Atmel Studio it gives an error:

Error   1   expected ')' before numeric constant

The line number refers to the line if(PIND.4==0) { If I remove the point between 'PIND' and '4' it builds but the program won't work. What am I doing wrong?

1

1 Answers

1
votes

The PIND.4 style of register access might not be defined in your particular ioXXXX.h file.

An easy replacement is

if(PIND & (1<<4) == 0) {