新聞中心

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

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

作者: 時(shí)間:2016-11-27 來(lái)源:網(wǎng)絡(luò) 收藏
#include "stm32f10x.h"
void Delay(unsigned int x);
unsigned int TimingDelay;
int main(void)
{
SystemInit();//配置系統(tǒng)時(shí)鐘
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);//使能APB2外設(shè)時(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--;
}
}
//以下是報(bào)錯(cuò)函數(shù)
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
while (1)
{
}
}
#endif


評(píng)論


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

關(guān)閉