新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 【STM32 Cotex-M3處理器系列編程】時基定時器

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

        作者: 時間:2016-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


        評論


        技術專區

        關閉
        主站蜘蛛池模板: 贵阳市| 新蔡县| 枣庄市| 青河县| 罗甸县| 民权县| 娱乐| 滕州市| 福海县| 河津市| 库伦旗| 渝北区| 五家渠市| 潞城市| 淮北市| 新野县| 安阳市| 宝丰县| 周口市| 确山县| 西峡县| 嘉禾县| 淄博市| 九台市| 乌拉特中旗| 滨州市| 云安县| 锡林浩特市| 琼中| 鹤山市| 历史| 惠州市| 阿荣旗| 始兴县| 中宁县| 涞源县| 抚州市| 洪湖市| 朝阳市| 乐清市| 嘉禾县|