当前位置:网站首页>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
边栏推荐
- Leetcode one week race 298, first three questions
- [from deleting the database to running] the end of MySQL Foundation (the first step is to run.)
- r329(MAIX-II-A(M2A)资料汇总
- R language plot visualization: plot visualizes the normalized histogram, adds the density curve KDE to the histogram, and uses geom at the bottom edge of the histogram_ Adding edge whisker graph with
- IAR engineering adapts gd32 chip
- 【时间复杂度和空间复杂度】
- JS tutorial using electron JS build native desktop application ping pong game
- SAP OData development tutorial - from getting started to improving (including segw, rap and CDP)
- 理想路径问题
- 《软件工程》期末重点复习笔记
猜你喜欢

The details of the first pig heart transplantation were fully disclosed: human herpes virus was found in the patient, the weight of the heart doubled after death, and myocardial cell fibrosis

神经网络“炼丹炉”内部构造长啥样?牛津大学博士小姐姐用论文解读

100+ data science interview questions and answers Summary - basic knowledge and data analysis

In a bad mood, I just write code like this

架构实战营毕业设计

国内首款开源 MySQL HTAP 数据库即将发布,三大看点提前告知
Scala 基礎 (二):變量和數據類型
![[Blue Bridge Cup training 100 questions] scratch distinguishing prime numbers and composite numbers Blue Bridge Cup scratch competition special prediction programming question intensive training simul](/img/26/c0c8a406ff4ffe0ae37d277f730bd0.png)
[Blue Bridge Cup training 100 questions] scratch distinguishing prime numbers and composite numbers Blue Bridge Cup scratch competition special prediction programming question intensive training simul
![[force deduction question] two point search: 4 Find the median of two positive arrays](/img/4f/43aa7e14344e7e1a2fb7c1d209d13b.png)
[force deduction question] two point search: 4 Find the median of two positive arrays

Ideal path problem
随机推荐
Natural language inference with attention and fine tuning Bert pytorch
安信证券排名第几位?开户安全吗?
Redis 迁移(操作流程建议)1
Cuckoo filter for Chang'an chain transaction
LeetCode Algorithm 24. 两两交换链表中的节点
Scala Basics (II): variables and data types
Binary array command of redis
固件供应链公司Binarly获得WestWave Capital和Acrobator Ventures的360万美元投资
What is the process of switching C # read / write files from user mode to kernel mode?
TCP congestion control details | 1 summary
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!
IAR工程适配GD32芯片
JS tutorial - printing stickers / labels using the electronjs desktop application
JS教程之使用 ElectronJS、VueJS、SQLite 和 Sequelize ORM 从 A 到 Z 创建多对多 CRUD 应用程序
Knowing these commands allows you to master shell's own tools
架构实战营毕业设计
Science | 红树林中发现的巨型细菌挑战传统无核膜观念
大话领域驱动设计——表示层及其他
Practice of federal learning in Tencent micro vision advertising
When a programmer is disturbed 10 times a day, the consequences are amazing!