Quantcast
Channel: 蓝牙论坛 - 最近的话题
Viewing all articles
Browse latest Browse all 7515

2541中断问题

$
0
0

各位大神们

                 大家好

我想请问一下有没有KeyFob中断的解释。我想解决一下中断的问题,但是在网上搜索的一些东西在协议栈中都找不到。

比如这样的:

                     

示例程序:按键控制LED灯

1 /******************************************************************************
2 *文 件 名:KEY.c
3 *作 者:陈照
4 *时 间:2015-04-23
5 *版 本:1.0
6 *描 述:按键中断方式控制流水灯
7 ******************************************************************************/
8 #include <iocc2541.h>
9 #include "delay.h"
10
11 typedef unsigned char uchar;
12 typedef unsigned int uint;
13
14 #define LED1 P1_0
15 #define LED2 P1_1
16 #define LED3 P1_4
17 #define KEY P0_1
18
19 /******************************************************************************
20 *函 数 名:InitLED
21 *功 能:LED灯初始化
22 *入口参数:mode,mode为1则点亮所有LED,mode为0则熄灭所有LED
23 *出口参数:无
24 ******************************************************************************/
25 void InitLED(uchar mode)
26 {
27 P1SEL &= ~0x13; //P1.0,P1.1,P1.4设置为通用I/O口
28 P1DIR |= 0x13; //P1.0,P1.1,P1.4设置为输出
29 LED1 = mode; //LED灯亮熄控制
30 LED2 = mode;
31 LED3 = mode;
32 }
33
34 /******************************************************************************
35 *函 数 名:InitKey
36 *功 能:按键中断初始化
37 *入口参数:无
38 *出口参数:无
39 ******************************************************************************/
40 void InitKey(void)
41 {
42 P0SEL &= ~0x02; //P0.1设置为通用I/O口
43 P0DIR &= ~0x02; //P0.1设置为输入
44 P0IFG &= ~0x02; //P0.1中断状态标志位清0
45 PICTL |= 0x00; //P0端口下降沿触发
46 P0IEN |= 0x02; //P0.1中断使能
47 IEN1 |= 0x20; //端口P0中断使能
48 EA = 1; //开总中断
49 }
50
51 /******************************************************************************
52 *函 数 名:P0_ISR
53 *功 能:中断服务子程序
54 *入口参数:无
55 *出口参数:无
56 ******************************************************************************/
57 #pragma vector = P0INT_VECTOR
58 __interrupt void P0_ISR(void)
59 {
60 if(0x02 & P0IFG) //判断按键中断
61 {
62 LED1 = !LED1; //流水灯
63 Delay1ms(1000); //延时1s
64 LED2 = !LED2;
65 Delay1ms(1000);
66 LED3 = !LED3;
67 Delay1ms(1000);
68 }
69 P0IFG = 0; //清中断标志
70 P0IF = 0; //清中断标志,IRCON[5],P0口中断
71 }
72
73 /******************************************************************************
74 *程序入口函数
75 ******************************************************************************/
76 int main(void)
77 {
78 InitLED(0); //LED初始化,熄灭LED1~3
79 InitKey(); //按键中断初始化
80
81 while(1)
82 {
83 }
84 }


Viewing all articles
Browse latest Browse all 7515

Trending Articles