Examples of flashled functions in flashing LEDs:
Library functions are simple to operate, but not as efficient as register operations, and register operations are complex because they are familiar with hundreds of registers, but the program is highly efficient.
/** below is the implementation of IO control by direct manipulation of library functions **/while (1) {gpio_resetbits (gpiob,gpio_pin_9); LED0 corresponding pin gpiof.9 pull low, bright equivalent to led0=0; Gpio_setbits (gpiob,gpio_pin_10); LED1 corresponding pin gpiof.10 pull high, off the equivalent of Led1=1;delay_ms (a); Delay 300msgpio_setbits (gpiob,gpio_pin_9); LED0 corresponding pin gpiof.0 pull high, eliminate the equivalent of led0=1; Gpio_resetbits (GPIOB,GPIO_PIN_10); LED1 corresponding pin gpiof.10 pull low, bright equivalent to Led1=0;delay_ms (a); Delay 300MS}
/********************* The code that is commented out below is the IO port control via the bit band Operation **************************************/int Main (void) { Delay_ Init (168); Initialize the delay function led_init (); Initialize the LED port while (1) { led0=0; LED0 Bright led1=1;//led1 extinguish Delay_ms (500); Led0=1;//led0 Led1=0;//led1 Liang Delay_ms (500); }}/************************************************************************************************** **//****** The following commented out code is the direct operation of the register to implement the IO port control **************************************/int main (void) { delay_init (168); Initialize the delay function led_init (); Initialize the LED port while (1) { gpiof->bsrrh=gpio_pin_9;//led0 bright gpiof->bsrrl=gpio_pin_10;//led1 off Delay_ms ( ); Gpiof->bsrrl=gpio_pin_9;//led0 gpiof->bsrrh=gpio_pin_10;//led1 Bright Delay_ms (500);}} /****************************************************************************************************/
/* I want to say I prefer this, hehe * /while (1) { //flashled (); * (unsigned int*) (0x40010c0c) |=0x200;d Elay_ms (100); * (unsigned int*) (0x40010c0c) &=0XFFFFFDFF;d Elay_ms (100);
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Comparison of library functions and register operations under STM32