当前位置:网站首页>STM32F103 LED flashing program realized by four methods
STM32F103 LED flashing program realized by four methods
2022-07-21 17:54:00 【Sell yourself to buy a lens】
This procedure is to light two LED, Respectively LED1 and LED2, Connect to several ports respectively GPIOB Of 0 Feet and 1 foot .
So first of all GPIOB Of 0 Feet and 1 Pin type initialization .
First create LED Driver program , LED.H and LED.C
LED.H
#ifndef __LED_H
#define __LED_H
#include "sys.h"
//#define LED1 PBout(0)// PB0
//#define LED2 PBout(1)// PB1
#define LEDPORT GPIOB // Definition LED Of IO Interface
#define LED1 GPIO_Pin_0 // Definition LED1 Of IO Interface
#define LED2 GPIO_Pin_1 // Definition LED2 Of IO Interface
void LED_Init(void);// initialization
#endif
LED.C
#include "led.h"
void LED_Init(void){
//LED Lamp interface initialization
GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC,ENABLE); // Set up A,B,C Three port enable clock
GPIO_InitStructure.GPIO_Pin = LED1 | LED2; // Select the port number (0,1 Port no. )
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // Set up IO The working mode of the interface is push-pull output
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Set up IO Interface speed 50MHz
GPIO_Init(LEDPORT, &GPIO_InitStructure);
}
/* choice IO How the interface works : GPIO_Mode_AIN Analog input GPIO_Mode_IN_FLOATING Floating input GPIO_Mode_IPD Drop down input GPIO_Mode_IPU Pull up input GPIO_Mode_Out_PP Push pull output GPIO_Mode_Out_OD Open drain output GPIO_Mode_AF_PP Multiplexing push pull output GPIO_Mode_AF_OD Reuse open drain output */
establish MAIN Program
main.c
#include "stm32f10x.h" //STM32 The header file
#include "sys.h"
#include "delay.h"
#include "led.h"
int main (void){
// The main program
RCC_Configuration(); // The clock is set
LED_Init();
while(1){
// Method 1:
GPIO_WriteBit(LEDPORT,LED1,(BitAction)(1)); //LED1 Interface output high level 1
delay_us(50000); // Time delay 1 second
GPIO_WriteBit(LEDPORT,LED1,(BitAction)(0)); //LED1 Interface output low level 0
delay_us(50000); // Time delay 1 second
// Method 2:
// GPIO_WriteBit(LEDPORT,LED1,(BitAction)(1-GPIO_ReadOutputDataBit(LEDPORT,LED1))); // Take the opposite LED1
// delay_ms(500); // Time delay 1 second
// Method 3:
// GPIO_SetBits(LEDPORT,LED1); //LED The lights are high level (1)
// delay_s(1); // Time delay 1 second
// GPIO_ResetBits(LEDPORT,LED1); //LED The lights are all low level (0)
// delay_s(1); // Time delay 1 second
// Method 4
// GPIO_Write(LEDPORT,0x0001); // Direct numeric operations write variable values to LED
// delay_s(2); // Time delay 1 second
// GPIO_Write(LEDPORT,0x0000); // Direct numeric operations write variable values to LED
// delay_s(2); // Time delay 1 second
}
}
边栏推荐
- Solve the problem of shell garbled code in Metasploit
- The design of off-site multi activity deployment of King glory mall
- 斯坦福、Meta AI新研究:实现AGI之路,数据剪枝比我们想象得更重要
- Vite 配置 cdn 加载资源
- C (36) folder, path, environment special directory class
- Haproxy+kept load balancing and high availability
- Code others
- Jianghu nickname of Chinese Universities
- Mutex mutex of thread C (43) is mutually exclusive
- STM32F103按键控制LED程序
猜你喜欢
史上最全的mysql数据类型汇总(下)
家园防线 | 全栈物联网灌溉系统技术指南
Thread of C (41)
Talk about pseudo sharing
Yolov7 experiment test 1: remote sensing image detection application
动手学moveit2|介绍和安装
关于Web响应式设计
Super milk's note taking software: obsidain
Clickhouse CPU memory resource optimization configuration
ipset v7.10: Kernel error received: set type not supported
随机推荐
聊聊Redis内存优化的7个神技
聊聊伪共享
Redis implements distributed global unique ID
Haproxy+kept load balancing and high availability
The new version of hands-on learning ros2 has been released
动态内存管理
家园防线 | 全栈物联网灌溉系统技术指南
Get file type
Talk about a wave of moveit2
王者荣耀商城异地多活部署设计
[CTF]-NepCTF2022
How to extract coordinate information in MATLAB visual image window figure
At the age of 30, I was laid off by the company, and some people never recovered, but I turned against the wind and was reborn~
Kali carries out ARP network disconnection attack
[featured] the structure of MySQL B-tree and b+tree?
国内DNS首选
XML parsing
From 20s to 500ms, I used these three methods
vim 编辑器学习笔记
STM32F103读写FLASH改变LED状态程序