Comparison of library functions and register operations under STM32

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.