一、硬體連接配接
按鍵名稱 | 引腳 | 控制方法 |
---|---|---|
蜂鳴器 | 14 | 高電平響、低電平停 |
LED燈 | 23 | 高電平亮、低電平滅 |
二、移植檔案
注意:以下出現缺失common.h檔案錯誤,去除即可。uint8改為uint8_t或unsigned char或自己宏定義
連結:https://pan.baidu.com/s/1cGrkf-KvlWZHsutpHCBecA 提取碼:osrg
将 board_gpo.c 和 board_gpo.h 兩個檔案加入工程的Application檔案夾下
2.1 board_gpo.c
/*********************************************************************
* INCLUDES
*/
#include "nrf_gpio.h"
#include "board_gpo.h"
#include "common.h"
/*********************************************************************
* PUBLIC FUNCTIONS
*/
/**
@brief 蜂鳴器驅動初始化
@param 無
@return 無
*/
void Board_BeepInit(void)
{
nrf_gpio_cfg_output(BOARD_BEEP_IO);
Board_BeepSet(BEEP_OFF);
}
/**
@brief 配置蜂鳴器工作模式
@param beepMode -[in] 工作模式
@return 無
*/
void Board_BeepSet(uint8 beepMode)
{
switch(beepMode) // 執行模式
{
case BEEP_OFF: // 蜂鳴器不響模式
nrf_gpio_pin_write(BOARD_BEEP_IO, 0);
break;
case BEEP_ON: // 蜂鳴器響模式
nrf_gpio_pin_write(BOARD_BEEP_IO, 1);
break;
default:
break;
}
}
/**
@brief LED燈驅動初始化
@param 無
@return 無
*/
void Board_LedInit(void)
{
nrf_gpio_cfg_output(BOARD_LED_IO);
Board_LedSet(LED_OFF);
}
/**
@brief 配置LED燈工作模式
@param ledMode -[in] 工作模式
@return 無
*/
void Board_LedSet(uint8 ledMode)
{
switch(ledMode) // 執行模式
{
case LED_OFF: // LED滅模式
nrf_gpio_pin_write(BOARD_LED_IO, 0);
break;
case LED_ON: // LED亮模式
nrf_gpio_pin_write(BOARD_LED_IO, 1);
break;
default:
break;
}
}
/****************************************************END OF FILE****************************************************/
2.2 board_gpo.h
#ifndef _BOARD_GPO_H_
#define _BOARD_GPO_H_
/*********************************************************************
* INCLUDES
*/
#include "common.h"
/*********************************************************************
* DEFINITIONS
*/
#define BOARD_BEEP_IO 14
#define BOARD_LED_IO 23
#define BEEP_OFF 0x00
#define BEEP_ON 0x01
#define LED_OFF 0x00
#define LED_ON 0x01
/*********************************************************************
* API FUNCTIONS
*/
void Board_BeepInit(void);
void Board_BeepSet(uint8 beepMode);
void Board_LedInit(void);
void Board_LedSet(uint8 ledMode);
#endif /* _BOARD_GPO_H_ */
三、API調用
需包含頭檔案 board_gpo.h
Board_BeepSet
功能 | 配置蜂鳴器工作模式 |
---|---|
函數定義 | void Board_BeepSet(uint8 beepMode) |
參數 | beepMode 工作模式(BEEP_ON或BEEP_OFF) |
傳回 | 無 |
Board_LedSet
功能 | 配置LED燈工作模式 |
---|---|
函數定義 | void Board_LedSet(uint8 ledMode) |
參數 | beepMode 工作模式(LED_ON或LED_OFF) |
傳回 | 無 |
• 由 Leung 寫于 2019 年 12 月 20 日
• 參考:青風電子社群