BMS STM32 V4.0.0.0

This commit is contained in:
2026-08-25 17:30:40 +08:00
commit 3ae7bcb054
313 changed files with 115734 additions and 0 deletions
+78
View File
@@ -0,0 +1,78 @@
/**
******************************************************************************
* @file tim.c
* @author Jerry
* @version V2.1
* @date 19-April-2022
* @brief tim program body.
******************************************************************************
* @attention
*
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "global.h"
//相对精确的ms延时,不使用中断
//优化:防止和其他中断冲突,导致卡死
void delay_ms(uint16_t ms)
{
uint16_t i;
volatile uint32_t tempreg;
uint32_t timeout; //等待时间
for(i=0; i<ms; i++)
{
SysTick->CTRL |= SysTick_CTRL_CLKSOURCE_Msk;
SysTick->LOAD = 72000 - 1;
SysTick->VAL = 0;
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
timeout = 72000;
do
{
tempreg = SysTick->CTRL;
timeout--;
if(timeout == 0)
{
break; //超时退出
}
}
while( (tempreg & SysTick_CTRL_COUNTFLAG_Msk) ==0);
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
SysTick->VAL = 0;
}
}
//相对精确的us延时,不使用中断
//(没调用过)
void delay_us(uint16_t us)
{
uint16_t i;
volatile uint32_t tempreg;
for(i=0; i<us; i++)
{
SysTick->CTRL |= SysTick_CTRL_CLKSOURCE_Msk;
SysTick->LOAD = 72;
SysTick->VAL = 0;
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
do
{
tempreg = SysTick->CTRL;
}
while( (tempreg & SysTick_CTRL_COUNTFLAG_Msk) ==0);
SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
SysTick->VAL = 0;
}
}