How to Write a C Program to Real Time Clock (One Second Timer) to Use ACLK (32768 Hz) to generate a one second timer and toggles an LED in C Programming Language ?
Solution:
/* Real Time Clock (One Second Timer)
* Description: Uses ACLK (32768 Hz) to generate a one second timer and toggles an LED.
*/
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
//16Mhz
if (CALBC1_16MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_16MHZ; // Set range
DCOCTL = CALDCO_16MHZ; // Set DCO step + modulation
P1DIR |= BIT0; // P1.0 output
CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 32768;
TACTL = TASSEL_1 + MC_2; // ACLK, contmode
_enable_interrupts(); // enable interrupts
}
// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
P1OUT ^= BIT0; // toggle P1.0
CCR0 += 32768; // extend timer 1s
}
Learn More :
Real Time Clock
32768 Hz
Generate
- How To Write a C program that generates two random numbers ?
- C program generates a random number and uses an algorithm to generate 9 other numbers.
- C Program Generates 10 Random Integers Between 0 and 99.
- C Program To Generating Fibonacci Series Using Recursion
- C Program To Generate Multiplication Table
- C Program to Generate Specific Formats
- Write a c program to accept a string from user & generate following pattern (e.g, input "abcd")
Toogle
ACLK