Guest User

Untitled

a guest
Oct 22nd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.98 KB | None | 0 0
  1. void start_buzzer(u8 cycles, u16 on_time, u16 off_time)
  2. {
  3.     // Store new buzzer duration while buzzer is off
  4.     if (sBuzzer.time == 0)
  5.     {
  6.         sBuzzer.time = cycles;
  7.         sBuzzer.on_time = on_time;
  8.         sBuzzer.off_time = off_time;
  9.  
  10.         // Need to init every time, because SimpliciTI claims same timer
  11.         // Reset TA1R, set up mode, TA1 runs from 32768Hz ACLK
  12.         TA1CTL = TACLR | MC_1 | TASSEL__ACLK;
  13.  
  14.         // Set PWM frequency
  15.         TA1CCR0 = BUZZER_TIMER_STEPS;
  16.  
  17.         // Enable IRQ, set output mode "toggle"
  18.         TA1CCTL0 = OUTMOD_4;
  19.  
  20.         // Allow buzzer PWM output on P2.7
  21.         P2SEL |= BIT7;
  22.  
  23.         // Activate Timer0_A3 periodic interrupts
  24.         fptr_Timer0_A3_function = toggle_buzzer;
  25.         Timer0_A3_Start(sBuzzer.on_time);
  26.  
  27.         // Preload timer advance variable
  28.         sTimer.timer0_A3_ticks = sBuzzer.off_time;
  29.  
  30.         // Start with buzzer output on
  31.         sBuzzer.state = BUZZER_ON_OUTPUT_ENABLED;
  32.     }
  33. }
Add Comment
Please, Sign In to add comment