LED Driver for STM32

Source: Internet
Author: User

This led applet is based on the minimum system board of the de-Lai. I was writing this program to be able to easily understand and facilitate portability. The trouble with a pin change for STM32 is that it's hard to get a job, so this time I'm writing this library, I also pay special attention to these aspects of a small LED is very simple sometimes used to do the adjustment trial, I think it is quite good below I will own the source of personal ability limited great God don't laugh!!!

In this source you just need to modify

Can quickly implement high and low level control on any of the STM32 pins.

Note that there is a delay in the operation of the first to be initialized in the main function (if not initialized will die in the loop) this delay source is borrowed from the atomic brother

#ifndef __led_h#define__led_h#include<sys.h>#defineLED2_ON 1#defineLed2_off 2#defineLED3_ON 3#defineLed3_off 4#defineLed2_rev 5//Pin Counter#defineLed3_rev 6//Pin Counter#defineLED2_CLK Rcc_apb2periph_gpioe#defineLed2_port Gpioe#defineLed2_pin Gpio_pin_5#defineLED3_CLK Rcc_apb2periph_gpiob#defineLed3_port Gpiob#defineLed3_pin Gpio_pin_5#defineLED2 Peout (5)//PF6#defineLED3 Pbout (5)//PF7voidLed_init (void);voidLed2_init (void);voidLed3_init (void);voiddebug_led (U8 x);#endif

/******************************************************************************* file LED.c* author Belye* version S T v3.5.0* Date 03-february-2016* The underlying driver for LEDs based on the de-fly Development Board * Usage Function Invocation Example * Note Remember to modify the corresponding LED initialization pin ******************** **********************************************************///V1.0 Modification Instructions//Adjust code add to reverse/*************************************** Function Call Example ************************************ led2_init ();//Remember to modify the contents of this function Debug_led (led2_on); ******************************************************************************************* ***/#include<LED.h>#include<delay.h>voidLed_init () {led2_init (); Led3_init ();}voidLed2_open () {LED2=0; }voidLed2_close () {LED2=1;}voidLed2rev () {gpio_writebit (Led2_port, Led2_pin, (bitaction) (1-(Gpio_readoutputdatabit (Led2_port, Led2_pin) )));}voidLed3_open () {LED3=0;}voidLed3_close () {LED3=1;}voidLed3rev () {gpio_writebit (Led3_port, Led3_pin, (bitaction) (1-(Gpio_readoutputdatabit (Led3_port, Led3_pin) )));}voiddebug_led (U8 x) {Switch(x) { Case 1: Led2_open ();  Break;  Case 2: Led2_close ();  Break;  Case 3: Led3_open ();  Break;  Case 4: Led3_close ();  Break;  Case 5: Led2rev ();  Break;  Case 6: Led3rev ();  Break; default:             Break; }}voidLed2_init (void) {gpio_inittypedef gpio_initstructure;             Rcc_apb2periphclockcmd (LED2_CLK, ENABLE); Gpio_initstructure.gpio_pin=Led2_pin; Gpio_initstructure.gpio_mode=gpio_mode_out_pp; Gpio_initstructure.gpio_speed=Gpio_speed_50mhz; Gpio_init (Led2_port,&gpio_initstructure);                         Gpio_setbits (Led2_port,led2_pin); }voidLed3_init (void) {gpio_inittypedef gpio_initstructure;            Rcc_apb2periphclockcmd (LED3_CLK, ENABLE); Gpio_initstructure.gpio_pin=Led3_pin; Gpio_initstructure.gpio_mode=gpio_mode_out_pp; Gpio_initstructure.gpio_speed=Gpio_speed_50mhz; Gpio_init (Led3_port,&gpio_initstructure);                        Gpio_setbits (Led3_port,led3_pin); }

LED Driver for 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.