【英文】蜂鸣器FlowerDance
Preface
Buzzer FlowerDance
Wiring: one end of the buzzer is connected to P1.0, and the other end is connected to the positive pole of the power supply
Source Code
#include<8052.h>
// Store the high register
unsigned int h;
// Store the low register
unsigned int l;
void init()
{
// Specify enabling Timer 0 interrupt
IE = 0x82;
// Specify the mode for Timer/Counter 0
// Specify software gating signal as the enable signal
// Specify operating in timer mode
// Specify operating mode 3
TMOD = 0x01;
}
void delay(unsigned int ms)
{
unsigned int j;
while (ms--)
for (j = 600; j > 0; j--);
}
void main(void)
{
init();
// Initialize the buzzer
P1_0 = 1;
// C major scale array of middle note 7
__code unsigned int pitch[] = {
262, 294, 330, 349, 392, 440, 494,
523, 587, 659, 698, 784, 880, 988,
1046, 1175, 1318, 1397, 1568, 1760, 1976,
2092, 2350, 2636, 2794, 3136, 3520, 3952,
0};
// Tone played by the buzzer each time
__code unsigned int tone[] = {
17, 16, 20, 16, 17, 16, 13, 16,
17, 16, 20, 16, 17, 16, 13, 16,
17, 16, 20, 16, 17, 16, 13, 16,
17, 16, 20, 16, 17, 16, 13, 16,
17, 16, 20, 16, 17, 16, 13, 16,
17, 16, 20, 16, 17, 16, 13, 16,
17, 16, 20, 16, 17, 16, 20, 16,
17,
17, 29, 13, 15, 16, 16, 19,
16, 21, 20, 19, 20, 24,
20, 24, 23, 24, 21, 19,
20, 29, 24,
17, 29, 13, 15, 17, 16, 19,
16, 19, 20, 21, 22, 21, 20, 19,
20, 24, 23, 24, 20, 24, 23, 24, 20, 24, 23, 24, 20, 24, 23, 24,
20, 24, 22, 24, 20, 24, 22, 24, 20, 24, 22, 24, 20, 17,
22, 21, 22, 23, 21, 20, 19, 17, 19,
20, 19, 20, 22, 19, 18, 17, 17, 19,
18, 17, 16, 18, 17, 16, 15, 17,
16, 15, 14, 13, 12, 13, 14, 10,
15, 14, 15, 16, 14, 13, 12, 10, 12,
13, 12, 13, 15, 12, 11, 10, 10, 12,
11, 18, 17, 16, 15, 14, 17, 16, 15, 14,
13, 17, 12, 17, 13,
17, 29, 13, 15, 17, 16, 19,
16, 21, 20, 19, 20, 24,
20, 24, 23, 24, 21, 19,
20, 29, 17,
17, 29, 13, 15, 17, 16, 19,
16, 19, 20, 21, 22, 21, 20, 19,
20, 24, 23, 24, 20, 24, 23, 24, 20, 24, 23, 24, 20, 24, 23, 24,
20, 24, 22, 24, 20, 24, 22, 24, 20, 24, 22, 24, 20, 17,
17, 29, 13, 15, 17, 16, 19,
16, 21, 20, 19, 20, 24,
20, 24, 23, 24, 21, 19,
20, 29, 17,
17, 29, 13, 15, 17, 16, 19,
16, 15, 20, 21, 17, 22, 16, 21, 16, 20, 14, 19,
20, 24, 23, 24, 20, 24, 23, 24, 20, 24, 23, 24, 20, 24, 23, 24,
20, 24, 22, 24, 20, 24, 22, 24, 20, 24, 22, 24, 20, 17,
22, 21, 22, 23, 21, 20, 19, 17, 19,
20, 19, 20, 22, 19, 18, 17, 17, 19,
18, 17, 16, 18, 17, 16, 15, 17,
16, 15, 14, 13, 12, 13, 14, 10,
15, 14, 15, 16, 14, 13, 12, 10, 12,
13, 12, 13, 15, 12, 11, 10, 10, 12,
11, 18,