微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 时基定时器

时基定时器

时间:11-27 来源:互联网 点击:
#include "stm32f10x.h"

void Delay(unsigned int x);

unsigned int TimingDelay;

int main(void)

{

SystemInit();//配置系统时钟

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);//使能APB2外设时钟

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD,ENABLE);//IO口使能设置

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);

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--;

}

}

//以下是报错函数

#ifdef USE_FULL_ASSERT

void assert_failed(uint8_t* file, uint32_t line)

{

while (1)

{

}

}

#endif

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top