[Atmel] mbed环境下SAMR21开发板2:按键

[复制链接]
 楼主| ddllxxrr 发表于 2016-2-9 21:39 | 显示全部楼层 |阅读模式
本帖最后由 ddllxxrr 于 2016-2-9 21:40 编辑

今天这个程序是在昨天的基础上改的,经查SAMR21的按键在PA28

而这个定义同mbed的定义名称一模一样:


以下是mbed的管脚定义h文件:
  1. /* mbed Microcontroller Library
  2. * Copyright (c) 2006-2015 ARM Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. *     http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MBED_PINNAMES_H
  17. #define MBED_PINNAMES_H

  18. #include "cmsis.h"

  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif

  22. typedef enum {
  23.     PIN_INPUT,
  24.     PIN_OUTPUT,
  25.     PIN_INPUT_OUTPUT        //pin state can be set and read back
  26. } PinDirection;

  27. typedef enum {
  28.     PA00  = 0,
  29.     PA01  = 1,
  30.     PA04  = 4,
  31.     PA05  = 5,
  32.     PA06  = 6,
  33.     PA07  = 7,
  34.     PA08  = 8,
  35.     PA09  = 9,
  36.     PA10  = 10,
  37.     PA11  = 11,
  38.     PA12  = 12,
  39.     PA13  = 13,
  40.     PA14  = 14,
  41.     PA15  = 15,
  42.     PA16  = 16,
  43.     PA17  = 17,
  44.     PA18  = 18,
  45.     PA19  = 19,
  46.     PA20  = 20,
  47.     PA22  = 22,
  48.     PA23  = 23,
  49.     PA24  = 24,
  50.     PA25  = 25,
  51.     PA27  = 27,
  52.     PA28  = 28,
  53.     PA30  = 30,
  54.     PA31  = 31,

  55.     PB00  = 32,
  56.     PB02  = 34,
  57.     PB03  = 35,
  58.     PB08  = 40,
  59.     PB09  = 41,
  60.     PB14  = 46,
  61.     PB15  = 47,
  62.     PB16  = 48,
  63.     PB17  = 49,
  64.     PB22  = 54,
  65.     PB23  = 55,
  66.     PB30  = 62,
  67.     PB31  = 63,

  68.     PC16 = 80,
  69.     PC18 = 82,
  70.     PC19 = 83,

  71.     USBTX = PA04,
  72.     USBRX = PA05,

  73.     LED1 = PA19,
  74.     LED2 = PA19,
  75.     LED3 = PA19,
  76.     LED4 = PA19,

  77.     // Not connected
  78.     NC = (int)0xFFFFFFFF
  79. } PinName;

  80. typedef enum {
  81.     PullNone = 0,
  82.     PullUp = 1,
  83.     PullDown = 2,
  84.     PullDefault = PullUp
  85. } PinMode;

  86. #ifdef __cplusplus
  87. }
  88. #endif

  89. #endif


而我要做的就是把PA28给定义成为我自己的按键:

DigitalIn mybutton(PA28);

而其余的程序就简单了。

以下是程序截图:


以下是编译通过截图:


以下是通过Atmel Studio7.0下载BIN文件的载图:



程序成功后我验证了一下,运行正确,我一按按键灯就一直亮,我放开就开始闪


本帖子中包含更多资源

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

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

本版积分规则

个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2403

主题

6994

帖子

68

粉丝
快速回复 在线客服 返回列表 返回顶部
个人签名:http://shop34182318.taobao.com/ http://shop562064536.taobao.com

2403

主题

6994

帖子

68

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