您的位置:首页 > 其它

.net micro framework的入门例程-点灯神话-3.按键中断控制LED

2014-05-02 18:03 429 查看
稍微学习一下如何添加中断服务程序。

IO双沿触发中断。

using System;

using System.Threading;

using Microsoft.SPOT;

using Microsoft.SPOT.Hardware;

using GHIElectronics.Gadgeteer;

namespace my_LED

{

public class my_led

{

static OutputPort lampOutport = new OutputPort((Cpu.Pin)

GHI.Hardware.G120.Pin.P1_15,true);

static InterruptPort switchInterrupt = new InterruptPort(

(Cpu.Pin)GHI.Hardware.G120.Pin.P2_10,

false,

Port.ResistorMode.PullUp,

Port.InterruptMode.InterruptEdgeBoth);

public static void Main()

{

switchInterrupt.OnInterrupt += new NativeEventHandler

(switchInterrupt_OnInterrupt);

while (true)

{

System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);

}

}

static void switchInterrupt_OnInterrupt(uint data1, uint data2, DateTime time)

{

switch (data2)

{

case 0: lampOutport.Write(false); break;

case 1: lampOutport.Write(true); break;

default: break;

}

//throw new NotImplementedException();

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: