请教IAR下函数指针的使用问题,

2019-03-24 15:35发布

拿到了团购的板子了!!高兴下!~~嘻嘻。刚才在跑官方的这段例程://   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)();  
初学菜鸟什么不懂,还请指教啊!!

此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
5条回答
sanbinabu
2019-03-24 19:48
< 没人回复么?~~~
((void (*)())0x170)();这句我是这样理解的:
void (*)() 表明的它将声明一个函数指针类型, 放在了 0x170前面使函数的执行地址为0x170。

今天又看了大半天msp的时钟系统,感觉真是很繁复难用啊! 大堆错综复杂的关系~~

一周热门 更多>

相关问题

    相关文章