.net micro framework 에 InterruptPort 클래스가 있는데 이것을 이용해서 인터럽트를 처리한다. 이 클래스는 Microsoft.SPOT.Hardware 네임스페이스에 있으며 레퍼런스는 아래와 같다.



먼저 생성자를 살펴보면


     public InterruptPort

     (

          Cpu.Pin portId,                   // (1)핀을 지정한다.

          bool glitchFilter,                  // (2)debouncing 필터 관련 지정인 듯

          Port.ResistorMode resistor, // (3)Disabled/PullDown/PullUp 저항을 연결할 것인가

          Port.InterruptMode interrupt // (4)인터럽트 발생 시점 지정

     )


  여기서 (2)번 항의 글리치는 물리적인 버튼을 연결했을 경우 접점이 떨어지거나 붙는 순간에 발생하는 노이즈(bounce 라고도 한다)인데 이 잡음으로 인해서 의도하지 않게 인터럽트가 여러 번 발생될 수도 있다. 하드웨어 회로적으로 이러한 잡음을 제거할 수도 있고 여기에서 처럼 소프트웨어로 필터링을 하도록 설정할 수 있다. (4)번 항에서는 인터럽트 발생시점을 지정하는데 다음과 같으며 이름으로 충분히 무슨 의미인지 예상할 수 있다.


  • InterruptNone
  • InterruptEdgeLow
  • InterruptEdgeHigh
  • InterruptEdgeBoth
  • InterruptEdgeLevelHigh
  • InterruptEdgeLevelLow


프로퍼티는 다음과 같은 것들이 있고 생성자에서 지정했던 옵션들을 읽거나 변경할 수 있다.


  • Id (get)
  • Interrupt (get/set)
  • Resistor (get/set)
  • GlitchFilter (get/set)


메쏘드는 하나인데 이것에 += 연산자를 이용하여 이벤트 처리 함수를 지정하면 된다.


  • OnInterrupt


예제프로그램은 다음과 같다.


----------------------------------------------------------------------------


using System;

using System.Threading;

using Microsoft.SPOT;

using Microsoft.SPOT.Hardware;

namespace InterruptPortApplication

{

     public class Program

     {

          public static void Main()

          { 

               InterruptPort button = new InterruptPort(Cpu.Pin.GPIO_Pin3, true,                                    Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLow);

               OnInterrupt += new GPIOInterruptEventHandler(button_OnInterrupt);

                while (true)

               { // The main thread can now essentially sleep // forever. 

                    Thread.Sleep(60 * 1000);

                    Debug.Print("House Keeping Ping...");

               }

          }

          

          static void button_OnInterrupt(Cpu.Pin port, bool state, TimeSpan time)

          {

               Debug.Print("The button is pressed");

          }

     }

}

----------------------------------------------------------------------------


Posted by 살레시오
,