// Set up digital I/O
P1DIR |= OUT1_PIN + OUT2_PIN + PWM1_PIN + PWM2_PIN; // Set P1.0, P1.1, P1.4, and P1.5 as outputs
P1OUT &= ~(OUT1_PIN + OUT2_PIN + PWM1_PIN + PWM2_PIN); // Set initial output values to 0
P1DIR &= ~(IN1_PIN + IN2_PIN); // Set P1.2 and P1.3 as inputs
P1REN |= IN1_PIN + IN2_PIN; // Enable pull-up resistors for P1.2 and P1.3
P1OUT |= IN1_PIN + IN2_PIN; // Set pull-up resistors for P1.2 and P1.3
// Set up timer
TA0CTL = TASSEL_2 + MC_0; // Use SMCLK as clock source, stop timer
TA0CCTL1 = OUTMOD_3; // Output mode: set/reset
TA0CCTL0 = CCIE; // Enable interrupt for TA0CCR0
TA0CCR0 = 1000; // Set timer period to 1ms
}
void main(void)
{
init();
while (1)
{
if ((P1IN & IN1_PIN) == 0) // If button is pressed
{
P1OUT |= PWM1_PIN; // Turn on PWM1 output
__delay_cycles(PULSE_WIDTH); // Wait for pulse width
P1OUT &= ~PWM1_PIN; // Turn off PWM1 output
__delay_cycles(DELAY_TIME); // Wait for delay time
}
if ((P1IN & IN2_PIN) == 0) // If button is pressed
{
P1OUT |= PWM2_PIN; // Turn on PWM2 output
__delay_cycles(PULSE_WIDTH); // Wait for pulse width
P1OUT &= ~PWM2_PIN; // Turn off PWM2 output
__delay_cycles(DELAY_TIME); // Wait for delay time
}
}
}
// Interrupt service routine for timer A0
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0_ISR(void)
{
// Toggle LED
P1OUT ^= OUT1_PIN + OUT2_PIN;
}