[MCU] 【MSP432评测】 -- 1、搭建环境并驱动LED指示灯

[复制链接]
1358|13
 楼主| tlled 发表于 2020-4-16 23:22 | 显示全部楼层 |阅读模式
本帖最后由 tlled 于 2020-4-16 23:23 编辑

   
    一、搭建环境

    MSP432P401R支持 CCS、KEIL和IAR开发环境,这里我选择KEIL开发环境。

    1.1、首先下载MSP432P401R开发板的软件SDK包   SDK包链接
   

    1.2、安装SDK包后,就可以使用里面的工程文件了。里面有几种编译环境的工程,我这里选择KEIL工程文件。   
    1.3、打开工程文件后,编译程序,看是否有报错
   
    编译成功,没有报错,KEIL开发环境正常使用。

    二、GPIO 驱动LED灯

    2.1、LED硬件电路
     使用了GPIO的P1.0和P2.0,P2.1,P2.2
   

    2.2、程序
    根据SDK的工程文件,截取自己的项目工程文件,并编写驱动程序。
    主要的程序如下:

    2.2.1、led.c
  1. #include "config.h"

  2. void LED_Init(void)
  3. {
  4.         GPIO_setAsOutputPin( GPIO_PORT_P1, GPIO_PIN0 );                //P1.0
  5.         GPIO_setAsOutputPin( GPIO_PORT_P2, GPIO_PIN0 );                //P2.0
  6.         GPIO_setAsOutputPin( GPIO_PORT_P2, GPIO_PIN1 );                //P2.1
  7.         GPIO_setAsOutputPin( GPIO_PORT_P2, GPIO_PIN2 );                //P2.2
  8.         
  9.         led2_r_off();
  10.         led2_g_off();
  11.         led2_b_off();
  12. }

    2.2.2、led.h
  1. #ifndef LED_H_
  2. #define LED_H_


  3. #define led1_off()         GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0)
  4. #define led1_on()        GPIO_setOutputHighOnPin(GPIO_PORT_P1, GPIO_PIN0)
  5. #define led1_tog()        GPIO_toggleOutputOnPin( GPIO_PORT_P1, GPIO_PIN0 )

  6. #define led2_r_off()         GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0)
  7. #define led2_r_on()        GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN0)
  8. #define led2_r_tog()        GPIO_toggleOutputOnPin( GPIO_PORT_P2, GPIO_PIN0 )

  9. #define led2_g_off()         GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN1)
  10. #define led2_g_on()        GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN1)
  11. #define led2_g_tog()        GPIO_toggleOutputOnPin( GPIO_PORT_P2, GPIO_PIN1 )

  12. #define led2_b_off()         GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN2)
  13. #define led2_b_on()        GPIO_setOutputHighOnPin(GPIO_PORT_P2, GPIO_PIN2)
  14. #define led2_b_tog()        GPIO_toggleOutputOnPin( GPIO_PORT_P2, GPIO_PIN2 )

  15. void LED_Init(void);

  16. #endif


    2.2.3、main.c

  1. #include "config.h"
  2. int main(void)
  3. {
  4.     uint32_t i;

  5.     // Stop watchdog timer
  6.     WDT_A_hold(WDT_A_BASE);
  7.                 LED_Init();
  8.     while(1)
  9.     {
  10.                                 led1_on();
  11.                                 for(i=100000; i>0; i--);
  12.                                 led1_off();
  13.         for(i=100000; i>0; i--);
  14.                                 
  15.                                 led2_r_on();
  16.                                 for(i=100000; i>0; i--);
  17.                                 led2_r_off();
  18.         for(i=100000; i>0; i--);
  19.                         
  20.                                 led2_g_on();
  21.                                 for(i=100000; i>0; i--);
  22.                                 led2_g_off();
  23.         for(i=100000; i>0; i--);
  24.                         
  25.                                 led2_b_on();
  26.                                 for(i=100000; i>0; i--);
  27.                                 led2_b_off();
  28.         for(i=100000; i>0; i--);
  29.                                 
  30.     }
  31. }

    2.3、工程文件   

   三、程序执行结果

    led1和led2指示灯顺序点亮。

   



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
Cjy_JDxy 发表于 2020-4-17 22:01 | 显示全部楼层
我把库弄错了,我说怎么这么费劲。应该是P4,我搞成E4了。妈的
mcu430 发表于 2020-4-19 23:33 | 显示全部楼层
支持  好东西
quickman 发表于 2020-4-20 22:40 | 显示全部楼层
        
jstgotodo 发表于 2020-4-20 22:40 | 显示全部楼层
给力的设计呢。     
iamaiqiyi 发表于 2020-4-20 22:40 | 显示全部楼层
支持 CCS、KEIL和IAR这么多   
dzfansman 发表于 2020-4-20 22:41 | 显示全部楼层
高性能 和低功耗     
sanxingnote7 发表于 2020-4-20 22:41 | 显示全部楼层
         
backlugin 发表于 2020-4-20 22:41 | 显示全部楼层
launchpad MSP432P401  
sdCAD 发表于 2020-4-20 22:41 | 显示全部楼层
MSP432是TI的MSP430家族新增加的32位产品系列  
fengm 发表于 2020-4-20 22:41 | 显示全部楼层
感谢楼主分享的资料。   
sanfuzi 发表于 2020-4-20 22:42 | 显示全部楼层
基于ARM Cortex-M4F内核的新型32位处理器系列。
10299823 发表于 2020-4-20 22:42 | 显示全部楼层
MSP432 系列 MCU 属于低功耗
sanxingnote7 发表于 2020-4-20 22:42 | 显示全部楼层
-MSP432英文手册有吗   
您需要登录后才可以回帖 登录 | 注册

本版积分规则

132

主题

701

帖子

7

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