|
#include
#define CPU_F ((double)1000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
#define PWM_P 0xFFFF
#define PWM_2 0xFFF
#define PWM_3 0xEFF
#define KEY1 BIT3
void SET0(void);//Standby
void SET30(void);//30% Dim
void SET100(void);//No Dim
void SET_FL(void);//Flash Mode
unsigned char STU1=0;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;// Stop watchdog timer to prevent time out reset
DCOCTL|= MOD0+DCO0;// +DCO1+DCO2 //Set DCO Frequence select
BCSCTL1|=DIVA_0+RSEL0;// +RSEL1+RSEL2+RSEL3 // Set DCO Resistor
P1DIR &= ~BIT3; //P1.3 input
P1REN |=BIT3; // P1.3 pullup
P1IE |= BIT3; // P1.3 interrupt enabled
P1IES |= BIT3; // P1.3 Hi/lo edge
P1IFG &= ~BIT3; // P1.3 IFG cleared
STU1=0;
SET0();
_BIS_SR(LPM3_bits + GIE); // Enter LPM3
}
#pragma vector=PORT1_VECTOR
__interrupt void Port_1 (void)
{
if((P1IFG&KEY1)==KEY1) //KEY1 按下
{
delay_ms(20);
if((P1IN&KEY1)==0)
{
switch(STU1)
{
case 0:
SET100();
STU1=1;
break;
case 1:
SET30();
STU1=2;
break;
case 2:
SET_FL();
STU1=3;
break;
case 3:
STU1=0;
SET0();
break;
}
P1IFG &= ~BIT3; // P1.3 IFG cleared
}
}
}
void SET100(void)
{
P1DIR |= BIT6+BIT4+BIT0;// P1.2 and P1.3 output
P1SEL |=BIT4+BIT0;//
P1OUT |=BIT6+BIT4+BIT0;//
}
void SET30(void)
{
P1DIR |= BIT6+BIT4+BIT0;// // P1.2 and P1.3 output
P1SEL |= BIT6+BIT4+BIT0;// // P1.2 and P1.3 TA1/2 options
P1OUT |= BIT3;
CCR0 = PWM_P; // PWM Period
CCTL1 = OUTMOD_3; // CCR1 reset/set
CCR1 = PWM_3; // CCR1 PWM duty cycle
TACTL = TASSEL_2 + MC_1; // MCLK, up mode
}
void SET0(void)
{
P1OUT &= BIT6;
P1IFG &= ~BIT3;
//_BIS_SR(LPM4_bits + GIE);
}
void SET_FL(void) //Flash Mode
{
P1DIR |= BIT6; // P1.2 and P1.3 output
P1SEL |= BIT6; // P1.2 and P1.3 TA1/2 options
P1OUT |= BIT6;
CCR0 = PWM_P; // PWM Period
CCTL1 = OUTMOD_2; // CCR1 reset/set
CCR1 = PWM_3; // CCR1 PWM duty cycle
TACTL = TASSEL_1 + MC_1; // ACLK, up mode
} |
|