zoukankan      html  css  js  c++  java
  • MSP430F149看门狗及其应用

    1、概述

    看门狗有两个作用:1、可以防止程序跑飞,若程序跑飞可让单片机复位;2、可作为间隔时间发生器,在中断中进行定期刷新显示、读取数据等对外设的操作。

    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;

  • 相关阅读:
    C# HTTP系列9 GET与POST示例
    [译]Android Studio 3.6 新特性概览
    mysql error 1290 hy000:The MySQL server is running with the --skip-grant-tables option so it cannot execute this statemen' 解决方案
    mysql error 1130 hy000:Host 'localhost' is not allowed to connect to this mysql server 解决方案
    Windows+Apache2.4.10+PHP7.0+MySQL5.6.21安装
    php版本的选择
    PHP,Mysql根据经纬度计算距离并排序
    windows无法启动MySQL服务 错误1067
    PHP MYSQL 搜索周边坐标,并计算两个点之间的距离
    html5获取用户当前的地理位置,即经纬度。
  • 原文地址:https://www.cnblogs.com/yuesheng/p/2100115.html
Copyright © 2011-2022 走看看