您的位置:首页 > 其它

嵌入式成长轨迹45【Zigbee项目】【CC2430基础实验】【外部中断】

2012-09-01 18:04 471 查看
PICTL (0x8C) – Port Interrupt Control
PICTL |= 0X11;
7 - 0 R0 Not used
6 PADSC Strength control for port pads in output mode. Selects output drive capability to account for low I/O supply voltage on pin DVDD.
0 Minimum drive capability
1 Maximum drive capability
5 P2IEN Port 2, inputs 4 to 0 interrupt enable. This bit enables interrupt requests for the port 2 inputs 4 to 0.
0 Interrupts are disabled
1 Interrupts are enabled
4 P0IENH Port 0, inputs 7 to 4 interrupt enable. This bit enables interrupt requests for the port 0 inputs 7 to 4.
0 Interrupts are disabled
1 Interrupts are enabled
3 P0IENL Port 0, inputs 3 to 0 interrupt enable. This bit enables interrupt requests for the port 0 inputs 3 to 0.
0 Interrupts are disabled
1 Interrupts are enabled
2 P2ICON Port 2, inputs 4 to 0 interrupt configuration. This bit s selects the interrupt request condition for all port 2 inputs
0 Rising edge on input gives interrupt
1 Falling edge on input gives interrupt
1 P1ICON
Port 1, inputs 7 to 0 interrupt configuration. This bit selects the interrupt request condition for all port 1 inputs
0 Rising edge on input gives interrupt
1 Falling edge on input gives interrupt
0 P0ICON Port 0, inputs 7 to 0 interrupt configuration. This bit selects the interrupt request condition for all port 0 inputs
0 Rising edge on input gives interrupt
1 Falling edge on input gives interrupt

IEN1 (0xB8) – Interrupt Enable 1
IEN1 |= 0X20; // P0IE = 1
7:6 - 00 R0 Not used. Read as 0
5 P0IE
P0IE – Port 0 interrupt enable
0 Interrupt disabled
1 Interrupt enabled
4 T4IE T4IE - Timer 4 interrupt enable
0 Interrupt disabled
1 Interrupt enabled
3 T3IE T3IE - Timer 3 interrupt enable
0 Interrupt disabled
1 Interrupt enabled
2 T2IE T2IE – Timer 2 interrupt enable
0 Interrupt disabled
1 Interrupt enabled
1 T1IE T1IE – Timer 1 interrupt enable
0 Interrupt disabled
1 Interrupt enabled
0 DMAIE DMAIE – DMA transfer interrupt enable
0 Interrupt disabled
1 Interrupt enabled

P0IFG (0x89) – Port 0 interrupt status flag
7:0 P0IF[7:0] Port 0, inputs 7 to 0 interrupt status flags. When an input port pin has an interrupt request pending, the corresponding flag bit will be set.

//main.c
#include <ioCC2430.h>

#define RLED P1_0
#define GLED 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 = 0;
GLED = 1;

P0SEL&=~0X60;
P0DIR&=~0X60;

P0INP|=0X60;//有上拉、下拉

/*
P1IEN |= 0X0c;   //P12 P13
PICTL |= 0X02;   //下降沿
*/
PICTL |= 0X11;   //P0口中断允许,下降沿触发

EA = 1;
//IEN2 |= 0X10;   // P1IE = 1;
IEN1 |= 0X20;   // P0IE = 1

//P1IFG &= ~0x0C;   //P12 P13中断标志清0
P0IFG &= ~0x60;   //P05 P06中断标志清0
};

/*****************************************
//主函数
*****************************************/
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 = P0INT_VECTOR
__interrupt void P0_ISR(void)
{
if(P0IFG>0)         //按键中断
{
P0IFG = 0;
GLED = GLED;
RLED = !RLED;
}
P0IF = 0;          //清中断标志
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐