308995000 发表于 2011-10-15 16:16:55

求教! ————————关于MSP430F5438 中的 WDT !

代码 如下
//******************************************************************************
//MSP430F54x Demo - Reset on Invalid Address fetch, Toggle P1.0
//
//Description: This program demonstrates how a reset is executed if the CPU
//tries to fetch instructions from within the module register memory address
//range (0x0100 --0x0FEF) or from within unused address ranges. Toggle P1.0
//by xor'ing P1.0 inside of a software loop that ends with TAR loaded with
//3FFFh - op-code for "jmp $". This simulates a code error. The MSP430F5438
//will force a reset because it will not allow a fetch from within the address
//range of the peripheral memory, as is seen by return to the mainloop and
//LED flash.
//ACLK = n/a, MCLK = SMCLK = default DCO ~1.045MHz
//
//                MSP430F5438
//             -----------------
//         /|\|               |
//          | |               |
//          --|RST            |
//            |               |
//            |             P1.0|-->LED
//
//   W. Goh
//   Texas Instruments Inc.
//   November 2008
//   Built with CCE Version: 3.2.2 and IAR Embedded Workbench Version: 4.11B
//******************************************************************************
#include "msp430x54x.h"

void main(void)
{
WDTCTL = WDTPW + WDTHOLD;               // Stop watchdog timer - SET BREAKPOINT HERE
P1DIR |= 0x01;                            // Set P1.0 to output direction
TA0R = 0x3FFF;                            // Valid opcode (for "jmp $")

while(1)
{
    P1OUT ^= 0x01;                        // Toggle P1.0 using exclusive-OR

    __delay_cycles(50000);                  // Delay loop

    // C code to directly call an address location
    ((void (*)())0x350)();                  // Invalid fetch ("call #0350h")

    /* 0x350 is address of TA0R register and is within the module register memory
    address range (0x0100 --0x0FEF) */
}
}


这段代码 有点 不懂啊、、、
谁能帮帮我理解理解呢。。

changhui0222 发表于 2011-10-15 17:00:24

这个有什么问题么?
只是TA1CCR0没有自动装载而已。
另外MSP430的TIMER用法很灵活,看下手册上面操作方法和图就会很清楚。

void_main 发表于 2011-11-2 21:17:24

msp430采用的是统一编址方式,也就把ROM、RAM、外围模块、特殊功能寄存器等等安排到统一地址空间,这样就可以使用一组地址、数据总线、相同的指令对它们进行字或字节的形式访问(这点有别于传统的处理器如8086、51等),该例子所要说明的就是程序的非法跳转问题。((void (*)())0x350)()汇编之后就是JMP 0x350;按照常理,程序此时应该跳转到0x350这个存储空间去执行,但是对于msp430来说这个空间是特殊功能寄存器区,并不是程序存储区,所以这个访问是非法的,结果就是造成单片机复位,程序重新执行,但是看上去程序就像主循环体内执行一样。
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;               // 停止看门狗定时器
P1DIR |= 0x01;                            // 设置P1.0为输出
TA0R = 0x3FFF;                            // 有效执行代码(相当于 "jmp $")(虽然存入了这个代码,但并不会被实际执行)

while(1)
{
    P1OUT ^= 0x01;                        // 通过异或运算对P1.0取反

    __delay_cycles(50000);                  // 延时循环

    // 通过C代码调用该地址
    ((void (*)())0x350)();                  // 无效访问("调用 #0350h")会造成单片机复位,并不会读取里面的内容

    /* 0x350 是TA0R 寄存器的地址并且在外围模块存储区
    地址范围为(0x0100 --0x0FEF) */
}
}

jlhgold 发表于 2011-11-2 22:16:11

回复【2楼】void_main乾乾
-----------------------------------------------------------------------

就是这个意思 难道LZ不看上面那段说明性的文字么?

QQ_PPt 发表于 2011-11-4 11:03:22

我现在都不会用看门狗。。。。唉,真悲催。。。。

pangfuhua 发表于 2011-11-5 10:42:02

楼主要先看看芯片手册中的各个模块~~

kingheimer 发表于 2011-11-7 09:45:14

顶2楼的解释

308995000 发表于 2011-11-16 09:04:00

回复【2楼】void_main 乾乾
-----------------------------------------------------------------------

非常 感谢!!!
页: [1]
查看完整版本: 求教! ————————关于MSP430F5438 中的 WDT !