Stm32 --- Key Learning

Source: Internet
Author: User
# Include "stm32f10x. H"
Gpio_inittypedef gpio_initstructure; // declare gpio_initstructure
Void led_init (){
Rcc_apb2periphclockcmd (rcc_apb2periph_gpioa, enable); // enable gpioa clock
Gpio_initstructure.gpio_pin = gpio_pin_4;
Gpio_initstructure.gpio_mode = gpio_mode_out_pp; // push the output
Gpio_initstructure.gpio_speed = gpio_speed_50mhz; // maximum output rate: 50 MHz gpio_init (gpioa, & gpio_initstructure); // initialize gpioa}
Void beep_init (){
Rcc_apb2periphclockcmd (rcc_apb2periph_gpiod, enable); // enable gpiod clock
Gpio_initstructure.gpio_pin = gpio_pin_3;
Gpio_initstructure.gpio_mode = gpio_mode_out_pp; // push the output
Gpio_initstructure.gpio_speed = gpio_speed_2mhz; // The maximum output rate is 2 MHz gpio_init (gpiod, & gpio_initstructure );
}
Void key_init (){
Rcc_apb2periphclockcmd (rcc_apb2periph_gpiod, enable); // enable gpiod clock
Gpio_initstructure.gpio_pin = gpio_pin_13;

Gpio_initstructure.gpio_mode = gpio_mode_ipu; // pull-up input

Gpio_initstructure.gpio_speed = gpio_speed_2mhz; // maximum output rate of 2 MHz gpio_init (gpiod, & gpio_initstructure); // initialize gpiod
}
Int main (){
Led_init (); beep_init (); key_init (); (;;){
If (gpio_readinputdatabit (gpiod, gpio_pin_13) = 0) // press {
Gpio_setbits (gpioa, gpio_pin_4); // set to 1, the light-emitting second-level tube is on gpio_resetbits (gpiod, gpio_pin_3); // reset, Buzzer sound}
Else // The button is not pressed {
Gpio_resetbits (gpioa, gpio_pin_4); // clear, light-emitting second-level tube off gpio_setbits (gpiod, gpio_pin_3); // set it to one with no sound on the buzzer }}
}

Stm32 --- Key Learning

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.