Some Characteristics of gpio, translated from the reference manual of St
1. 16 groups of Io are available
2. Push/Open/pull/drop-down
3. data can be output from ODR or from peripherals
4. Each Io speed can be set independently.
5. Float input, up/down input, analog input
6. input data to IDR or peripherals
7. You can use gpiox_bsrr to set a specific bit for ODR data.
8. The IO locking device can freeze the IO configuration. (Know the next reset)
9. What about public simulation?
10. Reuse input/output selection and access
11. Io is quickly reversed. Two clock cycles can be reversed once.
12. The easy-to-configure reuse function enables one Io to have multiple functions.
In this experiment, the digital output is used to control the I/O inversion time to form a set of LEDs with PWM waveform drives connected to the I/O port.
【CodeImplementation]
Definition of LED:
Typedef Enum
{
Led1 = 0,
Led2 = 1,
Led3 = 2,
Led4 = 3
} Led_def;
Static gpio_typedef * led_port [4] = {gpiod, gpiod };
Static const 2010led_pin [4] = {gpio_pin_12, gpio_pin_13, gpio_pin_14, gpio_pin_15 };
Led initialization Function
Void led_init (void)
{
Gpio_inittypedef gpio_initstructure;
Rcc_ahb1periphclockcmd (rcc_ahb1periph_gpiod, enable );
Gpio_initstructure.gpio_pin = gpio_pin_12 | gpio_pin_13 | gpio_pin_14 | gpio_pin_15;
Gpio_initstructure.gpio_mode = gpio_mode_out;
Gpio_initstructure.gpio_otype = gpio_otype_pp;
Gpio_initstructure.gpio_speed = gpio_speed_100mhz;
Gpio_initstructure.gpio_pupd = gpio_pupd_nopull;
Gpio_init (gpiod, & gpio_initstructure );
}
Void ledon (led_def led) // LED light
{
Led_port [led]-> bsrrl = led_pin [led];
}
Void ledoff (led_def led) // disable the LED
{
Led_port [led]-> bsrrh = led_pin [led];
}
Void ledtog (led_def led) // led status flip
{
Led_port [led]-> ODR ^ = led_pin [led];
}
After the initialization is complete, control the LED disconnection in the main function. When the PWM duty cycle is greater than one value, the brightness of the LED does not change significantly. Therefore, adjust the PWM change rate to make the brightness change even throughout the process. When the duty cycle is too small and the LED has no brightness, I will cancel this duty cycle. The implementation of the main function is as follows:
Without the while (1) loop, it is endless and repetitive.
For (I = 100; (I <2000) & (I> = 0); I = I + J)
{
Ledon (led2 );
Delay_us (I );
Ledoff (led2 );
Delay_us (2000-i );
If (I = 1990)
J =-5;
If (I = 10)
J = 1;
If (I >= 1000)
J = 5;
If (j = 5) & (I <= 1000 ))
J =-1;
}
Technorati flag: 440f4, gpio, led, breathing Lamp