新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 【STM32 Cotex-M3處理器系列編程】時基定時器

【STM32 Cotex-M3處理器系列編程】時基定時器

作者: 時間:2016-11-27 來源:網(wǎng)絡(luò) 收藏
#include "stm32f10x.h"
void Delay(unsigned int x);
unsigned int TimingDelay;
int main(void)
{
SystemInit();//配置系統(tǒng)時鐘
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);//使能APB2外設(shè)時鐘
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD,ENABLE);//IO口使能設(shè)置
GPIO_InitTypeDef GPIO_InitStructure; //定義I/O口結(jié)構(gòu)體
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);
if (SysTick_Config(72000000 / 100)) //每10ms中斷一次
{
while (1);
}
while(1)
{
GPIO_SetBits(GPIOC, GPIO_Pin_6);
Delay(100); //100*10ms=1s
GPIO_ResetBits(GPIOC, GPIO_Pin_6);
Delay(100); //100*10ms=1s
}
}
void Delay(unsigned int x)
{
TimingDelay=x;
while(TimingDelay!=0);
}
void TimingDelay_Decrement(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
//以下是報錯函數(shù)
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
while (1)
{
}
}
#endif


關(guān)鍵詞: STM32Cotex-M3時基定時

評論


技術(shù)專區(qū)

關(guān)閉