技术开发 频道

用模拟器零成本体验MF开发

 【It168技术文档】目前针对.Net Micro Framework无论是开发GPIO、SPI、I2C,还是串口通信都离不开硬件,前段时间我扩展了官方的MF模拟器,可以不用硬件,零成本的体验上述技术开发。

 要体验MF开发,必须具备如下条件:

  PC机上已安装VS2005;

  从http://msdn.microsoft.com/zh-cn/embedded/bb267253(en-us).aspx下载并安装MF 2.5 SDK;

  从http://www.sky-walker.com.cn/MFEmulator_SDK.rar下载模拟器及PPT文档;

  根据说明,在本机上注册该模拟器;

 一、模拟器的使用

 1、模拟器下载

 从http://www.sky-walker.com.cn/MFEmulator_SDK.rar下载模拟器。

 2、模拟器注册

 压缩包“YFMF模拟器”目录中有一个YFEmulatorReg.exe文件,运行该文件,并选择打开模拟器文件,完成注册。

 3、模拟器配置

 新建一个MF工程,打开该工程的属性页,在Micro Framework选项中,设定我们扩展的模拟器。

 4、启动后的模拟器

 二、应用开发示例

 1、GPIO测试

 模拟器中相关GPIO的PIN值如下:

 I0~I7    :Pin=10~17

 Q9~Q7 :Pin=20~27

 完整的测试代码如下:

 

 using System;

 using Microsoft.SPOT;

 using Microsoft.SPOT.Hardware;

 using System.Threading;

 namespace GPIOTest

 {

 public class Program

 {

 static OutputPort[] output = new OutputPort[8];

 static InputPort[] input = new InputPort[8];

 public static void Main()

 {

 //叶帆模拟器GPIO的pin定义

 Cpu.Pin[] pin_I = new Cpu.Pin[8] { (Cpu.Pin)10, (Cpu.Pin)11, (Cpu.Pin)12, (Cpu.Pin)13, (Cpu.Pin)14, (Cpu.Pin)15, (Cpu.Pin)16, (Cpu.Pin)17 };

 Cpu.Pin[] pin_Q = new Cpu.Pin[8] { (Cpu.Pin)20, (Cpu.Pin)21, (Cpu.Pin)22, (Cpu.Pin)23, (Cpu.Pin)24, (Cpu.Pin)25, (Cpu.Pin)26, (Cpu.Pin)27 };

 //GPIO

 for (int i = 0; i < 8; i++)

 {

 input[i] = new InputPort(pin_I[i], false, Port.ResistorMode.PullDown);

 output[i] = new OutputPort(pin_Q[i], false);

 }

 int Index = 0;

 while (true)

 {

 GPIOTest(ref Index);

 Thread.Sleep(200);

 }

 }

 //GPIO测试

 public static void GPIOTest(ref int Index)

 {

 output[Index].Write(!output[Index].Read());

 if (++Index > 7) Index = 0;

 string strPace = "   ";

 Debug.Print("Input : I0 I1 I2 I3 I4 I5 I6 I7");

 Debug.Print("        "+(input[0].Read() ? "1" : "0") + strPace + (input[1].Read() ? "1" : "0") + strPace + (input[2].Read() ? "1" : "0") + strPace + (input[3].Read() ? "1" : "0") + strPace + (input[4].Read() ? "1" : "0") + strPace + (input[5].Read() ? "1" : "0") + strPace + (input[6].Read() ? "1" : "0") + strPace + (input[7].Read() ? "1" : "0"));

 Debug.Print("Output: Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7");

 Debug.Print("        " + (output[0].Read() ? "1" : "0") + strPace + (output[1].Read() ? "1" : "0") + strPace + (output[2].Read() ? "1" : "0") + strPace + (output[3].Read() ? "1" : "0") + strPace + (output[4].Read() ? "1" : "0") + strPace + (output[5].Read() ? "1" : "0") + strPace + (output[6].Read() ? "1" : "0") + strPace + (output[7].Read() ? "1" : "0"));

 }

 }

 }

 测试结果:

 

0
相关文章