Randy 发表于 2012-7-18 09:23:56

【大赛原创经验贴】P1口中断控制P2口LED灯点亮

用P1口的中断控制P2口的LED灯#include <msp430x24x.h>
#define uchar unsigned char
#define uint unsigned int
uchar table[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar key;

void delay(int v)   //延时
{
while(v!=0)
    v--;
}
void main()
{
WDTCTL=WDTPW+WDTHOLD;
P1DIR=0X00;
P2DIR=0XFF;
P1IFG=0X00;
P1IES=0XFF;
P1IE=0XFF;
P2OUT=0XFF;
_EINT();
while(1)
{
    P2OUT=table;
}
}
#pragma vector=PORT1_VECTOR
__interrupt void timer()
{
uchar temp;
delay(2666);
if((P1IN&0XFF)==0XFF)//判断是否有中断
{
    temp=P1IFG;
    switch(temp)
    {
    case 1:key=0 ;break;
    case 2:key=1 ;break;
    case 4:key=2 ;break;
    case 8:key=3 ;break;
    case 16 :key=4 ;break;
    case 32 :key=5 ;break;
    case 64 :key=6 ;break;
    case 128:key=7 ;break;
    }
}
P1IFG=0X00;
}

plantpark 发表于 2012-9-28 14:16:39

为什么看不明白呢?
页: [1]
查看完整版本: 【大赛原创经验贴】P1口中断控制P2口LED灯点亮