新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > MSP430F149看門狗及其應用

        MSP430F149看門狗及其應用

        作者: 時間:2016-11-27 來源:網絡 收藏
        1、概述

        看門狗有兩個作用:1、可以防止程序跑飛,若程序跑飛可讓單片機復位;2、可作為間隔時間發生器,在中斷中進行定期刷新顯示、讀取數據等對外設的操作。

        本文引用地址:http://www.104case.com/article/201611/322342.htm

        2、設置

        不需要看門狗時可用軟件關閉,設置:WDTCTL = WDTPW + WDTHOLD;

        為防止誤觸發操作WDTCTL需要先寫入WDTPW。

        作為間隔定時器時詳細操作可見MSP430F149.H文件中的宏定義。

        3、相關寄存器

        1、WDTCTL Watchdog Timer Register

        WDTPW Bits

        15-8

        Watchdog timer password. Always read as 069h. Must be written as 05Ah, or

        a PUC will be generated.

        WDTHOLD Bit 7 Watchdog timer hold. This bit stops the watchdog timer. Setting WDTHOLD= 1 when the WDT is not in use conserves power.

        0 Watchdog timer is not stopped

        1 Watchdog timer is stopped

        WDTTMSEL Bit 4 Watchdog timer mode select

        0 Watchdog mode

        1 Interval timer mode

        WDTCNTCL Bit 3 Watchdog timer counter clear. Setting WDTCNTCL = 1 clears the count value

        to 0000h. WDTCNTCL is automatically reset.

        0 No action

        1 WDTCNT = 0000h

        2、IE1 Interrupt Enable Register 1

        WDTIE Bit 0 Watchdog timer interrupt enable. This bit enables the WDTIFG interrupt for

        interval timer mode. It is not necessary to set this bit for watchdog mode.

        Because other bits in IE1 may be used for other modules, it is recommended

        to set or clear this bit using BIS.B or BIC.B instructions, rather than MOV.B

        or CLR.B instructions.

        0 Interrupt not enabled

        1 Interrupt enabled

        4、設計實例

        4.1 利用WDT定時模式在中斷函數中定時操作外設

        說明:#define WDT_MDLY_32 (WDTPW+WDTTMSEL+WDTCNTCL)

        void main(void)

        {

        WDTCTL = WDT_MDLY_32; // Set Watchdog Timer interval to ~30ms

        IE1 |= WDTIE; // Enable WDT interrupt

        P2DIR |= 0x01; // Set P1.0 to output direction

        _BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt

        }

        // Watchdog Timer interrupt service routine

        #pragma vector=WDT_VECTOR

        __interrupt void watchdog_timer(void)

        {

        P2OUT ^= 0x01; // Toggle P1.0 using exclusive-OR

        }

        4.2 利用WDT定時模式延時

        WDTCTL = WDT_ADLY_1000;//延時1000ms

        //延時2s

        for(i = 0; i < 3; i++)

        {

        IFG1 &= ~WDTIFG;

        while(!(IFG1 & WDTIFG));

        }

        IFG1 &= ~WDTIFG;



        關鍵詞: MSP430F149看門

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 铁力市| 苏尼特右旗| 禹州市| 金阳县| 乐昌市| 北京市| 洪湖市| 都安| 广宁县| 霸州市| 阿城市| 加查县| 荥经县| 普格县| 轮台县| 东辽县| 保亭| 那曲县| 南宁市| 铜陵市| 淮北市| 绥芬河市| 商都县| 天水市| 当雄县| 沭阳县| 元朗区| 湖南省| 象山县| 梓潼县| 武陟县| 永靖县| 明溪县| 万宁市| 专栏| 漠河县| 临江市| 克什克腾旗| 名山县| 东方市| 保康县|