Esempio di latenza di un Interrupt

Dependencies:   mbed

Committer:
Mattinico
Date:
Sun Nov 06 12:39:18 2016 +0000
Revision:
0:046cbaef2d68
k;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Mattinico 0:046cbaef2d68 1 /* Program Example 2: Tests interrupt latency. External input causes interrupt, which
Mattinico 0:046cbaef2d68 2 pulses external LED.
Mattinico 0:046cbaef2d68 3 */
Mattinico 0:046cbaef2d68 4 #include "mbed.h"
Mattinico 0:046cbaef2d68 5 InterruptIn squarewave(D2); //Connect input square wave here
Mattinico 0:046cbaef2d68 6 DigitalOut out(D3);
Mattinico 0:046cbaef2d68 7 DigitalOut out2(D4);
Mattinico 0:046cbaef2d68 8 void pulse() //ISR sets external led high for fixed duration
Mattinico 0:046cbaef2d68 9 {
Mattinico 0:046cbaef2d68 10 out = 1;
Mattinico 0:046cbaef2d68 11 wait_us(50);
Mattinico 0:046cbaef2d68 12 out = 0;
Mattinico 0:046cbaef2d68 13 }
Mattinico 0:046cbaef2d68 14 int main()
Mattinico 0:046cbaef2d68 15 {
Mattinico 0:046cbaef2d68 16 squarewave.rise(&pulse); // attach the address of the pulse function to
Mattinico 0:046cbaef2d68 17 // the rising edge
Mattinico 0:046cbaef2d68 18 while(1) { // interrupt will occur within this endless loop
Mattinico 0:046cbaef2d68 19 Out2=!out2;
Mattinico 0:046cbaef2d68 20 wait_ms(25);
Mattinico 0:046cbaef2d68 21 }
Mattinico 0:046cbaef2d68 22 }