打印

MSP430学习小记~~~~关于在IAR环境下使用MSP的中断。

[复制链接]
5964|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
G21372|  楼主 | 2012-3-19 17:02 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
前段时间一直用CCS,但是机器太差(06 年的笔记本),启动一次CCS的调试需要近2分钟。。。。。:funk:   于是换IAR5.10,速度确实提升不少。。。。。


今天使用IAR新建的工程调试MSP430的IO中断程序。整个中断程序如下:


//#include "msp430.h"
//#include "io430.h"

#include "io430G2211.h"
#include "in430.h"

void delay()
{
  int i;
  for(i=0;i<6553;i++);
  for(i=0;i<6553;i++);
}
void blink(void)
{
           P2OUT = 0x00;
           delay();
      P2OUT = 0xFF;
           delay();
}
int main( void )
{
  // Stop watchdog timer to prevent time out reset

  WDTCTL = WDTPW + WDTHOLD;
  P2SEL = 0x00;                        // P1.0 = TACLK input, P1.7 = CAOUT
  P2DIR = 0xc0;  

  P2OUT = 0x00;




  P1DIR = 0x00;
  P1SEL = 0x00;
  P1REN = 0x08;
  P1OUT = 0x08;


  P1IE  = 0xff;   //interrupt enable
  P1IES = 0xff;   //set the high to low interrupt the P1.3
  P1IFG=0;//CLEAR INTERRUPT AT P1.3
  _BIS_SR(LPM0_bits+GIE);



  //GIE = aa;;
while(1);
}

#pragma vector=PORT1_VECTOR
__interrupt void P1VECTOR(void)
{
  //if(P1IFG&0x08!=0)
// {
unsigned j=0;
while(j<30)
{
    blink();
    j++;
}
P1IFG=0;//CLEAR INTERRUPT AT P1.3
}

简单说来,该程序使用P1.3作为IO中断输入,当有按键触发中断时跳入到中断处理函数中,使LED灯闪烁30次。。。。

P1IE  = 0xff;   //interrupt enable
  P1IES = 0xff;   //set the high to low interrupt the P1.3
  P1IFG=0;//CLEAR INTERRUPT AT P1.3
  _BIS_SR(LPM0_bits+GIE);   //open interrupt flag in SR reg.

最关键的也就是这4句话,前面三句表示的是打开对应的IO中断,最后一句是置SR寄存器中的GIE位,打开430的中断总开关。

也就是这句话出问题了,IAR弹出错误:

Error[e46]: Undefined external "_BIS_SR" referred in main ( F:\temp\iarbegin\Debug\Obj\main.r43 )

也就是说_BIS_SR没有定义。。。但是很多官方的例子里面都是使用_BIS_SR的啊!问题出在哪呢??看到工程上部的4个头文件


//#include "msp430.h"
//#include "io430.h"
#include "io430G2211.h"
#include "in430.h"


IAR新建工程时,默认使用的头文件是IO430.h,当我们把这个头文件换成msp430.h上述错误就消失了,中断正常响应。。。
于是我们继续查找这两个头文件的不同,发现msp430.h中会包含IN430.H头文件,而IO430.H中没有包含IN430.H这个文件。打开IN430.H,哈哈,我们要找的东西全在里面,除了刚才说的_BIS_SR外,我们还可以使用_EINT()  等CCS中常用的函数了。。


#ifndef __IN430_H
#define __IN430_H

#ifndef _SYSTEM_BUILD
  #pragma system_include
#endif

#include "intrinsics.h"
#pragma language=save
#pragma language=extended


/*
* Deprecated intrinsic functions.
*/
#ifdef __cplusplus
extern "C"
{
#endif
  /* Deprecated, please use "__bis_SR_register" instead. (If the
   * return value of this intrinsic is used, you can also use
   * "__get_SR_register".) */
  __intrinsic unsigned short _BIS_SR(unsigned short);
  /* Deprecated, please use "__bic_SR_register" instead. (If the
   * return value of this intrinsic is used, you can also use
   * "__get_SR_register".) */
  __intrinsic unsigned short _BIC_SR(unsigned short);
  /* Deprecated, please use "__bis_SR_register_on_exit" instead. (If
   * the return value of this intrinsic is used, you can also use
   * "__get_SR_register".) */
  __intrinsic unsigned short _BIS_SR_IRQ(unsigned short);
  /* Deprecated, please use "__bic_SR_register_on_exit" instead. (If
   * the return value of this intrinsic is used, you can also use
   * "__get_SR_register".) */
  __intrinsic unsigned short _BIC_SR_IRQ(unsigned short);
  /* Deprecated, please use the #pragma directive "bis_nmi_ie1"
   * instead. */
  __intrinsic unsigned short _BIS_NMI_IE1(unsigned short);
#ifdef __cplusplus
}
#endif

/*
* Convenience macros mapping old names to new.
*/
/* Deprecated, please use "__disable_interrupt" instead. */
#define _DINT()        __disable_interrupt()
/* Deprecated, please use "__enable_interrupt" instead. */
#define _EINT()        __enable_interrupt()
/* Deprecated, please use "__no_operation" instead. */
#define _NOP()         __no_operation()
/* Deprecated, please use "__op_code" instead. */
#define _OPC(x)        __op_code(x)
/* Deprecated, please use "__swap_bytes" instead. */
#define _SWAP_BYTES(x) __swap_bytes(x)

/* Deprecated, please use the keyword "__monitor" instead. */
#define monitor        __monitor
/* Deprecated, please use the keyword "__no_init" instead. */
#define no_init        __no_init
#pragma language=restore
#endif /* __IN430_H */

相关帖子

沙发
yangguangaisha| | 2012-3-19 17:08 | 只看该作者
大家顶起来。。 楼主辛苦了

使用特权

评论回复
板凳
gexingyouxian| | 2012-3-19 19:44 | 只看该作者
我也用的ccs感觉不熟悉,呵呵 看来换IAR是迟早的事了

使用特权

评论回复
地板
acer4736| | 2012-3-19 19:59 | 只看该作者
加上in430.h就好啦

使用特权

评论回复
5
jinpaidianzi| | 2012-3-19 20:11 | 只看该作者
要是能把in430.h进一步再进一步讲明白就好了


还有问问大侠们,谁比较过IAR和CCS编译出来的字节数一样么?那个效率高?

使用特权

评论回复
6
JF林| | 2013-5-21 11:04 | 只看该作者
学习了

使用特权

评论回复
7
1988020566| | 2013-5-21 23:58 | 只看该作者
还是ccs好用的。

使用特权

评论回复
8
liuyang8023| | 2014-3-13 08:22 | 只看该作者

使用特权

评论回复
9
强仔00001| | 2014-3-13 13:14 | 只看该作者
楼主赶快换电脑吧,现在这么便宜,我比较喜欢用IAR,很方便

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

197

主题

1658

帖子

5

粉丝