.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();
}
}
}
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();
}
}
}
相关文章推荐
- C语言SOCKET获取本机所有IP
- Windows下notepad++配置java编译环境
- C# 之 枚举与结构
- C语言使用socket通过IP138获取外网IP
- 使用隐式转换auto_ptr导致程序崩溃原因
- 【C++】1.1 VS中关于工程的使用
- .net micro framework的入门例程-点灯神话-2.按键控制LED灯
- Decode Ways
- CATransform3D参数的意义
- .net micro framework的入门例程-点灯神话-1.神灯自闪
- Json文件的加载 和 按钮的消息相应
- Oracle中sql语句循环插入
- @synchronized(self)的用法
- 路由中的shells / CLI
- Java将一个正整数分解质因数
- 15 Essential Compilers and IDEs for C/C++ Programmers
- 硬链接与软链接
- Getting help as XML
- OpenGL编程轻松入门之显示例表
- mongodb学习流水笔记