SLEEP LED Blink Mode
This sample code guide is designed to help users easily and comprehensively understand SLEEP LED sample. In this sample, SLEEP LED is configured in blink mode.
Requirements
For hardware requirements, please refer to the Requirements.
Wiring
Connect P0_1 to LED1 and connect P2_1 to LED2 and connect P2_2 to LED3 On the EVB.
The hardware connection of SLEEP LED sample code is shown in the figure below.

SLEEP LED Sample Code Hardware Connection Diagram
Configurations
The following macros can be configured to modify pin definitions.
#define LED_OUT_0 ADC_1
#define LED_OUT_1 P2_1
#define LED_OUT_2 P2_2
The entry function is as follows, call this function in
main()
to run this sample code. For more details, please refer to the Initialization.sleep_led_blink_demo();
Building and Downloading
For building and downloading, please refer to the Building and Downloading.
Experimental Verification
Press the Reset button on the EVB board, LEDs blink with 200ms on and 100ms off.
Code Overview
This section introduces the code and process description for initialization and corresponding function implementation in the sample.
Source Code Directory
For project directory, please refer to Source Code Directory.
Source code directory:
sdk\src\sample\io_demo\led\sleep_led_demo.c
.
Initialization
The initialization flow for peripherals can refer to Initialization Flow.
The initialization flow of SLEEP LED blink mode is shown in the following figure.

SLEEP LED Blink Mode Initialization Flow Chart
Call
Pad_Config()
andPad_FunctionConfig()
to initialize the pin.static void board_led_init(void) { Pad_Config(LED_OUT_0, PAD_SW_MODE, PAD_IS_PWRON, PAD_PULL_NONE, PAD_OUT_ENABLE, PAD_OUT_HIGH); Pad_Config(LED_OUT_1, PAD_SW_MODE, PAD_IS_PWRON, PAD_PULL_NONE, PAD_OUT_ENABLE, PAD_OUT_HIGH); Pad_Config(LED_OUT_2, PAD_SW_MODE, PAD_IS_PWRON, PAD_PULL_NONE, PAD_OUT_ENABLE, PAD_OUT_HIGH); Pad_FunctionConfig(LED_OUT_0, LED0); Pad_FunctionConfig(LED_OUT_1, LED1); Pad_FunctionConfig(LED_OUT_2, LED2); }
Call
SleepLed_Reset()
to clear all SLEEP LED registers to their default reset values.Initialize the SLEEP LED peripheral:
Define the
SLEEP_LED_InitTypeDef
typeLed_Initsturcture
, and callSleepLed_StructInit()
to pre-fillLed_Initsturcture
with default values.Modify the
Led_Initsturcture
parameters as needed. The SLEEP LED initialization parameter configuration is shown in the table below.Call
SleepLed_Init()
to initialize the SLEEP LED peripheral.
SLEEP LED Initialization Parameters SLEEP LED Hardware Parameters
Setting in the
Led_Initsturcture
VariablesSLEEP LED
Clock Division Factor
32
Mode
Polarity
High Level Time
Channel0 Period0: 200 (200ms)
Channel0 Period1: 200 (200ms)
Channel0 Period2 : 200 (200ms)
Channel1 Period0: 200 (200ms)
Channel1 Period1: 200 (200ms)
Channel1 Period2 : 0 (0)
Channel2 Period0: 200 (200ms)
Channel2 Period1: 0 (0)
Channel2 Period2 : 0 (0)
Low Level Time
Channel0 Period0: 100 (100ms)
Channel0 Period1: 100 (100ms)
Channel0 Period2 : 100 (100ms)
Channel1 Period0: 100 (100ms)
Channel1 Period1: 100 (100ms)
Channel1 Period2 : 0 (0)
Channel2 Period0: 100 (100ms)
Channel2 Period1: 0 (0)
Channel2 Period2 : 0 (0)
Call
SleepLed_Cmd()
to enable SLEEP LED.