Light up led (library function implementation)

Source: Internet
Author: User

The chip used in this test is stm32f103cb.

My Development Board is as follows:

This development board has 8 LEDs, including D11, D12, D13, D14, d15, D16, d17, and d18. After querying the circuit diagram of the core board, we know that the control pins of the corresponding chip are p0.0, p0.1, listen 2, listen 3, listen 4, Listen 5, listen 6, listen 7, and then 8.

Now test to light up D11. The main source code is as follows:

1 //main.c2 #include "pbdata.h"3 #include "led.h"4 5 int main(void)6 {7         led_init();8         led_setBit();9 }
1 //pbdata.h2 #ifndef _pbdata_H3 #define _pbdata_H4 5 #include "stm32f10x.h"6 void delay(u32 nCount);7 8 #endif
1 //pbdata.c2 #include "pbdata.h"3 4 void delay(u32 nCount)5 {6     for(;nCount != 0;nCount--);7 }
 1 //led.h 2 #ifndef _LED_H 3 #define _LED_H 4  5 #define GPIO_Pin_x GPIO_Pin_8 6 #define GPIO_LED GPIOB 7  8 void led_init(void); 9 void led_setBit(void);10 11 #endif
1 // led. C 2 # include "LED. H "3 # include" pbdata. H "4 5 void led_init (void) 6 {7 gpio_inittypedef gpio_initstructure; 8 9 systeminit ();/* set the system clock */10 11 clock = gpio_pin_x; 12 clock = gpio_speed_50mhz; 13 bytes = gpio_mode_out_pp; 14 15 rcc_apb2periphclockcmd (temperature, enable);/* enable the gpio clock used by LEDs */16 gpio_init (gpio_led, & gpio_initstructure ); 17} 18 19 void led_setbit (void) 20 {21 While (1) 22 {23 gpio_setbits (gpio_led, gpio_pin_x); // set 124 delay (6000000); 25 gpio_resetbits (gpio_led, gpio_pin_x); 26 delay (6000000); 27} 28}

 

Updating register edition...

01:30:14

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.