Bluetooth Low-Power BLE: Controls GPIO to light LEDs and blegpio
This section describes the simplest and most basic things. The ios operation of the CC2540 uses the PORT as the GPIO. If you don't talk much about it, let's look at it.
1. Hardware Circuit
The most simple hardware circuit is to use a GPIO to control the LED light. Since GPIO is used as the output, the GPIO mode is not required.
It is quite simple to control the GPIO on the left to switch the LED lights.
2. Related registers
P0SEL |
P0 [] registers, which are set as common I/O ports by default |
P0indium |
P0 [] can be used as the circuit mode register when the input port is used as the input port. |
P0 |
P0 [] I/O registers addressable |
P0DIR |
P0 port input and output settings register |
P0SEL 0: Common IO port 1: second function
P0DIR 0: Input 1: Output
P0indium 0: Pull up/pull down 1: three States
3. Code Implementation
Let's take P1_0 as an example to see how it is implemented in the code.
HalLedInit function in hal_led.c:
void HalLedInit (void){#if (HAL_LED == TRUE) HalLedSet(HAL_LED_ALL, HAL_LED_MODE_OFF); // Initialize all LEDs to OFF. // Set LED GPIOs to outputs. LED1_DDR |= LED1_BV;#if (!defined HAL_PA_LNA && !defined HAL_PA_LNA_CC2590) LED2_DDR |= LED2_BV;#if (!defined CC2540_MINIDK && !defined HAL_BOARD_CC2540USB) LED3_DDR |= LED3_BV;#endif#endif#if defined BLINK_LEDS HalLedStatusControl.sleepActive = FALSE; // Initialize sleepActive to FALSE.#endif#endif
Macro definition
/* 1 - Green */#define LED1_BV BV(0)#define LED1_SBIT P1_0#define LED1_DDR P1DIR#define LED1_POLARITY ACTIVE_HIG
Switch LED
#define HAL_TURN_OFF_LED1() st( LED1_SBIT = LED1_POLARITY (0); ) #define HAL_TURN_OFF_LED2() st( LED2_SBIT = LED2_POLARITY (0); ) #define HAL_TURN_OFF_LED3() st( LED3_SBIT = LED3_POLARITY (0); ) #define HAL_TURN_OFF_LED4() HAL_TURN_OFF_LED1() #define HAL_TURN_ON_LED1() st( LED1_SBIT = LED1_POLARITY (1); ) #define HAL_TURN_ON_LED2() st( LED2_SBIT = LED2_POLARITY (1); ) #define HAL_TURN_ON_LED3() st( LED3_SBIT = LED3_POLARITY (1); ) #define HAL_TURN_ON_LED4() HAL_TURN_ON_LED1(
Extract the key code:
1) set P1_0 to output
P1_DIR |= 0x01;
2) Set P1_0 to a high level to light the LED
P1_0 = 1;
2) Set P1_0 to low and turn off the LED
P1_0 = 0;
In fact, it is not difficult to look at the HAL encapsulation for each interface in the protocol stack.
This section is here first.
What can sayang do with 226 sex? Which one is better than AMD's sempron 2200 +?
Playing games is of course AMD's good, but multimedia is a better game player.