#include <msp430x14x.h>
void delay(unsigned int x)
{
unsigned int i,j;
for(i=x;i>0;i--)
for(j=1000;j>0;j--);
}
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;
//TIMER_A相关设置
CCTL0 = CCIE;
// CCR0 = 2047; //设定周期0.5S
CCR0=60000;
TACTL = TASSEL_1 + ID_3 + MC_1; //定时器A的时钟源选择ACLK,增计数模式
P2DIR |=0xff; //设置P2方向为输出
P1DIR=0X00;
P1IES=0xff;
P1IE=0XFF;
_EINT(); //使能全局中断
while(1)
{
P2OUT=0XFF;
}
}
#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
_EINT();
P2OUT=0XFD;
delay(1000);
}
#pragma vector=PORT1_VECTOR
__interrupt void timer()
{
unsigned char temp;
if((P1IFG&0X0F)!=0X0F)
{
temp=P1IFG;
switch(temp)
{
case 1 :P2OUT=0XEF;break;
case 2 :P2OUT=0XDF;break;
case 4 :P2OUT=0XBF;break;
case 8 :P2OUT=0X7F;break;
}
}
delay(100);
P1IFG=0X00;
}
|