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

[复制链接]
776|1
 楼主| 天灵灵地灵灵 发表于 2016-9-9 10:21 | 显示全部楼层 |阅读模式
AnalogIn analog_value_01(A0);
DigitalOut led1(LED1);
一般我们看到的例程都是这样的,也就是板子上已经有的宏定义,比如这个LED1,还有这个A0,这些在开发板上都有定义了,而且专门的把A0A1这些排列在了一起的插座。
那么如果用那些赤裸裸的原始管脚呢?
经过摸索发现可以这样
DigitalOut gpioDIN(PF_12);
比如这个,作为输出顶一个gpioDIN名字的对象,使用的管脚的宏填进去是PF_12管脚。这样就行了,
后面我们就可以操作这个对象了。

 楼主| 天灵灵地灵灵 发表于 2016-9-9 10:22 | 显示全部楼层
  1. #include "mbed.h"
  2. #include "math.h"

  3. AnalogIn analog_value_01(A0);
  4. AnalogIn analog_value_02(A1);

  5. DigitalOut led1(LED1);
  6. DigitalOut led2(LED2);
  7. DigitalOut led3(LED3);

  8. DigitalOut gpioDIN(PF_12);
  9. DigitalOut gpioSCLK(PD_15);
  10. DigitalOut gpioCS(PD_14);







  11. void Write_MAX548x(int x)
  12. {
  13.     int i=0;


  14.    
  15.      gpioCS=0;
  16.     for(i=0;i<16;i++)
  17.     {
  18.         gpioSCLK=0;
  19.         
  20.      if((x<<i)&0x8000) gpioDIN=1;
  21.      else              gpioDIN=0;
  22.    
  23.        gpioSCLK=1;
  24.         
  25.     }

  26.     gpioCS=1;
  27.    
  28.    
  29.    
  30. }





  31. int main() {
  32.     float analog_01,analog_02;
  33.     float  temp1;   

  34.     printf("\nAnalogIn example\n");

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

  37.     while(1) {
  38.         analog_01 = analog_value_01.read(); // Converts and read the analog input value (value from 0.0 to 1.0)   
  39.         analog_01 = analog_01 * 3300; // Change the value to be in the 0 to 3300 range
  40.         
  41.         analog_02 = analog_value_02.read(); // Converts and read the analog input value (value from 0.0 to 1.0)  
  42.         analog_02 = analog_02 * 3300; // Change the value to be in the 0 to 3300 range
  43.         
  44.    if(abs(temp1-analog_01)>5)
  45.         printf("A0 = %.0f mV\n", analog_01);
  46.         
  47.         printf("A1 = %.0f mV\n", analog_02);
  48.                
  49.      temp1=analog_01;
  50.       if(analog_01>825)  led1 = 1;
  51.       if(analog_01>1650) led2 = 1;
  52.       if(analog_01>2475) led3 = 1;

  53.       if(analog_01<2475) led3 = 0;      
  54.       if(analog_01<1650) led2 = 0;
  55.       if(analog_01<825)  led1 = 0;     
  56.    
  57.         wait(0.2); // 200 ms
  58.         
  59.             Write_MAX548x(0x0120);

  60.     }
  61. }


您需要登录后才可以回帖 登录 | 注册

本版积分规则

183

主题

3475

帖子

13

粉丝
快速回复 在线客服 返回列表 返回顶部