当前位置:网站首页>Stm32f103c8t6 realize breathing lamp code
Stm32f103c8t6 realize breathing lamp code
2022-06-26 16:33:00 【Related to the sun_】
PWM.h
#ifndef __PWM_H
#define __PWM_H
void PWM_Init();
void PWM_SetCompare1(uint16_t Compare);
#endif
PWM.c
#include "stm32f10x.h" // Device header
void PWM_Init()
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE); // Turn on timer 2
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);// passageway 2 Clock enable function
GPIO_InitTypeDef GPIO_InitStructure; // Definition GPIO Initializing structure variables
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // Set up GPIO For push-pull output mode
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; // Set up P1 P2
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // The speed is set to 50MHz
GPIO_Init(GPIOA, &GPIO_InitStructure); // Proceed according to the above parameters GPIO The initialization
TIM_InternalClockConfig(TIM2);//TIM The time base unit of is controlled by the internal clock
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInitStructure.TIM_Period = 100 - 1; //ARR The value of the automatic reloader
TIM_TimeBaseInitStructure.TIM_Prescaler = 720 - 1; //PSC Prescaler value Yes 72M(720000000) Conduct 7200 frequency division namely 10K At different frequencies meter 10000 Number 1s Time for
TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0;// Repeat counter value
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitStructure);
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;// Output polarity selection
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;// Output status enable
TIM_OCInitStructure.TIM_Pulse = 10;//CCR
TIM_OC1Init(TIM2,&TIM_OCInitStructure);
TIM_Cmd(TIM2,ENABLE);
}
void PWM_SetCompare1(uint16_t Compare)// Constant adjustment CCR, Achieve breathing lamp effect
{
TIM_SetCompare1(TIM2, Compare);
}
main.c
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "LED.h"
#include "Key.h"
#include "OLED.H"
#include "PWM.H"
uint8_t i;
int main(void)
{
OLED_Init();
PWM_Init();
while (1)
{
for ( i = 0; i <= 100; i++)
{
PWM_SetCompare1(i);
Delay_ms(10);// Delay , Otherwise it will be too fast
}
for ( i = 0; i <= 100; i++)
{
PWM_SetCompare1(100 - i);
Delay_ms(10);
}
}
}
Secretly trying , Grow slowly
边栏推荐
- C语言 头哥习题答案截图
- 基于STM32+华为云IOT设计的云平台监控系统
- C. Inversion Graph
- Which position does Anxin securities rank? Is it safe to open an account?
- Supplement the short board - Open Source im project openim about initialization / login / friend interface document introduction
- 当一个程序员一天被打扰 10 次,后果很惊人!
- What does the inner structure of the neural network "alchemy furnace" look like? An interpretation of the thesis by the doctor of Oxford University
- 牛客小白月赛50
- R语言plotly可视化:plotly可视化归一化的直方图(historgram)并在直方图中添加密度曲线kde、并在直方图的底部边缘使用geom_rug函数添加边缘轴须图
- JS tutorial using electron JS build native desktop application ping pong game
猜你喜欢
C语言 头哥习题答案截图
Oilfield exploration problems
What does the inner structure of the neural network "alchemy furnace" look like? An interpretation of the thesis by the doctor of Oxford University
[Li Kou brush questions] 11 Container holding the most water //42 Rain water connection
若依如何实现接口限流?
Cloud platform monitoring system based on stm32+ Huawei cloud IOT design
Cuckoo filter for Chang'an chain transaction
100+ data science interview questions and answers Summary - basic knowledge and data analysis
[graduation season] a word for graduates: the sky is high enough for birds to fly, and the sea is wide enough for fish to leap
stm32h7b0替代h750程序导致单片机挂掉无法烧录程序问题
随机推荐
牛客编程题--必刷101之动态规划(一文彻底了解动态规划)
知道这几个命令让你掌握Shell自带工具
[机缘参悟-31]:鬼谷子-抵巇[xī]篇-危机是危险与机会并存
Solution for filtering by special string of microservice
架构实战营毕业设计
[from deleting the database to running] the end of MySQL Foundation (the first step is to run.)
电路中缓存的几种形式
【力扣刷题】二分查找:4. 寻找两个正序数组的中位数
"C language" question set of ⑩
用Attention和微调BERT进行自然语言推断-PyTorch
请指教同花顺软件究竟是什么?网上开户是否安全么?
数据分析----numpy快速入门
Dialogue with the senior management of Chang'an Mazda, new products will be released in Q4, and space and intelligence will lead the Japanese system
# 补齐短板-开源IM项目OpenIM关于初始化/登录/好友接口文档介绍
Structure the graduation project of actual combat camp
day10每日3题(2):统计最大组的数目
Kept to implement redis autofailover (redisha)
stm32h7b0替代h750程序导致单片机挂掉无法烧录程序问题
Oilfield exploration problems
Redis order sorting command