就是让 LED灯5秒亮10秒灭
前面的程序:void Delay(unsigned int nDelay);
unsigned int time_seg=0;
int sec=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
//---io_config----
P2DIR |= 0x08;
P2OUT &= ~0x08;
P2OUT |= 0x08;
for(;;)
{
TA0CCTL0 = CCIE; // TA0CCR0 interrupt enabled
TA0CCR0 = 0X8000; //32.768khz---->1s
TA0CTL = TASSEL_1 + MC_2; // ACLK, contmode
//-------亮
Delay(100);
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}// for(;;)
}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
{
sec=sec+1;
if(sec>1)
{
P2OUT |= 0x08; // init==start
sec=0;
}
else
{
P2OUT &= ~0x08; // init==start
}
TA0CCR0 +=0X8000; // Add Offset to TA0CCR0
}
void Delay(unsigned int nDelay)
{
int ii,jj,kk=0;
for ( ii=0;ii<nDelay;ii++ )
{
for ( jj=0;jj<1024;jj++ )
{
kk++;
}
}
}
前面的程序:void Delay(unsigned int nDelay);
unsigned int time_seg=0;
int sec=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
//---io_config----
P2DIR |= 0x08;
P2OUT &= ~0x08;
P2OUT |= 0x08;
for(;;)
{
TA0CCTL0 = CCIE; // TA0CCR0 interrupt enabled
TA0CCR0 = 0X8000; //32.768khz---->1s
TA0CTL = TASSEL_1 + MC_2; // ACLK, contmode
//-------亮
Delay(100);
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}// for(;;)
}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
{
sec=sec+1;
if(sec>1)
{
P2OUT |= 0x08; // init==start
sec=0;
}
else
{
P2OUT &= ~0x08; // init==start
}
TA0CCR0 +=0X8000; // Add Offset to TA0CCR0
}
void Delay(unsigned int nDelay)
{
int ii,jj,kk=0;
for ( ii=0;ii<nDelay;ii++ )
{
for ( jj=0;jj<1024;jj++ )
{
kk++;
}
}
}