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.

请教CC2540/1检测引脚电平的问题



我想在simpleBLEperipheral例程里加入对P0_0和P0_2两个引脚的电平变化检测功能,问题如下:

1.我是该直接用单片机的寄存器中断检测电平变化啊,还是该在osal里的hal_key.c里修改相应引脚?哪种比较好?

2.假如直接用中断检测.P0_0和P0_2能否共用一个中断函数?

void InitAntiIO(void)
{
    P0DIR &= 0x00;   //P0定义为输入
    P0_0 = 0;             //初始低电平
    P0_2 = 0;            //初始低电平
    P0IEN |= 0x05;    // P0.0和P0.2 设置为中断方式 1:中断使能
    PICTL |= 0x0;    //下降沿触发  0x0上升沿触发       
    IEN1 |= 0x20;    //允许P0口中断;
    P0IFG = 0x00;    //初始化中断标志位
    EA = 1;          //打开总中断
}

 

/****************************************************************************
* 名    称: P0_ISR(void) 中断处理函数
* 描    述: #pragma vector = 中断向量,紧接着是中断处理程序
****************************************************************************/
#pragma vector = P0INT_VECTOR   
__interrupt void P0_ISR(void)
{
    DelayMS(10);     //延时去抖
    LED1 = ~LED1;    //改变LED1状态
    P0IFG = 0;       //清中断标志
    P0IF = 0;        //清中断标志
}

#endif

3. 有没有什么好的例子或方法了?