新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > STM32學(xué)習(xí)筆記—SysTick定時(shí)器

        STM32學(xué)習(xí)筆記—SysTick定時(shí)器

        作者: 時(shí)間:2013-01-24 來源:網(wǎng)絡(luò) 收藏

        void SysTick_Configuration(void)

        {

        /* Select AHB clock(HCLK) as SysTick clock source 設(shè)置AHB時(shí)鐘為SysTick時(shí)鐘*/

        SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);

        /* Set SysTick Priority to 3 設(shè)置SysTicks中斷搶占優(yōu)先級(jí) 3, 從優(yōu)先級(jí)0*/

        NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 3, 0);

        /* SysTick interrupt each 1ms with HCLK equal to 72MHz 每1ms發(fā)生一次SysTick中斷*/

        SysTick_SetReload(72000);

        /* Enable the SysTick Interrupt */

        SysTick_ITConfig(ENABLE);

        }

        延時(shí)函數(shù),需要延時(shí)處調(diào)用:

        view plaincopy to clipboardprint?

        void Delay(u32 nTime)

        {

        /* Enable the SysTick Counter 允許SysTick計(jì)數(shù)器*/

        SysTick_CounterCmd(SysTick_Counter_Enable);

        TimingDelay = nTime;

        while(TimingDelay != 0)

        ; //等待計(jì)數(shù)至0

        /* Disable the SysTick Counter 禁止SysTick計(jì)數(shù)器*/

        SysTick_CounterCmd(SysTick_Counter_Disable);

        /* Clear the SysTick Counter 清零SysTick計(jì)數(shù)器*/

        SysTick_CounterCmd(SysTick_Counter_Clear);

        }

        void Delay(u32 nTime)

        {

        /* Enable the SysTick Counter 允許SysTick計(jì)數(shù)器*/

        SysTick_CounterCmd(SysTick_Counter_Enable);

        TimingDelay = nTime;

        while(TimingDelay != 0)

        ; //等待計(jì)數(shù)至0

        /* Disable the SysTick Counter 禁止SysTick計(jì)數(shù)器*/

        SysTick_CounterCmd(SysTick_Counter_Disable);

        /* Clear the SysTick Counter 清零SysTick計(jì)數(shù)器*/

        SysTick_CounterCmd(SysTick_Counter_Clear);

        }

        中斷函數(shù),定時(shí)器減至零時(shí)調(diào)用,放在stm32f10x_it.c文件中

        view plaincopy to clipboardprint?

        void SysTickHandler(void)

        {

        TimingDelay--;

        }

        塵埃粒子計(jì)數(shù)器相關(guān)文章:塵埃粒子計(jì)數(shù)器原理

        上一頁 1 2 下一頁

        評(píng)論


        相關(guān)推薦

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

        關(guān)閉
        主站蜘蛛池模板: 通许县| 安康市| 甘泉县| 湛江市| 九台市| 方城县| 定安县| 黄骅市| 武川县| 页游| 镇康县| 惠州市| 峡江县| 满城县| 门源| 宁远县| 昌平区| 北海市| 临西县| 昌乐县| 瓮安县| 景德镇市| 宜兰县| 沙洋县| 绵阳市| 融水| 福建省| 韶关市| 渭南市| 久治县| 天津市| 洪泽县| 连城县| 清流县| 鱼台县| 东宁县| 龙南县| 卢龙县| 榆中县| 梅州市| 慈溪市|