[nRF51822]1. 点亮一个LED

实现功能

使LED闪烁

硬件电路

 

 

实现原理

芯片P021引脚控制LED,高电平熄灭,低电平电量。

配置芯片引脚为输出,循环电平反转和延时。

 

代码

 

 

main.c

#include "nrf_delay.h"
#include "nrf_gpio.h"

#define LED_1    21                       /* P0.21连接LED_1 */

int main(void)
{
    nrf_gpio_cfg_output(LED_1);            //配置单个引脚模式为输出
        
    nrf_gpio_pin_set(LED_1);               //设置单个引脚输出高电平
    
    while(1)
    {
        nrf_gpio_pin_toggle(LED_1);        //设置单个引脚电平翻转
        
        nrf_delay_ms(200);                 //延时200ms(非精确延时)
    }
}

 

知识点

nRF51822芯片的引脚设置是调用SDK的API完成的。

void nrf_gpio_cfg_output(uint32_t pin_number)

  设置单个引脚为输出

 

void nrf_gpio_pin_set(uint32_t pin_number)

  设置单个引脚输出高电平

 

void nrf_gpio_pin_toggle(uint32_t pin_number)

  设置单个引脚电平翻转

 

void nrf_delay_ms(uint32_t volatile number_of_ms)

  非精确延时函数

 

posted @ 2020-10-26 12:45  doitjust  阅读(187)  评论(0编辑  收藏  举报