新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > STM32系統(tǒng)嘀嗒時基定時器應用

STM32系統(tǒng)嘀嗒時基定時器應用

作者: 時間:2016-11-27 來源:網(wǎng)絡 收藏
測試條件:STM32F103VET6開發(fā)板



本文引用地址:http://butianyuan.cn/article/201611/322253.htm


#include "stm32f10x.h"

void Delay_Nms(unsigned int n)
{
SysTick->LOAD=9000*n;//裝入初始值,定時時間為1/(72M/8) *9000 s
SysTick->CTRL=0x00000001; //設置始終源為系統(tǒng)始終八分頻,并打開定時器
while(!(SysTick->CTRL&0x00010000));//等待遞減計數(shù)器減到0
SysTick->CTRL=0x00000000;//關閉定時器
}

int main(void)
{
SystemInit();//配置系統(tǒng)時鐘
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);//使能APB2外設時鐘
GPIO_InitTypeDef GPIO_InitStructure;//定義I/O口結構體
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽輸出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);

GPIO_ResetBits(GPIOC, GPIO_Pin_6);


while(1)
{

GPIO_SetBits(GPIOC, GPIO_Pin_6);
Delay_Nms(1000);//延時1s
GPIO_ResetBits(GPIOC, GPIO_Pin_6);
Delay_Nms(1000);
}
}


//以下是報錯函數(shù)
#ifdefUSE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
while (1)
{
}
}
#endif



評論


技術專區(qū)

關閉