惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
Microsoft Security Blog
Microsoft Security Blog
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Last Week in AI
Last Week in AI
罗磊的独立博客
腾讯CDC
云风的 BLOG
云风的 BLOG
月光博客
月光博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
宝玉的分享
宝玉的分享
U
Unit 42
I
InfoQ
D
DataBreaches.Net
Blog — PlanetScale
Blog — PlanetScale
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
美团技术团队
IT之家
IT之家
Stack Overflow Blog
Stack Overflow Blog
F
Fortinet All Blogs
GbyAI
GbyAI
S
SegmentFault 最新的问题

博客园 - zelu

质量工程读书笔记 - 零缺陷管理的基本原则 质量工程读书笔记 - 品质部的职责 Arduino SoftwareSerial + CO2传感器模组MH-Z14 质量工程读书笔记 - 精益生产 质量工程读书笔记 - 预防为主的质量管理系统 质量工程读书笔记 - 优秀经理人的潜质 质量工程读书笔记 - 经理人的修炼 质量工程读书笔记 - 产品检验 质量工程读书笔记 - 质量工程师的工作 距离 Restart MSP430G2553 Launchpad 硬件I2C驱动 MSP430G2553 模数转换器 ADC10 MSP430 G2553 Launchpad实现电容测量 MSP430 G2553 比较器Comparator_A+、数据流程图DFD、状态转换图STD MSP430 G2553 低功耗模式LPMx MSP430 G2553 计时/计数器 Timer_A MSP430 G2553 基本时钟模块+ (Basic Clock Module+) MSP430 G2553 LaunchPad设置GPIO
MSP430 G2553 LaunchPad GPIO中断
zelu · 2015-06-07 · via 博客园 - zelu

P1、P2端口上的每个管脚都支持外部中断。P1端口的所有管脚都对应同一个中断向量(Interrupt Vector),类似的,P2端口的所有管脚都对应另一个中断向量;通过PxIFG寄存器来判断中断来源于具体哪个管脚。

相关的寄存器如下表所示。

  Register                           Short Form       Register Type       Initial State          
  Interrupt Flag   PxIFG   Read/write   Reset with PUC
  Interrupt Edge Select   PxIES   Read/write   Unchanged
  Interrupt Enable   PxIE   Read/write   Reset with PUC

PxIFG:中断标志,1表示有中断事件待处理

PxIES:中断边沿选择,0表示上升沿触发,1表示下降沿触发

PxIE:GPIO中断使能,0表示禁用,1表示使能

程序示例

利用板上S2按键控制LED1灯闪烁,每按下一次,LED1灯闪烁一次。该程序还缺少按键消抖的功能。(G2 LaunchPad Rev1.5上P1.3没有连接电容及上拉电阻)

 1 #include "io430.h"
 2 
 3 #define LED1 BIT0
 4 #define PUSH2 BIT3
 5 
 6 //function declarations
 7 void delay(void);
 8 
 9 void main(void)
10 {
11     // Stop watchdog timer to prevent time out reset
12     WDTCTL = WDTPW + WDTHOLD;
13     
14     //set P1.3 to input with pullup
15     P1OUT = 0;
16     P1OUT |= PUSH2; //initialize the pullup state
17     P1REN |= PUSH2; //enable internal pullup
18     
19     //set P1.0 to output
20     P1DIR |= LED1; //P1.0 out to LED1, P1.3 remains input for PUSH2 button
21     
22     //set the interrupt registers
23     P1IES |= PUSH2; //select high -> low transition
24     P1IFG &= ~PUSH2; //clear the flag for P1.3 before enabling the interrupt,
25     // to prevent an immediate interrupt
26     P1IE |= PUSH2; //enable interrupt for P1.3
27     
28     __enable_interrupt(); //turn on the interrupts
29     
30     while(1)
31     {
32     }
33 
34 }
35 
36 void delay(void)
37 {
38     volatile unsigned int i;
39     for(i = 0; i < 50000; i++);
40 }
41 
42 //interrupt service routines
43 #pragma vector  = PORT1_VECTOR
44 __interrupt void P1_ISR(void)
45 {
46     if((P1IFG & PUSH2) == PUSH2)
47     {
48         P1IFG &= ~PUSH2; //clear the interrupt flag
49         
50         P1OUT |= LED1; //turn on LED1
51         delay();
52         P1OUT &= ~LED1; //turn off LED1
53     }
54     else
55     {
56         P1IFG = 0;
57     }
58 }