The internal timer A of the MSP430F149 microcontroller is set to flash the LED for 1 second

Publisher:ShiningSmileLatest update time:2015-09-08 Source: eefocusKeywords:MSP430F149 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include "msp430x14x.h"  
 
//********************Function declaration******************
void InitClock();
 
//********************Main function************************
void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                  // Turn off the watchdog
  InitClock();                               // Initialize the clock
  P1DIR |= BIT0;                             // Set P1.0 as output
  CCTL0 = CCIE;                              // Enable CCR0 interrupt
  CCR0 = 500;
  TACTL = TASSEL_2 + MC_1;                   // Subsystem clock, up counting mode
  _BIS_SR(LPM0_bits + GIE);                  // Low power mode 0/ open general interrupt
}
 
//******************************************
Function name: InitClock
Function     : Initialize the clock function
Parameters     : None
Return value   : None
//************************************************
void InitClock()
{
  unsigned int oscdly;
  BCSCTL1 &= ~XT2OFF; // Clear OSCOFF/XT2 to enable XT2 oscillator
 
  do
  {
    IFG1 &=~OFIFG; //Clear OFIFG
 
    oscdly=255;
    while(oscdly--); //delay waiting 
 
  }
  while(IFG1 & OFIFG); //Until OFIFG=0
  DCOCTL |= DCO0 + DCO1 + DCO2;               // Max DCO
  BCSCTL1 |= RSEL0 + RSEL1 + RSEL2;           // XT2on, max RSEL
  //These two sentences set DCOCTL and BCSCTL1, set the frequency of DCO
  // Generally speaking, after the PUC is reset, if the system clock MCLK is not set specifically, the MCU will default to
  //Recognize the frequency generated by the DCO oscillator as the system clock, but if you set BCSCTL2 to select
  //If the clock source of MCLK is (such as: BCSCTL2 |= SELM_2+SELS;), the system clock is
  //XT2 oscillates.
  //------------------------------------------------ -------------
  BCSCTL2 |= SELM_2+SELS;     //SMCLK and MCLK uses XT2
  //This sentence sets BCSCTL2 and selects the clock sources of MCLK and SMCLK
  //Note: ACLK can only come from LFXT1. The frequency division of ACLK can be set in BCSCTL1.
  //------------------------------------------------ -------------
}
 
//******************************************
Function name: Timer_A
Function     : Timer A interrupt service subroutine
Parameters     : None
Return value   : None
//************************************************
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
  P1OUT ^= BIT0;                           // Invert P1.0
}
Keywords:MSP430F149 Reference address:The internal timer A of the MSP430F149 microcontroller is set to flash the LED for 1 second

Previous article:Display the light intensity value on LCD1602 based on MSP430F149 and BH1750FVI
Next article:C language driver for PCF8563 clock chip of MSP430 microcontroller

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号