新编的程序,目的是通过3个摁键将msp430g2553上的P1.0和P1.6口的LED灯点亮,但问什么1.1和1.2可以1.3不行
#include"msp430g2553.h"#definekeyin0(P1IN&0x0e)//#definekeyin1(P1IN&BIT1)//#definekey...
#include "msp430g2553.h"
#define keyin0 (P1IN&0x0e)
//#define keyin1 (P1IN&BIT1)
//#define keyin2 (P1IN&BIT2)
void delay(void);
int main(void)
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P1DIR = ~0x0e;//~(BIT0+BIT1+BIT2)
P1REN |= 0x0e;
P1OUT =0x0e;
while(1)
{
if(keyin0 ==0x02)
{
delay();
if(keyin0 ==0x02)
{
P1OUT^=0X40;
delay();
while(keyin0 ==0x02);
}
}
else if(keyin0 ==0x04)
{
delay();
if(keyin0 ==0x04)
{
P1OUT^=0X01;
delay();
while(keyin0 ==0x04);
}
}
else if(keyin0 !=0x08)
{
delay();
if(keyin0 !=0x08)
{
P1OUT^=0X40;
delay();
while(keyin0 !=0x08);
}
}
}
}
void delay(void)
{
unsigned int i;
for(i=18000; i>0; i--);
}
第二个else打错了,应该是
else if(keyin0 ==0x08)
{
delay();
if(keyin0 ==0x08)
{
P1OUT^=0X40;
delay();
while(keyin0 ==0x08);
}
} 展开
#define keyin0 (P1IN&0x0e)
//#define keyin1 (P1IN&BIT1)
//#define keyin2 (P1IN&BIT2)
void delay(void);
int main(void)
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P1DIR = ~0x0e;//~(BIT0+BIT1+BIT2)
P1REN |= 0x0e;
P1OUT =0x0e;
while(1)
{
if(keyin0 ==0x02)
{
delay();
if(keyin0 ==0x02)
{
P1OUT^=0X40;
delay();
while(keyin0 ==0x02);
}
}
else if(keyin0 ==0x04)
{
delay();
if(keyin0 ==0x04)
{
P1OUT^=0X01;
delay();
while(keyin0 ==0x04);
}
}
else if(keyin0 !=0x08)
{
delay();
if(keyin0 !=0x08)
{
P1OUT^=0X40;
delay();
while(keyin0 !=0x08);
}
}
}
}
void delay(void)
{
unsigned int i;
for(i=18000; i>0; i--);
}
第二个else打错了,应该是
else if(keyin0 ==0x08)
{
delay();
if(keyin0 ==0x08)
{
P1OUT^=0X40;
delay();
while(keyin0 ==0x08);
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询