#include #include #include /*Macros definition*/ #define BIT(x) (1 << (x)) //Set a particular bit mask #define CHECKBIT(x,b) x&b //Checks bit status #define SETBIT(x,b) x|=b; //Sets the particular bit #define CLEARBIT(x,b) x&=~b; //Sets the particular bit #define TOGGLEBIT(x,b) x^=b; //Toggles the particular bit int main(void) { // DDR = Data Direction Register // Register Pins: 0 = input, 1 = output SETBIT(DDRA,BIT(7)) //Sets Direction of 7th pin of port A as output // Coding attempts // LOW is pressed button, HIGH is not pressed button // Clear just in case, I guess? CLEARBIT(DDRA,BIT(3)) //Sets direction of button as input while(1) { // Will just blink the LED /*SETBIT(PORTA,BIT(7)) //Sets PORTA7 as high i.e. turn on led _delay_ms(100); CLEARBIT(PORTA,BIT(7)) //Clears PORTA7(PA7 pin goes low) i.e turn off led _delay_ms(100);*/ // Turn on LED when button pressed if (CHECKBIT(PINA,BIT(3))) { CLEARBIT(PORTA,BIT(7)) } else { SETBIT(PORTA,BIT(7)) } } return 0; }