拿到了团购的板子了!!高兴下!~~嘻嘻。刚才在跑官方的这段例程:
// MSP430G2xx1 Demo - Reset on Invalid Address fetch, Toggle P1.0//// Description: 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 MSP430F21x1 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.// In contrast, an MSP430F1xx device will "jmp $" stopping code execution with// no LED flash.// ACLK = n/a, MCLK = SMCLK = default DCO//// MSP430G2xx1// -----------------// /|| XIN|-// | | |// --|RST XOUT|-// | |// | P1.0|-->LED//// H. Grewal / M. Buccini// Texas Instruments Inc.// October 2010// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10//******************************************************************************
#include <msp430g2231.h>
void main(void){ WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR |= 0x01; // Set P1.0 to output direction TAR = 0x3FFF; // Opcode for "jmp $"
for (;;) { volatile unsigned int i;
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
i = 50000; // Delay do (i--); while (i != 0); ((void (*)())0x170)(); // Invalid fetch ("call #0170h") }}
对里面的这句代码不大理解:((void (*)())0x170)(); // Invalid fetch ("call #0170h")
猜想这个应该是函数函数指针之类的操作。使程序跳转到0x170初,也就是中断向量处,为了验证我的想法,我使用函数指针写了下面这段代码,
int (*funp)(void); funp=0x170; funp();像这样的一段代码我在keil下编译是没有问题的,函数能正确跳转到0x170处执行,但在IAR下就不行了。提示错误:
Error[Pe513]: a value of type "int" cannot be assigned to an entity of type "int (*)(void)" C:UsersAdministratorDesktoplaunchpad projectmain.c 47
请问这是什么问题呢?要怎么解决?也就是说,我要在IAR里使用函数指针应该怎么做呢?哪位大大帮我分析这例程里的那句 ((void (*)())0x170)();
初学菜鸟什么不懂,还请指教啊!!
此帖出自
小平头技术问答
赞同
void (*)()声明的是一个指向函数类型的指针
((void (*)())加了一个括号是强制类型转换
((void (*)())0x170)给这个函数指针赋值0x170
((void (*)())0x170)()就是调用该地址的函数了
参考资料:
让你不再害怕指针
http://bbs.eeworld.com.cn/viewthread.php?tid=94348
一周热门 更多>