97 lines
2.8 KiB
C
97 lines
2.8 KiB
C
|
/*
|
|||
|
********************************************************************************************************
|
|||
|
<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>delay.c
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>us ms
|
|||
|
<EFBFBD><EFBFBD> ע<EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>https://shop60670850.taobao.com
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD>ߣ<EFBFBD>lilianhe
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: 2017-2-6
|
|||
|
*********************************************************************************************************
|
|||
|
*/
|
|||
|
|
|||
|
/*
|
|||
|
********************************************************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><EFBFBD>
|
|||
|
1.2017-2-6<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>ó<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD>ֹ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ȷ,<EFBFBD><EFBFBD><EFBFBD><EFBFBD>do while<EFBFBD>ṹ!
|
|||
|
|
|||
|
*********************************************************************************************************
|
|||
|
*/
|
|||
|
|
|||
|
#include "delay.h"
|
|||
|
|
|||
|
static u8 fac_us=0;//us<75><73>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
static u16 fac_ms=0;//ms<6D><73>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
/*
|
|||
|
********************************************************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>Delay_Init(u8 SYSCLK)
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ӳٺ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
Ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>SYSTICK<EFBFBD><EFBFBD>ʱ<EFBFBD>ӹ̶<EFBFBD>ΪHCLKʱ<EFBFBD>ӵ<EFBFBD>1/8<EFBFBD><EFBFBD>SYSCLK:ϵͳʱ<EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD> ע<EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: 2017-2-6
|
|||
|
*********************************************************************************************************
|
|||
|
*/
|
|||
|
void Delay_Init(u8 SYSCLK)
|
|||
|
{
|
|||
|
// SysTick->CTRL&=0xfffffffb;//bit2<74><32><EFBFBD><EFBFBD>,ѡ<><D1A1><EFBFBD>ⲿʱ<E2B2BF><CAB1> HCLK/8
|
|||
|
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); //ѡ<><D1A1><EFBFBD>ⲿʱ<E2B2BF><CAB1> HCLK/8
|
|||
|
fac_us=SYSCLK/8;
|
|||
|
fac_ms=(u16)fac_us*1000;
|
|||
|
}
|
|||
|
|
|||
|
/*
|
|||
|
********************************************************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>Delay_ms(u16 nms)
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>ʱnms
|
|||
|
Ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>//SysTick->LOADΪ24λ<34>Ĵ<EFBFBD><C4B4><EFBFBD>,<2C><><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱΪ:
|
|||
|
//nms<=0xffffff*8*1000/SYSCLK
|
|||
|
//SYSCLK<4C><4B>λΪHz,nms<6D><73>λΪms
|
|||
|
//<2F><>72M<32><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,nms<=1864
|
|||
|
<EFBFBD><EFBFBD> ע<EFBFBD><EFBFBD>
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: 2017-2-6
|
|||
|
*********************************************************************************************************
|
|||
|
*/
|
|||
|
void Delay_ms(u16 nms)
|
|||
|
{
|
|||
|
u32 temp;
|
|||
|
SysTick->LOAD=(u32)nms*fac_ms;//ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(SysTick->LOADΪ24bit)
|
|||
|
SysTick->VAL =0x00; //<2F><><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
SysTick->CTRL=0x01 ; //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
do
|
|||
|
{
|
|||
|
temp=SysTick->CTRL;
|
|||
|
}
|
|||
|
while(temp&0x01&&!(temp&(1<<16)));//<2F>ȴ<EFBFBD>ʱ<EFBFBD>䵽<EFBFBD><E4B5BD>
|
|||
|
SysTick->CTRL=0x00; //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
SysTick->VAL =0X00; //<2F><><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
|
|||
|
/*
|
|||
|
********************************************************************************************************
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>void Delay_us(u32 nus)
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>ʱnus
|
|||
|
Ӳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>
|
|||
|
<EFBFBD><EFBFBD> ע:
|
|||
|
<EFBFBD><EFBFBD> <EFBFBD><EFBFBD>: 2017-2-6
|
|||
|
*********************************************************************************************************
|
|||
|
*/
|
|||
|
void Delay_us(u32 nus)
|
|||
|
{
|
|||
|
u32 temp;
|
|||
|
SysTick->LOAD=nus*fac_us; //ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
SysTick->VAL=0x00; //<2F><><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
SysTick->CTRL=0x01 ; //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
do
|
|||
|
{
|
|||
|
temp=SysTick->CTRL;
|
|||
|
}
|
|||
|
while(temp&0x01&&!(temp&(1<<16)));//<2F>ȴ<EFBFBD>ʱ<EFBFBD>䵽<EFBFBD><E4B5BD>
|
|||
|
SysTick->CTRL=0x00; //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
SysTick->VAL =0X00; //<2F><><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
}
|
|||
|
//------------------End of File----------------------------
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|