#ifndef __SYSTICK_H
#define __SYSTICK_H
#include "stm32f10x.h"
#define SetTim_1us 72
#define SetTim_10us SetTim_1us*10
#define SetTim_1ms SetTim_1us*1000
void SysTick_Init(void);
void Delay_us(uint32_t time);
void Delay_ms(uint32_t time);
#endif
#include "systick.h"
static uint8_t dleay_us ;
static uint16_t dleay_ms ;
void SysTick_Init(void)
{
SysTick->CTRL &= ~(0x01<<2);
dleay_us = 9;
dleay_ms = 9000;
}
void Delay_us(uint32_t time)
{
uint32_t tmp;
SysTick->LOAD = time*dleay_us-1;
SysTick->VAL = 0x00;
SysTick->CTRL |= 0x01<<0;
do
{
tmp = SysTick->CTRL;
}while((tmp&0x01)&&!(tmp&(1<<16)));
SysTick->CTRL &= ~(0x01<<0);
SysTick->VAL = 0x00;
}
void Delay_ms(uint32_t time)
{
uint32_t tmp;
SysTick->LOAD = (uint32_t)time*dleay_ms-1;
SysTick->VAL = 0x00;
SysTick->CTRL |= 0x01<<0;
do
{
tmp = SysTick->CTRL;
}while((tmp&0x01)&&!(tmp&(1<<16)));
SysTick->CTRL &= ~(0x01<<0);
SysTick->VAL = 0x00;
}
|