nRF51 Example 1 - Blinky

Source Demo:
loop1

Download Link

My Demo:
loop2
Download Link

Please click “more” on the right!

Tips:

1.Configure LED-pins as outputs

nrf_gpio_cfg_output();

2.Open LED

nrf_gpio_pin_set();

3.Close LED

nrf_gpio_pin_clear();

4.Toggle LED

nrf_gpio_pin_toggle();

5.Delay with millisecond

nrf_delay_ms();

Part of my source files

main.c

1
#include <stdbool.h>
#include <stdint.h>
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "led.h"

/**
 * @brief Function for application main entry.
 */
int main(void)
{
	// Configure LED-pins as outputs
	LED_Init();
	while(true)
	{
		int i;
		for(i=17; i<=20; i++)
		{
			LED_Loop(i,250);
		}
		for(i=19; i>=16; i--)
		{
			LED_Loop(i,250);
		}
	}
}

led.h

1
#ifndef __LED_H
#define	__LED_H

#include "nrf51.h"

#define LED_START      16
#define LED_0          16
#define LED_1          17
#define LED_2          18
#define LED_3          19
#define LED_4          20
#define LED_5          21
#define LED_6          22
#define LED_7          23
#define LED_STOP       23

void LED_Init(void);
void LED_Open(int LED_X);
void LED_Close(int LED_X);
void LED_Toggle(int LED_X);
void LED_Loop(int LED_X,int sec);
#endif /* __LED_H */

led.c

1
#include "nrf51.h"
#include "nrf_gpio.h"
#include "led.h"
#include "nrf_delay.h"

void LED_Init(void)
{
	int i;
	for(i=16; i<=20; i++)
	{
		// Configure LED-pins as outputs
		nrf_gpio_cfg_output(i);
		nrf_gpio_pin_set(i);
	}
}

void LED_Open(int LED_X)
{
	nrf_gpio_pin_set(LED_X);
}

void LED_Close(int LED_X)
{
	nrf_gpio_pin_clear(LED_X);
}

void LED_Toggle(int LED_X)
{
	nrf_gpio_pin_toggle(LED_X);
}

void LED_Loop(int LED_X, int sec)
{
	nrf_gpio_pin_clear(LED_X);
	nrf_delay_ms(sec);
	nrf_gpio_pin_set(LED_X);
}

Download my files


This work is licensed under a Creative Commons Attribution 4.0 International License.

文章目录
  1. 1. Tips:
    1. 1.0.1. 1.Configure LED-pins as outputs
    2. 1.0.2. 2.Open LED
    3. 1.0.3. 3.Close LED
    4. 1.0.4. 4.Toggle LED
    5. 1.0.5. 5.Delay with millisecond
  • 2. Part of my source files
    1. 2.1. main.c
    2. 2.2. led.h
    3. 2.3. led.c
  • ,