/* Title: interrupt.c
* Author: Corey Crawford, [email protected]
* Description: Testing interrupts on tiny85
* Created: Dec 17, 2023
* Edited: Dec 18, 2023
*
* TODO : Assess and mitigate button bounce
*
*/
// Import device headers and init program functions
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <TinyDebug.h>
void init();
// Main function
int main() {
init();
Debug.begin();
// Enters blink loop
for(;;){
// Toggle pin PB0 and wait
PORTB ^= 0x01;
Debug.print("\nloop");
_delay_ms(1000);
}
return(1);
}
// Initialization of output pins and ISR
void init(){
GIMSK &= 0b00000000; // Disables interrupts
DDRB |= 0b00000011; // Sets Ports PB0 and PB1 as outputs
SREG |= 0b10000000; // Sets global interrupt flag
MCUCR |= 0b00000010; // Sets ext interrupt for falling edge
GIMSK |= 0b01000000; // Enables interrupts
}
// Interrupt Service Routine
ISR(INT0_vect){
// Toggles output of pin PB1
PORTB ^= 0b00000010;
GIFR |= 0b01000000; // Clears interrupt flag
Debug.print(" interrupted!");
}