#include<avr/io.h>
#include<util/delay.h>
/*#define LED_PORT PORTB
#define LED_PIN ((1<<PD6)|(1<<PD7))
#define SWITCH_PORT 0X3C
#define SWITCH_PORT_C PINC*/
int main(void)
{
//Set PORT D (PD7 - PD2) and PORT C(PC3 - PC0)as input for switches
DDRD &= 0xC3; // 0xC3 binary is 11000011, setting PD7 to PD2 as inputs
DDRC &= 0x0F; // 0x0F binary is 00001111, setting PC3 to PC0 as inputs
//Set PORT B (PB0 to PB5)as output for LEDs
DDRB = 0x3F; //0x3f binary is 00111111 PB0 to PB5 as outputs
while(1)
{
//check if PD2 (switch) is pressed
if(!(PIND & (1<< PD2)))
{
//If PD2 is pressed, turn on all LEDs
PORTB = 0x3F; //Turn on PB0 to PB5
PORTD |= ((1<<PD7)|(1<<PD6)); //Turn on PD7 & PD6
}else{
//If PD2 is not pressed, turn OFF all LEDs
PORTB = 0x00;
PORTD &= ~((1<<PD7)|(1<<PD6));
}
}
return 0;
}