#include char led[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
void delay()
{
unsigned int i;
for(i=0;i<50000;i++);
}
void main()
{
unsigned int k=0;
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗
P2DIR = 0xff;
for(;;k++)
{ if(k==8)
k=0; P2OUT = led[k];
delay();
P2OUT = 0x00;
delay(); }
} 下面学习BCSCTL2的调节系统时钟。求懂的人拜师 程序二 #include "msp430x14x.h"
void delay(void)
{
unsigned int i;
for(i = 0; i<50000;i++);
}
int main( void )
{
//关闭看门狗,防止程序运行过程中,在看门狗作用下使单片机复位, 而中断程序。
WDTCTL = WDTPW + WDTHOLD;
DCOCTL = DCO0+DCO1+DCO2;
BCSCTL1 = RSEL0;
P2DIR = 0XFF;
for(;;)
{
delay();
P2OUT = 0X00;
delay();
P2OUT = 0Xff;
} } 程序三
#include "msp430x14x.h"
void delay(void)
{
unsigned int i;
for(i=0;i<5000;i++);
}
int main( void )
{
WDTCTL = WDTPW + WDTHOLD;//关闭看门狗;
P2DIR = 0X04;
for(;;)
{
P2OUT ^=BIT2;
delay();
}
} 程序四
#include "msp430x14x.h"
void delay(void)
{
unsigned int i;
for(i=0;i<5000;i++);
}
int main( void )
{
WDTCTL = WDTPW + WDTHOLD;//关闭看门狗;
P2DIR = 0X1C;
for(;;)
{
P2OUT ^=BIT2 + BIT3 +BIT4;
delay();
}
} 程序⑤
#include "msp430x14x.h"
int main( void )
{ WDTCTL = WDTPW + WDTHOLD;//关闭看门狗
TACTL = TASSEL0 + ID0 +ID1 + MC0;
CCR0 = 2047;//开定时器中断
CCTL0 = CCIE;
P2DIR = 0X0F;
P2OUT = 0X0F;
_EINT();//使能全局中断
LPM3;
}
#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A(void)
{
P2OUT ^= 0x0f; //P2口输出取反
}
|