Created
February 20, 2011 20:18
-
-
Save PhirePhly/836262 to your computer and use it in GitHub Desktop.
Experiment with both CC registers for Timer A on the MSP430G2231
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <msp430g2211.h> | |
#define LED_0 BIT0 | |
#define LED_1 BIT6 | |
#define LED_OUT P1OUT | |
#define LED_DIR P1DIR | |
unsigned int timerCount = 0; | |
unsigned int timerCount1 = 0; | |
void main(void) | |
{ | |
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer | |
LED_DIR |= (LED_0 | LED_1); // Set P1.0 and P1.6 to output direction | |
LED_OUT &= ~(LED_0 | LED_1) ; // Set the LEDs off | |
TACCTL0 = CCIE; | |
TACCTL1 = CCIE; | |
TACTL = TASSEL_2 | MC_2; // Set the timer A to SMCLCK, Continuous | |
// Clear the timer and enable timer interrupt | |
__enable_interrupt(); | |
__bis_SR_register(LPM0 + GIE); // LPM0 with interrupts enabled | |
} | |
// Timer A0 interrupt service routine | |
#pragma vector=TIMERA0_VECTOR | |
__interrupt void Timer_A0 (void) | |
{ | |
timerCount = (timerCount + 1) % 8; | |
if(timerCount ==0) | |
P1OUT ^= (LED_0); | |
} | |
// Timer A1 interrupt service routine | |
#pragma vector=TIMERA1_VECTOR | |
__interrupt void Timer_A1 (void) | |
{ | |
TAIV &= ~(0x02); // CLEAR INTERRUPT | |
timerCount1 = (timerCount1 + 1) % 9; //4096; | |
if(timerCount1 ==0) | |
P1OUT ^= (LED_1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your reply. You explained it clearly. I now understand the purpose of the modulus operator and how it is applied in the code.