nRF51 Example 2 - System Clock and Delay

Please click “more” on the right!

Notes:

system_nrf51.c

System Clock Frequency:

1
#define __SYSTEM_CLOCK      (16000000UL)     /*!< nRF51 devices use a fixed System Clock Frequency of 16MHz */

Toolchain:
ARM RealView (armcc), IAR EWARM (iccarm), and GNU Compiler Collection (gcc).

1
#if defined ( __CC_ARM )//ARM RealView
    uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;  
#elif defined ( __ICCARM__ )//IAR EWARM
    __root uint32_t SystemCoreClock = __SYSTEM_CLOCK;
#elif defined   ( __GNUC__ )// GNU Compiler Collection(GCC)
    uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
#endif

My assignment

Create a function call nrf_delay_s to replace nrf_delay_ms

Part of my source files

main.c

1
int main(void)
{
	LED_Init();
	while(1)
	{
		LED_Toggle();
		nrf_delay_s(1);
	}
}

nrf_delay.c

1
void nrf_delay_ms(uint32_t volatile number_of_ms)
{
    while(number_of_ms != 0)
    {
        number_of_ms--;
        nrf_delay_us(999);
    }
}

void nrf_delay_s(uint32_t volatile number_of_s)
{
    while(number_of_s != 0)
    {
        number_of_s--;
        nrf_delay_ms(999);
    }
}

Download my files


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

文章目录
  1. 1. Notes:
  2. 2. My assignment
  3. 3. Part of my source files
    1. 3.1. main.c
    2. 3.2. nrf_delay.c
,