【TI首届低功耗设计大赛】+@fxyc87+第三课 GPIO中断操作
前三次讲了金刚狼开发板的开发环境,包括CCS,IAR以及一个简单的GPIO触摸实例
其实这个芯片默认输入就可以触摸的,无需其它设置,所有引脚均支持,若关闭只需开启上拉或下拉电阻即可
这次再来个教程
GPIO中断示例
以下所有代码均为本人原创
开发板演示方法:按下S2键,LED2亮
- #include "msp430fr5969.h"
- //by fxyc87@gmail.com
- int i=0;
- int main(void)
- {
- WDTCTL = WDTPW | WDTHOLD; //关闭看门狗
-
- P1OUT=0+BIT1; //初始化指示灯灭+S2上拉,关闭触摸,实体按键
- P1REN=BIT1; //上拉启用
- P1DIR = BIT0; //P1.0设置为输出
- P1IES = BIT1; //1>0 下降沿触发
- P1IE =BIT1; //P1.1开启中断
- PM5CTL0 &= ~LOCKLPM5; //启用GPIO配置
- P1IFG=0;//清除中断标志
- _EINT();//开启总中断
- while(1){
- if(i)
- P1OUT |= BIT0;
- else
- P1OUT&=~BIT0;
-
- }
- }
- #pragma vector=PORT1_VECTOR
- __interrupt void P1IV_ISR (void){
- if(P1IV&(BIT1*2)){
- i=1;
- //P1OUT^=BIT0;
- }
- P1IFG=0;
- }
解说:
#pragma vector=PORT1_VECTOR
这里是中断入口点,关于中断点,
可以在 "msp430fr5969.h"文件最尾部有声明
然后就是开启PXIE相应引脚及总中断_EINT()
P1IV为中断标志位,见手册354页说明或下方文字
引用: Port 1 interrupt vector value
00h = No interrupt pending
02h = Interrupt Source: Port 1.0 interrupt; Interrupt Flag: P1IFG.0; Interrupt
Priority: Highest
04h = Interrupt Source: Port 1.1 interrupt; Interrupt Flag: P1IFG.1
06h = Interrupt Source: Port 1.2 interrupt; Interrupt Flag: P1IFG.2
08h = Interrupt Source: Port 1.3 interrupt; Interrupt Flag: P1IFG.3
0Ah = Interrupt Source: Port 1.4 interrupt; Interrupt Flag: P1IFG.4
0Ch = Interrupt Source: Port 1.5 interrupt; Interrupt Flag: P1IFG.5
0Eh = Interrupt Source: Port 1.6 interrupt; Interrupt Flag: P1IFG.6
10b = Interrupt Source: Port 1.7 interrupt; Interrupt Flag: P1IFG.7; Interrupt
Priority: Lowest
中断就到这里,比较简单
休息三天,赶紧恶补这款芯片哦
我的其它贴子,大家可以在论坛中搜索 【TI首届低功耗设计大赛】+@fxyc87
来查找我发表的其它贴子
谢谢,看贴要回贴啰~