打印
[STM32F4]

在MBED中如何使用开发板上没有定义的管脚

[复制链接]
681|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
AnalogIn analog_value_01(A0);
DigitalOut led1(LED1);
一般我们看到的例程都是这样的,也就是板子上已经有的宏定义,比如这个LED1,还有这个A0,这些在开发板上都有定义了,而且专门的把A0A1这些排列在了一起的插座。
那么如果用那些赤裸裸的原始管脚呢?
经过摸索发现可以这样
DigitalOut gpioDIN(PF_12);
比如这个,作为输出顶一个gpioDIN名字的对象,使用的管脚的宏填进去是PF_12管脚。这样就行了,
后面我们就可以操作这个对象了。

沙发
天灵灵地灵灵|  楼主 | 2016-9-9 10:22 | 只看该作者
#include "mbed.h"
#include "math.h"

AnalogIn analog_value_01(A0);
AnalogIn analog_value_02(A1);

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);

DigitalOut gpioDIN(PF_12);
DigitalOut gpioSCLK(PD_15);
DigitalOut gpioCS(PD_14);







void Write_MAX548x(int x)
{
    int i=0;


   
     gpioCS=0;
    for(i=0;i<16;i++)
    {
        gpioSCLK=0;
        
     if((x<<i)&0x8000) gpioDIN=1;
     else              gpioDIN=0;
   
       gpioSCLK=1;
        
    }

    gpioCS=1;
   
   
   
}





int main() {
    float analog_01,analog_02;
    float  temp1;   

    printf("\nAnalogIn example\n");

    printf("\nA0 is Analog channel \n");   
    printf("\nA1 is Digital channel \n");   

    while(1) {
        analog_01 = analog_value_01.read(); // Converts and read the analog input value (value from 0.0 to 1.0)   
        analog_01 = analog_01 * 3300; // Change the value to be in the 0 to 3300 range
        
        analog_02 = analog_value_02.read(); // Converts and read the analog input value (value from 0.0 to 1.0)  
        analog_02 = analog_02 * 3300; // Change the value to be in the 0 to 3300 range
        
   if(abs(temp1-analog_01)>5)
        printf("A0 = %.0f mV\n", analog_01);
        
        printf("A1 = %.0f mV\n", analog_02);
               
     temp1=analog_01;
      if(analog_01>825)  led1 = 1;
      if(analog_01>1650) led2 = 1;
      if(analog_01>2475) led3 = 1;

      if(analog_01<2475) led3 = 0;      
      if(analog_01<1650) led2 = 0;
      if(analog_01<825)  led1 = 0;     
   
        wait(0.2); // 200 ms
        
            Write_MAX548x(0x0120);

    }
}


使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

167

主题

3345

帖子

13

粉丝