现在的位置: 首页 > 综合 > 正文

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

2013年06月21日 ⁄ 综合 ⁄ 共 3051字 ⁄ 字号 评论关闭

      目前针对.Net Micro Framework无论是开发GPIOSPII2C,还是串口通信都离不开硬件,前段时间我扩展了官方的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、启动后的模拟器

 

 

 

二、应用开发示例

   1GPIO测试

模拟器中相关GPIOPIN值如下:

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()

        {

            //叶帆模拟器GPIOpin定义

            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"));

        }

    }

}

 

 

 

 

测试结果:

 

 

  2SPI测试

模拟器中相关SPIPIN值如下:

PIN=30

完整的测试代码如下:

using System;

using Microsoft.SPOT;

using Microsoft.SPOT.Hardware;

using System.Threading;

 

namespace SPITest

{

    public class Program

    {

        static SPI _spi;

        static int QAW = 0;

        public static void Main()

        {

            //SPIpin定义

            _spi = new SPI(new SPI.Configuration((Cpu.Pin)30, true, 0, 0, false, false, 4000, SPI.SPI_module.SPI1));

 

            while (true)

            {

                SPITest();

                Thread.Sleep(200);

            }

        }

 

        //读写SPI数据

        private static Int16 SPIReadWrite(Int16 value)

        {

            byte[] bout = new byte[2];

            byte[] bin = new byte[2];

抱歉!评论已关闭.