当前位置:网站首页>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
边栏推荐
- R语言广义线性模型函数GLM、glm函数构建逻辑回归模型(Logistic regression)、分析模型是否过离散(Overdispersion)、使用残差偏差与二项式模型中的剩余自由度的比率评估
- Science | 红树林中发现的巨型细菌挑战传统无核膜观念
- [understanding of opportunity -31]: Guiguzi - Daoyu [x ī] Crisis is the coexistence of danger and opportunity
- pybullet机器人仿真环境搭建 5.机器人位姿可视化
- Net based on girdview control to delete and edit row data
- Ideal path problem
- Cookie和Session详解
- Pybullet robot simulation environment construction 5 Robot pose visualization
- Stm32h7b0 replaces the h750 program, causing the MCU to hang up and unable to burn the program
- 【毕业季】致毕业生的一句话:天高任鸟飞,海阔凭鱼跃
猜你喜欢

Quickly get started with federal learning -- the practice of Tencent's self-developed federal learning platform powerfl

基于Kubebuilder开发Operator(入门使用)

Niuke programming problem -- dynamic programming of must brush 101 (a thorough understanding of dynamic programming)

I regard it as a dry product with a monthly income of more than 30000 yuan for sidelines and more than 10000 yuan for novices!

Développer un opérateur basé sur kubebuilder (démarrer)

架构实战营毕业设计

基於Kubebuilder開發Operator(入門使用)

5G未平6G再启,中国引领无线通信,6G的最大优势在哪里?

Structure the graduation project of actual combat camp

r329(MAIX-II-A(M2A)资料汇总
随机推荐
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
R language plotly visualization: Violin graph, multi category variable violin graph, grouped violin graph, split grouped violin graph, two groups of data in each violin graph, each group accounts for
内存分区模型
架构实战营毕业设计
基於Kubebuilder開發Operator(入門使用)
Solidus Labs欢迎香港前金融创新主管赵嘉丽担任战略顾问
无需人工先验!港大&同济&LunarAI&旷视提出基于语义分组的自监督视觉表征学习,显著提升目标检测、实例分割和语义分割任务!...
1-12Vmware新增SSH功能
【力扣刷题】11.盛最多水的容器//42.接雨水
Exquisite makeup has become the "soft power" of camping, and the sales of vipshop outdoor beauty and skin care products have surged
[chat in 5] eight years after graduation, I have been pursuing my dream
Redis Guide (8): principle and implementation of Qianfan Jingfa distributed lock
JS教程之使用 ElectronJS 桌面应用程序打印贴纸/标签
Redis 迁移(操作流程建议)1
How to implement interface current limiting?
Redis order sorting command
Pybullet robot simulation environment construction 5 Robot pose visualization
【毕业季】致毕业生的一句话:天高任鸟飞,海阔凭鱼跃
SAP OData 开发教程 - 从入门到提高(包含 SEGW, RAP 和 CDP)
【从删库到跑路】MySQL基础 完结篇(入个门先跑路了。。)