消えゆく世界と流れる未来に最後の灯を since 2006/4/3
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
CSCTL1 |= DCORSEL1;
// GPIO Interruption
P1DIR |= BIT0;
P2OUT |= BIT3; // Configure P2.3 as pulled-up
P2REN |= BIT3; // P2.3 pull-up register enable
P2IES |= BIT3; // P2.3 Hi->Low edge
P2IE |= BIT3; // P2.3 interrupt enabled
P1OUT = 0;
P1DIR |= BIT1 | BIT2 | BIT4 | BIT5; // P1.1-P1.2, P1.4-P1.5 output
P1SEL1 |= BIT1 | BIT2 | BIT4 | BIT5; // P1.1-P1.2, P1.4-P1.5 options select
// Disable the GPIO power-on default high-impedance mode to activate
// previously configured port settings
PM5CTL0 &= ~LOCKLPM5;
P2IFG &= ~BIT3;
// P1.1: TA0.1
// P1.2: TA0.2
TA0CCR0 = 0xc000; // PWM Period
TA0CCTL1 = OUTMOD_2; // CCR1 reset/set
TA0CCR1 = 0x3fff; // CCR1 PWM duty cycle
TA0CCTL2 = OUTMOD_6; // CCR2 reset/set
TA0CCR2 = 0x3fff; // CCR2 PWM duty cycle
TA0CTL = TASSEL__SMCLK | MC__CONTINUOUS | TACLR; // SMCLK, up mode, clear TAR
// P1.4: TA1.1
// P1.5: TA1.2
TA1CCR0 = 0x8000; // PWM Period
TA1CCTL1 = OUTMOD_6; // CCR1 reset/set
TA1CCR1 = 0; // CCR1 PWM duty cycle
TA1CCTL2 = OUTMOD_2; // CCR2 reset/set
TA1CCR2 = 0; // CCR2 PWM duty cycle
TA1CTL = TASSEL__SMCLK | MC__CONTINUOUS | TACLR; // SMCLK, up mode, clear TAR
__bis_SR_register(LPM0_bits | GIE); // Enter LPM0
__no_operation(); // For debugger
}
// Port 2 interrupt service routine
// Reverse rotation polarity
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void)
{
P2IFG &= ~BIT3; // Clear P2.3 IFG
if (TA0CCTL1 == OUTMOD_2) {
TA0CCTL1 = OUTMOD_6;
TA0CCTL2 = OUTMOD_2;
} else {
TA0CCTL1 = OUTMOD_2;
TA0CCTL2 = OUTMOD_6;
}
P1OUT ^= BIT0;
}
制御としては下記のような図になると思う。