//******************************************************************************
//*******************************************************************
/***********************************************************************
main file, GPIO operation, complete the simplest IO operation experiment, which is to control the LED lights.
The 4 LEDs correspond to the 6th, 7th, 8th, and 9th pins of the PC respectively. 4 LEDs display water
*********************************************************************************/
#include "stm32f10x_lib.h"
GPIO_InitTypeDef GPIO_InitStructure;
void LED_Init(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_In itStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void LED_TurnOn(u8 led)
{
}
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
main()
{
//RCC_Configuration();
LED_Init();
while(1)
{
GPIO_SetBits(GPIOC, GPIO_Pin_9);
Delay(0x8ffff);
GPIO_ResetBits(GPIOC, GPIO_Pin_9);
Delay(0x8ffff);
GPIO_SetBits(GPIOC, GPIO_Pin_10);
Delay(0x8ffff);
GPIO_ResetBits(GPIOC, GPIO_Pin_10); Delay(
0x8ffff ); GPIO_SetBits(GPIOC,
GPIO_Pin_11 ); Delay(0x8ffff); _12) ; Delay( 0x8ffff); GPIO_ResetBits(GPIOC, GPIO_Pin_12); Delay(0x8ffff); } } Note: RCC and GPIO library functions are used here, so these two functions must be added to the project. About the firmware library function in the folder: C:\Keil\ ARM\RV31\LIB\ST\STM32F10xIn order to avoid changing the library functions in the KEIL folder during operation, the firmware function library can be placed in other folders, such as: E:\jy\work\STM\WxlStm32\LAB\ The stm32f10x_lib.c file in the library contains some definitions of the entire library and is required. The project after adding is: GPIO library function brief description: Function name Function description GPIO_DeInit Reinitialize peripheral device GPIOx related registers to their default reset values GPIO_AFIODeInit Initialize interleaving functions (remap, event control and EXTI configuration) Register GPIO_Init According to the GPIO_initialization structure Initializes the peripheral device GPIOx with the specified elements GPIO_StructInit Fills the elements in the GPIO_initialization structure (GPIO_InitStruct) with reset values GPIO_ReadInputDataBit Reads the input data of the specified port pin GPIO_ReadInputData Reads the input data of the specified port GPIO_ReadOtputDataBit Reads the output data of the specified port pin GPIO_ReadOtputData Reads the output data of the specified port GPIO_SetBits Sets the specified port pin to 1 GPIO_ResetBits Clears the specified port pin to 0 GPIO_WriteBit Sets or clears the selected data port pin GPIO_Write Writes the specified data to the GPIOx port register GPIO_ANAPinConfig Enables or disables GPIO 4 Analog input modeGPIO_PinLockConfig locks the GPIO pin registerGPIO_EventOutputConfig selects the GPIO pin as event outputGPIO_EventOutputCmd enables or disables event outputGPIO_PinRemapConfig changes the mapping of the specified pinGPIO_EMIConfig enables or disables the EMI mode of GPIO 8 and 9Extended experiment: LED lights display on the top On the basis of the key program, let's first look at the principle diagram of the key: Of course, this principle diagram is also quite simple, no need to read the explanation, the only thing to note is that the difference between the OK key and the other three keys is that pressing High level, the other three are low level when pressed. The complete list after joining is as follows: //******************************************** ***************************** // Author: JingYong // Time: 2008/4/24 //***** ************************************************** **************** /************************************* ************************************** GPIO operation, complete the simplest IO operation experiment, use Button control LED light flashing ************************************************ *****************************/ #include "stm32f10x_lib.h"
GPIO_InitTypeDef GPIO_InitStructure;
//Keyboard definition
#define KEY_OK GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)
#define KEY_DOWN GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1)
#define KEY_UP GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2)
#define KEY_ESC GPIO_ReadInputData Bit(GPIOA, GPIO_Pin_3)
//LED initialization
void LED_Init( void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
//Key initialization
void KEY_Init (void)
{
GPIO_InitTypeDef gpio_init;
RCC_APB2PeriphClockCmd(RC C_APB2Periph_GPIOA, ENABLE);
gpio_init.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
gpio_init.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &gpio_init);
}
//Delay function
void Delay(vu32 nCount)
{
for(; nCount != 0; nCount--);
}
//Main function
main()
{
//RCC_Configuration();
LED_Init();
KEY_Init ();
while(1)
{
if(!KEY_ESC)
{
while(! KEY_ESC) ;
GPIO_SetBits(GPIOC, GPIO_Pin_9);
Delay(0x8ffff);
GPIO_ResetBits(GPIOC, GPIO_Pin_9);
Delay(0x8ffff);
}
else if(!KEY_UP)
{
while(!KEY_UP) ;
GPIO_SetBits(GPIOC, GPIO_Pin_10);
Delay( 0x8ffff);
GPIO_ResetBits(GPIOC, GPIO_Pin_10);
Delay(0x8ffff);
}
else if(!KEY_DOWN)
{
while(!KEY_DOWN);
GPIO_SetBits(GPIOC, GPIO_Pin_11);
Delay(0x8ffff);
GPIO_ResetBits(GPIOC, GPIO_Pin_11);
Delay(0x8ffff);
}
else if(KEY_OK)
{
while(KEY_OK);
GPIO_SetBits(GPIOC, GPIO_Pin_12);
Delay(0x8ffff);
GPIO_ResetBits( GPIOC, GPIO_Pin_12);
Delay(0x8ffff);
}
}
}
This example is to press different buttons to flash the corresponding LED lights.
Previous article:stm32 assembly example
Next article:stm32 rcc clock
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- How is the 4-20mA output circuit of a pressure sensor or temperature sensor usually implemented?
- The driver chip made by TI's LM3409 encountered a problem and the LED could not light up
- [TI recommended course] #Boost and buck-boost DCDC converters help wireless charging design#
- How to draw a flowchart for programming? Share a simple method of drawing a flowchart
- RXD outputs a high level, how can we make it output a low level to turn on Q2?
- GaN Amplifiers - Gallium Nitride Technology
- Is this the price you paid for the CC3220SF board you have?
- The upcoming Circuit Playground Bluefruit
- C5000 Low Power DSP – Tools and Software
- Measuring a signal with an oscilloscope (first time using an oscilloscope)