当前位置:网站首页>[STM32 learning] (4) press the key to control the flow light
[STM32 learning] (4) press the key to control the flow light
2022-07-24 09:50:00 【Use small materials】
Learning single-chip microcomputer should learn water lamp , Because the running water lamp is relatively simple , Easy to implement , The effect is also better .
This time, the water light is controlled by pressing the key , Press the key once to start the running water lamp , The use of buttons , It is essential in the development of SCM .
The model of single chip microcomputer I use here is STM32F103VET
8 individual LED The light is connected PA The lower eight places of mouth .
Be careful :
1. Turn on GPIOA and GPIOB The clock of
2. Set up GPIOA Working mode of port , and GPIOB Working mode of port
GPIOA:
1) open 0-7 IO mouth
2) Set up 8 Each port is a push-pull output
3) Speed is 50MHz
GPIOB:( Connect with the key )
1) Set up 0 mouth
2) Enter... For pull-up
The project layout is shown below :

The code is also relatively simple , The code is as follows :( I didn't modularize the code here , Only in main Function , Easy for beginners to understand , Later code will gradually modularize )
#include "stm32f10x.h" // Device header
#include "stm32f10x_gpio.h"
void delay(void);
int main(void)
{
unsigned char temp=0XF0;
RCC_DeInit(); // Add peripherals RCC Register reset to default
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); // To enable or disable APB2 Peripheral clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitTypeDef GPIO_InitStruct; // Defining structure Contains peripherals GPIO Configuration information
GPIO_DeInit(GPIOA); // Add peripherals GPIOA Register reset to default
GPIO_DeInit(GPIOB);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7; // Select low 8 For pin
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP; // Push pull output
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; // Maximum output rate 50MHz
GPIO_Init(GPIOA,&GPIO_InitStruct); // according to GPIO_InitStruct The parameter specified in GPIOA register
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStruct);
GPIO_Write(GPIOA,0X00F0);
while(1)
{
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0) == 0) // Check that the key is pressed
{
delay(); // Desquamation
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0) == 0) // Judge whether the key is pressed again
{
temp = ~temp;
GPIO_Write(GPIOA,temp);
while(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_0) == 0); // Switch release detection
}
}
}
}
void delay(void)
{
int i,j;
for(i=0;i<400;i++)
{
for(j=0;j<400;j++);
}
}The effect is water lamp , Please test yourself .
Code link , In fact, the code has been posted above , You don't need to download points .
https://download.csdn.net/download/xiaocaidayong/11884602
边栏推荐
- IdentityServer4入门
- Cyclicbarrier and countdownlatch [concurrent programming]
- The most complete solution for distributed transactions
- 程序的编译与链接
- 获取所有股票历史行情数据
- Firewall off and on command
- Where is the bitbucket clone address
- Do you really understand the concept of buffer? Take you to uncover the buffer zone~
- Synchronized scope "concurrent programming"
- Hands on deep learning (VII) -- bounding box and anchor box
猜你喜欢
![Cyclicbarrier and countdownlatch [concurrent programming]](/img/38/3305a0cdb6de40e1370cc93c8e5014.png)
Cyclicbarrier and countdownlatch [concurrent programming]

云原生(十二) | Kubernetes篇之Kubernetes基础入门
![[note] what is kernel / user space? Let's start with how the CPU runs the program](/img/b5/0ab4f2841faf3573b4502d2cd09069.png)
[note] what is kernel / user space? Let's start with how the CPU runs the program

Opencv learning Day5
![[robot learning] mechanism kinematics analysis and MATLAB simulation (3D model +word report +matlab program)](/img/dd/d29a5be7306580ad388ba6487d230f.png)
[robot learning] mechanism kinematics analysis and MATLAB simulation (3D model +word report +matlab program)

The most complete solution for distributed transactions

JS locate Daquan to get the brother, parent and child elements of the node, including robot instances

Linux deployment mysql8.0

MySQL基础篇(一)-- SQL基础

What if path is deleted by mistake when configuring system environment variables?
随机推荐
Linux deployment mysql8.0
力扣300-最长递增子序列——动态规划
Learn more about the synchronized lock upgrade process [concurrent programming]
LiteOS_ a - SYS_ The run() function is missing a header file.
[MySQL] - deep understanding of index
JS, the return statement used in the for loop should be placed in the function to terminate the loop, similar to the invalid return problem in break & foreach
MySQL基础篇(一)-- SQL基础
Spark Learning: using RDD API to implement inverted index
Arduino drive Lora module node
Detailed LinkedList
MySQL Basics (I) -- SQL Basics
Dorissql syntax Usage Summary
详解LinkedList
Is it safe for Oriental Fortune futures to open an online account, and will it be cheated?
DSP development, using CCS software to establish engineering and burning
[leetcode] 31. Next arrangement
07 Jason module
IdentityServer4入门
What happens from the input URL to the page load
[Luogu p3426] SZA template (string) (KMP)