新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > NXP_LPC1114延時函數集合

        NXP_LPC1114延時函數集合

        作者: 時間:2016-11-29 來源:網絡 收藏
        #include "LPC11XX.h"
        #include "gpio.h"
        #include "timer16.h"
        /*系統時鐘配置為48MHz,AHB不分頻,一次定時器時鐘為48Mhz,因此得出以下分頻值,匹配值*/
        void Delay_Us(unsigned int DelayTimes)
        {
        /* * setup timer #1 for delay */
        //LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8); /*開啟定時器Timer16_1時鐘--時鐘配置中開啟該時鐘*/
        LPC_TMR16B1->TCR = 0x02; /* reset timer */
        LPC_TMR16B1->PR = 48; /* set prescaler to zero 根據AHB時鐘確定分頻值*/
        LPC_TMR16B1->MR0 = DelayTimes; /* 所需的延時時間 */
        LPC_TMR16B1->IR = 0xff; /* reset all interrrupts 復位所有的中斷*/
        LPC_TMR16B1->MCR = 0x04; /* stop timer on match --達到匹配停止*/
        LPC_TMR16B1->TCR = 0x01; /* start timer 啟動定時器*/
        while (LPC_TMR16B1->TCR & 0x01); /*等待直到時間到*/
        LPC_TMR16B1->TCR = 0x00; /* Close timer --關閉定時器*/
        }
        void Delay_Ms(unsigned int DelayTimes)
        {
        /* * setup timer #1 for delay */
        //LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8); //開啟定時器Timer16_1時鐘
        LPC_TMR16B1->TCR = 0x02; /* reset timer */
        LPC_TMR16B1->PR = 48000; /* set prescaler to zero */
        LPC_TMR16B1->MR0 = DelayTimes;
        LPC_TMR16B1->IR = 0xff; /* reset all interrrupts */
        LPC_TMR16B1->MCR = 0x04; /* stop timer on match */
        LPC_TMR16B1->TCR = 0x01; /* start timer */
        while (LPC_TMR16B1->TCR & 0x01); /*等待直到時間到*/
        LPC_TMR16B1->TCR = 0x00; /* Close timer */
        }
        void Delay_Sec(unsigned char DelayTimes)
        {
        /* * setup timer #1 for delay */
        //LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8); //開啟定時器Timer16_1時鐘
        LPC_TMR16B1->TCR = 0x02; /* reset timer */
        LPC_TMR16B1->PR = 48000000; /* set prescaler to zero */
        LPC_TMR16B1->MR0 = DelayTimes;
        LPC_TMR16B1->IR = 0xff; /* reset all interrrupts */
        LPC_TMR16B1->MCR = 0x04; /* stop timer on match */
        LPC_TMR16B1->TCR = 0x01; /* start timer */
        while (LPC_TMR16B1->TCR & 0x01); /*等待直到時間到*/
        LPC_TMR16B1->TCR = 0x00; /* Close timer */
        }


        關鍵詞: NXPLPC1114延時函

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 金湖县| 安丘市| 利津县| 东宁县| 南阳市| 合水县| 治多县| 教育| 山丹县| 富川| 林周县| 肥东县| 象山县| 前郭尔| 焉耆| 安多县| 湘乡市| 泊头市| 莱阳市| 镇巴县| 客服| 洞头县| 岳阳县| 柳州市| 甘谷县| 巍山| 永泰县| 崇义县| 福鼎市| 南昌市| 江西省| 兴安县| 永州市| 彭泽县| 青冈县| 砚山县| 泰宁县| 台东市| 万盛区| 长泰县| 志丹县|