// Jeffery Durand // First Code for AVR! Starting from scratch to learn the details // Next version build off of this one // Good practice: specify the pin numbers and the components attached to them: // // v_01: if button pressed, led blinks every 10th of second // // Button PA3 (pin 10) // LED PA7 (pin 6) // Cristal Xtal 1 & 2 (pin 2 & 3) #include // basic library #include /* Functions to waste time */ int main (void) { /* Initialization */ DDRA = 0b10000000; // configure PA7 as output, rest of pins as input DDRA |= (1 << PA7); // equivalent : |= is like += but with | the OR op, << is bit shifting the left by the right (int) PORTA = 0b00001000; // set pull-up resistor at PA3 PORTA &= (1 << PA3); // testing the notation (nice because of manipulation possibilities) /* Event Loop */ while (1) { /* action */ if ((PINA & 0b00001000) == 0) // meaning the input on PA3 is low, so ground is connected, so button is pressed { PORTA |= (1 << PA7); // turn the LED pin on _delay_ms(10); // wait PORTA = ~((1 << PA7) | ~PORTA); // turn the led pin off _delay_ms(10); } else { PORTA = ~((1 << PA7) | ~PORTA); // turn the led pin off } } return (0); // never reached }