60 lines
1.3 KiB
C
60 lines
1.3 KiB
C
|
#include "delay.h"
|
|||
|
#include "stdint.h"
|
|||
|
#include "stm32f10x.h"
|
|||
|
|
|||
|
static uint8_t fac_us=0; //us<75><73>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
static uint16_t fac_ms=0; //ms<6D><73>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
|
|||
|
void DelayInit(void)
|
|||
|
{
|
|||
|
//ѡ<><D1A1><EFBFBD>ⲿʱ<E2B2BF><CAB1>
|
|||
|
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
|
|||
|
fac_us=SystemCoreClock/8000000; //<2F><><EFBFBD><EFBFBD>Ϊϵͳʱ<CDB3>ӵ<EFBFBD>1/8
|
|||
|
fac_ms=(u16)fac_us*1000;
|
|||
|
}
|
|||
|
|
|||
|
void Delay_us(unsigned int us)
|
|||
|
{
|
|||
|
u32 temp;
|
|||
|
SysTick->LOAD=us*fac_us; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
SysTick->VAL=0x00; //<2F><><EFBFBD>ռ<EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk;
|
|||
|
do
|
|||
|
{
|
|||
|
temp=SysTick->CTRL;
|
|||
|
}
|
|||
|
while(temp&0x01&&!(temp&(1<<16))); //<2F>ȴ<EFBFBD>ʱ<EFBFBD>䵽<EFBFBD><E4B5BD>
|
|||
|
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //<2F>رռ<D8B1>ʱ<EFBFBD><CAB1>
|
|||
|
SysTick->VAL=0x00; //<2F><><EFBFBD>ռ<EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
void Delay_ms(unsigned int ms)
|
|||
|
{
|
|||
|
u32 temp;
|
|||
|
SysTick->LOAD=ms*fac_ms;
|
|||
|
SysTick->VAL=0x00;
|
|||
|
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk;
|
|||
|
do
|
|||
|
{
|
|||
|
temp=SysTick->CTRL;
|
|||
|
}
|
|||
|
while(temp&0x01&&!(temp&(1<<16)));
|
|||
|
SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;
|
|||
|
SysTick->VAL=0x00;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
void Delay_s(unsigned int s)
|
|||
|
{
|
|||
|
unsigned char i;
|
|||
|
for(i=0;i<s;i++)
|
|||
|
{
|
|||
|
Delay_ms(1000);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|