代码一:
/**********************************
程序功能:用按键控制LED灯熄灭
***********************************/
#include <msp430x14x.h> void int_clk();
void main()
{
WDTCTL = WDTPW + WDTHOLD;
int_clk();
P1DIR = 0Xf0;
P1OUT = 0Xff;
P6DIR = 0XFF;
P6OUT = 0x00;
while()
{
switch(P1IN & 0X0F)
{
case 0x0e:P6OUT = 0XC0;break;
case 0x0d:P6OUT = 0X30;break;
case 0x0b:P6OUT = 0X0C;break;
case 0x07:P6OUT = 0X03;break;
}
}
} void int_clk()
{
BCSCTL1 &= ~XT2OFF;
BCSCTL2 |= SELM_1 + SELS;
do
{
IFG1 &= ~OFIFG;
for(int i=;i>;i--)
_NOP();
}while((IFG1 & OFIFG)!=);
IFG1 &= ~OFIFG;
}
代码二:
#include <msp430x14x.h> void int_clk();
void delay(int i);
void main()
{
int_clk();
//initialize IO
P1DIR = 0XF0;
P1OUT = 0XFF;
P6DIR = 0XFF;
P6OUT = 0XFF; if(P1IN != 0X0F)
{
delay();
if(P1IN != 0X0F)
{
switch(P1IN & 0X0F)
{
case 0x0e:P6OUT = 0XFC;break;
case 0x0d:P6OUT = 0XF3;break;
case 0x0b:P6OUT = 0XCF;break;
case 0x07:P6OUT = 0X3F;break;
}
}
}
else
P6OUT = 0XFF;
} void int_clk()
{
BCSCTL1 &= ~XT2OFF;
BCSCTL2 |= SELM_1 + SELS;
do
{
IFG1 &= ~OFIFG;
for(int i=;i<;i++)
_NOP();
}while((IFG1 & OFIFG)!=);
IFG1 &= ~OFIFG;
} void delay(int i)
{
while(i--);
}