Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions project/buzzer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <msp430.h>

#include "libTimer.h"

#include "buzzer.h"



void buzzer_init()

{

/*

Direct timer A output "TA0.1" to P2.6.

According to table 21 from data sheet:

P2SEL2.6, P2SEL2.7, anmd P2SEL.7 must be zero

P2SEL.6 must be 1

Also: P2.6 direction must be output

*/

timerAUpmode(); /* used to drive speaker */

P2SEL2 &= ~(BIT6 | BIT7);

P2SEL &= ~BIT7;

P2SEL |= BIT6;

P2DIR = BIT6; /* enable output to speaker (P2.6) */



buzzer_set_period(1000); /* start buzzing!!! */

}



void buzzer_set_period(short cycles)

{

CCR0 = cycles;

CCR1 = cycles >> 1; /* one half cycle */

}