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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#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.