This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541中断



我想每次P1.6上升沿中断,读取P1.7脚位的状态,OSAL有没有相应的函数还是,开一个函数,像这样设置:

P0INP|=0x1<<6;

PICTL &=~(0x1<<2);

EA=0x1;

IEN2|=(0x1<<4);

P1IFG |=0;

P1DIR &=~(1<<7);

然后写中断函数

  • 没有直接的函数,可以自己写外部中断的初始化和中断函数.

    外部中断的一个完整例子

    #include <ioCC2540.h>

    #define RLED P1_0

    #define led2 P1_1

    #define uchar unsigned char

    #define uint unsigned int

    /*****************************************

    //函数声明

    *****************************************/

    void Delay(uint n);

    /*****************************************

    //io及LED初始化

    *****************************************/

    void Init_IO_AND_LED(void)

    {

       P1DIR = 0X03; //0为输入(默认),1为输入

       RLED = 1;

       led2 = 1;

       P0INP &= ~0X0c;//有上拉、下拉

       P1INP &= ~0X40; //选择上拉

       P0IEN |= 0X30;   //P04 P05

       PICTL |= 0X02;   //下降沿

       EA = 1;

       IEN1 |= 0X20;   // P0IE = 1;

       P0IFG |= 0x00;   //P12 P13

    };

    /*****************************************

    //主函数

    *****************************************/

    void main(void)

    {

       Init_IO_AND_LED();

       while(1)

       {

       };

    }

    /*****************************************

    //延时

    *****************************************/

    void Delay(uint n)

    {

     uint ii;

     for(ii=0;ii<n;ii++);

     for(ii=0;ii<n;ii++);

     for(ii=0;ii<n;ii++);

     for(ii=0;ii<n;ii++);

     for(ii=0;ii<n;ii++);

    }

    #pragma vector = P1INT_VECTOR

    __interrupt void P1_ISR(void)

    {

           if(P0IFG>0)         //按键中断

           {

             P0IFG = 0;

             RLED = !RLED;

           }

           P0IF = 0;          //清中断标志

    }

  • 你好 TY,我想知道IO口能不能设置成电平触发中断?如何设置?

  • 吃不消啊,弄个例程也这么混乱,又是P1,又是P0的