Simple Interrupt example

Dependencies:   mbed

Committer:
Kit1
Date:
Thu Aug 29 17:49:47 2013 +0000
Revision:
0:5163e0741765
Interrupt example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kit1 0:5163e0741765 1 /* Program 10: Simple interrupt example. External input causes interrupt, while led flashes */
Kit1 0:5163e0741765 2 #include "mbed.h"
Kit1 0:5163e0741765 3
Kit1 0:5163e0741765 4 InterruptIn button(p5); //define and name the interrupt input
Kit1 0:5163e0741765 5 DigitalOut led(LED1);
Kit1 0:5163e0741765 6 DigitalOut flash(LED4);
Kit1 0:5163e0741765 7
Kit1 0:5163e0741765 8 void ISR1() { //this is the response to interrupt, i.e. the ISR
Kit1 0:5163e0741765 9 led = !led;
Kit1 0:5163e0741765 10 }
Kit1 0:5163e0741765 11
Kit1 0:5163e0741765 12 int main() {
Kit1 0:5163e0741765 13 button.rise(&ISR1); // attach the address of the ISR function to the
Kit1 0:5163e0741765 14 // interrupt rising edge
Kit1 0:5163e0741765 15 while(1) { // continuous loop, ready to be interrupted
Kit1 0:5163e0741765 16 flash = !flash;
Kit1 0:5163e0741765 17 /* if(flash=1)
Kit1 0:5163e0741765 18 __disable_irq(); //disable interrupts
Kit1 0:5163e0741765 19 else
Kit1 0:5163e0741765 20 __enable_irq(); //enable interrupts */
Kit1 0:5163e0741765 21 wait(1);
Kit1 0:5163e0741765 22 }
Kit1 0:5163e0741765 23 }