# Intro to Embedded Systems Lecture Notes: February 7th, 2023 ## Using Interrupts ```c #define INTERRUPT_PINS 0x03 int main(void) { P4IE |= INTERRUPT_PINS; // Local interrupt enable P4IFG |= INTERRUPT_PINS; P4IES |= INTERRUPT_PINS; _enable_interrupts(); // Global interrupt enable __bis_SR_register(GIE); while (true) { ... } return 0; } // Port 4 interrupt service routine void __attribute__ ((interrupt(PORT4_VECTOR))) Port_4 (void) { ... } ``` ## Interrupt Servicing Summary 1. Interrupt Pending 2. Complete Current Instruction 3. Clear SR 4. Retrieve starting address of ISR & put address in PC 5. Execute ISR 6. Pop SR and PC from stack 7. Continue to main program ## Multiple Interrupts ### Three Types: 1. Reset Interrupt 2. Maskable Interrupt - ADC, port, timer, e_USCI - User-asserted event 3. Non-Maskable Interrupt - Fault, error detection - Oscillator fault - Flash key violation ## Priority of Interrupts 1. Timers 2. e_USCI 3. ADC 4. Port