MCU control buzzer playing music applet

Program features: MCU control buzzer playing song "I wish you peace"

----------------------------------------------

DIP switch setting: Set BUZZER bit to ON, and other bits to OFF

Test Description: Listen to the buzzer "sing out" music

Since it is a piece of music for a note, it should include two parts

First, the second tone is the duration. In this program, the tone is simple.

Delay-level flipping is implemented, changing the delay time changes

Tones, and time is achieved by counting comparisons, when the counts are equal

Just jump out of the loop and play the next note.

MCU control buzzer playing music applet

*********************************************/

#include "msp430x14x.h"

Typedef unsigned char uchar;

#include "music.h"

#define Buzzer BIT7

#define Buzzer_Port P6OUT

#define Buzzer_DIR P6DIR

Uchar counter;

Void Play_Song(void);

/***************Main function ****************/

Void main(void)

{

Uchar i;

/* The following six lines close all IO ports */

P1DIR = 0XFF; P1OUT = 0XFF;

P2DIR = 0XFF; P2OUT = 0XFF;

P3DIR = 0XFF; P3OUT = 0XFF;

P4DIR = 0XFF; P4OUT = 0XFF;

P5DIR = 0XFF; P5OUT = 0XFF;

P6DIR = 0XFF; P6OUT = 0XFF;

P6DIR |= BIT2;P6OUT |= BIT2; //Turn off level translation

WDTCTL = WDTPW + WDTHOLD; //Close Watchdog

/*------Select system master clock is 8MHz-------*/

BCSCTL1 &= ~XT2OFF; // Open XT2 high-frequency crystal oscillator

Do

{

IFG1 &= ~OFIFG; //Clear crystal failure flag

For (i = 0xFF; i ” 0; i--); // Wait for the 8MHz crystal to start

}

While ((IFG1 & OFIFG)); // Does the crystal failure flag still exist?

BCSCTL2 |= SELM_2 + SELS; //select high-frequency crystal for master clock and slave clock

// Set timer A to interrupt every 10ms

CCTL0 = CCIE;

CCR0 = 10000;//Changing this value changes the speed of the performance

TACTL |= TASSEL_2 + ID_3;

// Set the control buzzer's IO direction to output

Buzzer_DIR |= Buzzer;

// Open the global interrupt

_EINT();

// Loop play songs

While(1)

{

Play_Song();

}

}

/*******************************************

Function Name: TimerA_ISR

Function: Timer A interrupt service function

Parameters: None

Return value: None

********************************************/

#pragma vector = TIMERA0_VECTOR

__interrupt void TimerA_ISR(void)

{

Counter++;

}

/*******************************************

Function Name:Delay_Nms

Function: delay function of N ms ps: do not know how to calculate this place is delayed milliseconds

Parameters: n - delay length

Return value: None

********************************************/

Void Delay_Nms(uchar n)

{

Uchar i,j;

For( i = 0;i "n; i++ )

{

For( j = 0;j 3;j++ )

_NOP();

}

}

/*******************************************

Function Name:Play_Song

Function: Play "I wish you peace" music

Parameters: None

Return value: None

********************************************/

Void Play_Song(void)

{

Uchar Temp1,Temp2;

Uchar addr = 0;

Counter = 0; //Interrupt counter cleared

While(1)

{

Temp1 = SONG[addr++];

If ( Temp1 == 0xFF ) // rest

{

TACTL &=~MC_1; // Stop counting

Delay_Nms(100);

}

Else if ( Temp1 == 0x00 ) //End of song

{

Return;

}

Else

{

Temp2 = SONG[addr++];

TACTL |=MC_1; //start counting

While(1)

{

Buzzer_Port ^= Buzzer;//Level Reversal

Delay_Nms (Temp1) ;/ / Temp1 value determines the length of the delay, but also determines the frequency of the sound

If (Temp2 == counter )// determines the duration of the tone, and when the count time expires, it jumps out of the loop to play the next one.

{

Counter = 0;

Break;

}

}

}

}

}

Infrared Thermometer

With more than 15+ yrs rich MFG experience, you can definitely trust in and cooperate with.
Provide you with the supply of Personal Protective Equipment. to help you safely get back to your daily routine.
Our products include pulse Oximeter Finger, Forehead Thermometer, Automatic foam soap dispenser, etc.
Our strict quality control protocol thoroughly vets every aspect of production, storage, and shipments all the way way to our end customers.

infrared thermometers wholesale, forehead thermometer wholesale,wholesale thermometer suppliers

TOPNOTCH INTERNATIONAL GROUP LIMITED , https://www.itopnoobluetoothes.com

This entry was posted in on