1
votes

I need to modify the code in this picture so that the LED I have connected to bit 7 of PORT D blinks only when both the switches are on. I have a switch connected to bit 5 of PORT D as well. This is where the on-board LED is for my arduino. I am totally stuck. AVR C Program

1
the question is a bit confusing... you haven't explained whats connected to port b, and you seem to imply that you have 2 switches... but only mention the 1 connected to bit 5 of PORT DScott Morken
also you appear to have set all bits of PORT B to outputs, is this just more LEDs?Scott Morken
Change if(x&0b00010000) (pin 4 only) to if(x&0b00010000 && x&0b0010000) (pins 4 and 5 both on).uncleO

1 Answers

0
votes

I assume your led is on D.7 and switch on (active low) D.4 and D.5 (i dont know why PORT B mentioned on your code.

unsigned char x;
 int main(void)
 DDRD = 0b10000000;
 PORTD = 0b00110000; //activate internal pull just in case
 x=PIND;
 x&=0b00110000; // just in case (again)
 if (x&0b00110000)
  {
   PORTD = 0b11000000; //blinks
   _delay_ms (500);
   PORTD = 0b00000000; //blinks
   _delay_ms (500);
  }
 }