// Clock defaults
// FLL clock FLL select XT1
// Auxiliary clock ACLK selects XT1 32768Hz
// Main system clock MCLK selection DCOCLKDIV 8000000Hz
// Subsystem clock SMCLK selection DCOCLKDIV 8000000Hz
// TA1 selects ACLK, the maximum count value is 16384, and the interrupt frequency is 2HZ
// Toggle P4.0 in TIMER1_A0_VECTOR
#include
#include
void clock_config(void);
void select_xt1(void);
void dco_config(void);
int main(void)
{
clock_config(); // Initialize the clock
P4DIR |= BIT0; //P4.0 output
TA1CCTL0 = CCIE; // Enable TA1CCR0, compare match interrupt
TA1CCR0 = 16384; // Initialize the maximum value, the compare match interrupt frequency occurs 32768/16384 = 2Hz
TA1CTL = TASSEL_1 + MC_1 + TACLR; // Select ACLK, the maximum value is CCR0, clear the count value
_EINT(); // Initialize global interrupt
while(1)
{
;
}
}
void clock_config(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog
select_xt1(); // Select XT1
dco_config(); // ACLK = XT1 = 32.768K
// MCLK = SMCLK = 8000K
}
void select_xt1(void)
{
// Start XT1
P7SEL |= 0x03; // P7.0 P7.1 peripheral function
UCSCTL6 &= ~(XT1OFF); // XT1 is turned on
UCSCTL6 |= XCAP_3; // Internal capacitor
do
{
UCSCTL7 &= ~XT1LFOFFG; // Clear XT1 error flag
}while (UCSCTL7&XT1LFOFFG); // Check XT1 error flag
}
void dco_config(void)
{
__bis_SR_register(SCG0); // Disable FLL function
UCSCTL0 = 0x0000; // Set lowest possible DCOx, MODx
UCSCTL1 = DCORSEL_5; // DCO maximum frequency is 16MHz
UCSCTL2 = FLLD_1 + 243; // Set DCO frequency to 8MHz
// MCLK = SMCLK= Fdcoclkdiv = (N+1)X(Ffllrefclk/n)
// N is the only value that needs to be calculated
// Ffllrefclk FLL reference clock, default is XT1
// n takes the default value, which is 1
// (243 + 1) * 32768 = 8MHz
__bic_SR_register(SCG0); // Enable FLL function
// Necessary delay
__delay_cycles(250000);
// Clear the error flag
do
{
UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + XT1HFOFFG + DCOFFG);
// Clear all oscillator error flags
SFRIFG1 &= ~OFIFG; // Clear oscillator error
}while (SFRIFG1&OFIFG); // Wait for clear completion
}
#pragma vector=TIMER1_A0_VECTOR
__interrupt void TIMER1_A0_ISR(void)
{
P4OUT ^= BIT0;
}
Previous article:I2C Operation Notes - Taking AT24C04 as an example
Next article:MSP430F5438A instruction cycle and clock cycle
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Why are relays still used to drive automotive motors?
- Which MSP430FR6972 development board is suitable?
- Please recommend some easy-to-understand books or web links about phase detectors and frequency detectors. Thank you.
- DIY a CNC switching power supply, you need to master these knowledge
- General architecture of the hardware system of the C6000 series DSP
- Two symmetrical cascade amplifiers in one cavity + layout looks very pleasing to the eye
- Mini2440 serial communication
- State Machine Design-English.pdf
- Give a suggestion to NUCLEO development board
- Teach you how to turn a brushless motor