1559 views|0 replies
- Last login
- 2023-11-15
- Online Time
- 196 hours
- Prestige
- 1018 points
- Points
- 641 points
|
#include
/******************************************************************** * Name: Divider_SetDivFactor * Function: Set the division factor * Input parameter: Factor: division factor (2~65535) * Output parameter: None****************************************************************/ void Divider_SetDivFactor(unsigned int Factor) //Set the division factor { TACCR0=Factor-1; // Division factor = counter overflow period TACCR2=Factor/2; // Duty cycle = 50% } void main( void ) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog FLL_CTL0 |= XCAP18PF; // Configure crystal load capacitance P1DIR &=~BIT5; // P1.5(TACLK) as input pin P1SEL |= BIT5; // Allow its second function as TACLK input P2DIR |= BIT0; // P2.0 as output P2SEL |= BIT0; // Allow P2.0 to have the second function as TA2 output TACTL = TASSEL_0 + MC_1 ; // TA external counting, up counting mode TACCTL2 = OUTMOD_7; // TA2 as output, mode 7 (PWM mode) Divider_SetDivFactor(100); // 100 division while(1) { //CPU can continue to execute other tasks} }
|
|