蜂鸣器:
#include "beep.h"
void hal_beep_init()
{
/******RCC章节*******/
RCC->MP_AHB4ENSETR |= (0x1<<1);
RCC->MP_APB1ENSETR |= (0x1<<2);
/******GPIO章节******/
GPIOB->MODER &= (~(0x3<<12));
GPIOB->MODER |= (0x1<<13);
GPIOB->AFRL &= (~(0xf<<24));
GPIOB->AFRL |= (0x1<<25);
/******TIM4章节******/
TIM4 ->PSC = 209 - 1;
TIM4 ->ARR = 1000;
TIM4 ->CCR1 = 700;
TIM4->CCMR1 &= (~(0x1<<16));
TIM4->CCMR1 &= (~(0x7<<4));
TIM4->CCMR1 |= (0x6<<4);
TIM4->CCMR1 |= (0x1<<3);
// TIM4->CCMR1 &= (0x3<<0);
TIM4->CCER |= (0x1<<3);
TIM4->CCER &= (~(0x1<<1));
TIM4->CCER |= (0x1<<0);
TIM4->CR1 |= (0x1<<7);
TIM1->CR1 &= (~(0x3<<5));
TIM4->CR1 |= (0x1<<4);
TIM4->CR1 |= (0x1<<0);
}
震动马达:
#include "beep.h"
void hal_motor_init()
{
/******RCC章节*******/
RCC->MP_AHB4ENSETR |= (0x1<<5);
RCC->MP_APB2ENSETR |= (0x1<<3);
/******GPIO章节******/
GPIOF->MODER &= (~(0x3<<12));
GPIOF->MODER |= (0x1<<13);
GPIOF->AFRL &= (~(0xf<<24));
GPIOF->AFRL |= (0x1<<24);
/******TIM16章节******/
TIM16 ->PSC = 209 - 1;
TIM16 ->ARR = 1000;
TIM16 ->CCR1 = 700;
TIM16->CCMR1 &= (~(0x1<<16));
TIM16->CCMR1 &= (~(0x7<<4));
TIM16->CCMR1 |= (0x6<<4);
TIM16->CCMR1 |= (0x1<<3);
// TIM16->CCMR1 &= (0x3<<0);
TIM16->CCER |= (0x1<<3);
TIM16->CCER &= (~(0x1<<1));
TIM16->CCER |= (0x1<<0);
TIM16->CR1 |= (0x1<<7);
TIM1->CR1 &= (~(0x3<<5));
TIM16->CR1 |= (0x1<<4);
TIM16->CR1 |= (0x1<<0);
TIM16->BDTR |= (0x1<<15);
}
风扇:
#include "beep.h"
void hal_fun_init()
{
/******RCC章节*******/
RCC->MP_AHB4ENSETR |= (0x1<<4);
RCC->MP_APB2ENSETR |= (0x1<<0);
/******GPIO章节******/
GPIOE->MODER &= (~(0x3<<18));
GPIOE->MODER |= (0x1<<19);
GPIOE->AFRH &= (~(0xf<<4));
GPIOE->AFRH |= (0x1<<4);
/******TIM1章节******/
TIM1 ->PSC = 209 - 1;
TIM1 ->ARR = 1000;
TIM1 ->CCR1 = 700;
TIM1->CCMR1 &= (~(0x1<<16));
TIM1->CCMR1 &= (~(0x7<<4));
TIM1->CCMR1 |= (0x6<<4);
TIM1->CCMR1 |= (0x1<<3);
//TIM1->CCMR1 &= (~(0x3<<0));
TIM1->CCER |= (0x1<<3);
TIM1->CCER &= (~(0x1<<1));
TIM1->CCER |= (0x1<<0);
TIM1->CR1 |= (0x1<<7);
TIM1->CR1 &= (~(0x3<<5));
TIM1->CR1 |= (0x1<<4);
TIM1->CR1 |= (0x1<<0);
TIM1->BDTR |= (0x1<<15);
}