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

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.

 1 //main.c
 2 #include <ioCC2430.h>
 3 
 4 #define RLED P1_0
 5 #define GLED P1_1
 6 
 7 #define uchar unsigned char
 8 #define uint unsigned int
 9 
10 /*****************************************
11 //函数声明
12 *****************************************/
13 void Delay(uint n);
14 
15 /*****************************************
16 //io及LED初始化
17 *****************************************/
18 void Init_IO_AND_LED(void)
19 {
20     P1DIR = 0X03; //0为输入(默认),1为输出
21     RLED = 0;
22     GLED = 1;
23     
24     P0SEL&=~0X60;
25     P0DIR&=~0X60;
26     
27     P0INP|=0X60;//有上拉、下拉
28 
29     /*
30     P1IEN |= 0X0c;   //P12 P13
31     PICTL |= 0X02;   //下降沿
32     */
33     PICTL |= 0X11;   //P0口中断允许,下降沿触发
34 
35     EA = 1;
36     //IEN2 |= 0X10;   // P1IE = 1;
37     IEN1 |= 0X20;   // P0IE = 1
38 
39     //P1IFG &= ~0x0C;   //P12 P13中断标志清0
40     P0IFG &= ~0x60;   //P05 P06中断标志清0
41 };
42 
43 /*****************************************
44 //主函数
45 *****************************************/
46 void main(void)
47 {
48     Init_IO_AND_LED();
49     while(1)
50     {
51     };
52 }
53 
54 /*****************************************
55 //延时
56 *****************************************/
57 void Delay(uint n)
58 {
59   uint ii;
60   for(ii=0;ii<n;ii++);
61   for(ii=0;ii<n;ii++);
62   for(ii=0;ii<n;ii++);
63   for(ii=0;ii<n;ii++);
64   for(ii=0;ii<n;ii++);
65 }
66 
67 /*********************************************************************
68 //中断服务程序
69 *********************************************************************/
70 #pragma vector = P0INT_VECTOR
71  __interrupt void P0_ISR(void)
72  {
73         if(P0IFG>0)         //按键中断
74         {
75           P0IFG = 0;
76           GLED = GLED;
77           RLED = !RLED;
78         }
79         P0IF = 0;          //清中断标志
80  }
原文地址:https://www.cnblogs.com/zeedmood/p/2666914.html