// Nicole Wang [MAS.863.12] // 10.23.12 // From Jeremy Scott + Neil Gershenfeld // LED Button Blink Program #include // #define F_CPU 1e6 // Defined in Makefile. #include #include #define TRUE 1 #define FALSE 0 int main() { // Set clock divider to /1. // Lines 15-16 are from Neil's hello.ftdi.44.echo.c code. // CLKPR = (1 << CLKPCE); CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0); // Button = PA7. // Green LED = PA2; red LED = PA3. PORTA |= _BV(PA7); // Turn button pull-up resistor on. DDRA |= _BV(PA2); // Enables output on the green LED pin. PORTA |= _BV(PA2); // Turns green LED on. DDRA |= _BV(PA3); // Enables output on the red LED pin. PORTA |= _BV(PA3); // Turns red LED on. int count = 0; // LOOP while (TRUE) { // If the button is not pushed: if ((PINA & _BV(PA7))) { PORTA &= ~_BV(PA2); // Turns green LED off. PORTA &= ~_BV(PA3); // Turns red LED off. // Else turn the LED on: } else { PORTA |= _BV(PA2); _delay_ms(500); PORTA &= ~_BV(PA2); _delay_ms(1000); count++; int i; for (i = 1; i <= count; i++) { if (i%2 == 0) { PORTA |= _BV(PA2); _delay_ms(250); PORTA &= ~_BV(PA2); _delay_ms(250); } else { PORTA |= _BV(PA3); _delay_ms(250); PORTA &= ~_BV(PA3); _delay_ms(250); } } if (count>=4) { count = 0; } } } }