Quantcast
Channel: MSP 低功耗微控制器论坛 - 最近的话题
Viewing all articles
Browse latest Browse all 3634

请问我现在有一个按键中断程序,我想在按键中断时,打开定时器和定时器中断,应该怎么写呢?

$
0
0

我希望在按键中断中,拉高P1.7,同时定时一分钟,一分钟后拉低P1.7,该怎么写呢?

我目前的代码如下:

#include"msp430g2553.h"

void delay(int time)
{
static int i,j;

for(i=0;i<time;i++)
{ for(j=0;j<128;j++);}

}

void InitIOInterrupt()
{
P1DIR &= ~BIT3;//设置P1.3为输入
P1REN |= BIT3;//启用P1.3电阻
P1OUT |= BIT3;//设置上拉电阻
P1IES |= BIT3;//P1.3中断边缘选择
P1IE |= BIT3;//P1.3中断使能
P1IFG = 0x00;//清除中断标识
}

void InitLed()
{
P1DIR |= BIT7;//设置BIT7为输出

P1OUT &= 0x00; //设置BIT7低电平
}

#pragma vector=PORT1_VECTOR //按键中断
__interrupt void PORT1_ISR(void)
{
static int k;
delay(50);
P1OUT = 0x80;//P1.7置高
P1IFG = 0;//清除中断标识

}

void main()
{

WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
//DCOCTL = CALDCO_1MHZ;
//BCSCTL1 = CALBC1_1MHZ;
InitLed(); //初始化输出端口
InitIOInterrupt(); //初始化IO中断
_EINT(); //开总中断
while(1);

}


Viewing all articles
Browse latest Browse all 3634

Trending Articles