Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void start_buzzer(u8 cycles, u16 on_time, u16 off_time)
- {
- // Store new buzzer duration while buzzer is off
- if (sBuzzer.time == 0)
- {
- sBuzzer.time = cycles;
- sBuzzer.on_time = on_time;
- sBuzzer.off_time = off_time;
- // Need to init every time, because SimpliciTI claims same timer
- // Reset TA1R, set up mode, TA1 runs from 32768Hz ACLK
- TA1CTL = TACLR | MC_1 | TASSEL__ACLK;
- // Set PWM frequency
- TA1CCR0 = BUZZER_TIMER_STEPS;
- // Enable IRQ, set output mode "toggle"
- TA1CCTL0 = OUTMOD_4;
- // Allow buzzer PWM output on P2.7
- P2SEL |= BIT7;
- // Activate Timer0_A3 periodic interrupts
- fptr_Timer0_A3_function = toggle_buzzer;
- Timer0_A3_Start(sBuzzer.on_time);
- // Preload timer advance variable
- sTimer.timer0_A3_ticks = sBuzzer.off_time;
- // Start with buzzer output on
- sBuzzer.state = BUZZER_ON_OUTPUT_ENABLED;
- }
- }
Add Comment
Please, Sign In to add comment