资料和应用文档,非常详细的说明了其工作原理:
单片机音乐的应用.pdf
(383.34 KB, 下载次数: 106)
代码:
单片机音乐的应用.c
(29.12 KB, 下载次数: 74)
- #include "reg51.h"
- #define uint unsigned int
- #define uchar unsigned char
- uchar * TABLE ;
- code uint TABLE1 [15]={64260,64400,64524,64580,
- 64684,64777,64820,64898,
- 64968,65030,65058,65110,
- 65157,65178,65217};
- code uchar SONG [ ]={
- //1. 迟来的爱
- //0
- 0x08,0x08,
- //1
- 0x02,0x12,0x42,0x62,0x52,0x42,0x21,11,
- 0x18,0x18,
- 0x02,0x22,0x42,0x82,0x92,0x82,0x61,0x51,0x42,
- 0x58,0x58,
- //2
- 0x66,0x51,0x61,0x84,0x62,0x82,
- 0x52,0x62,0x42,0x52,0x28,
- 0x52,0x42,0x52,0x62,0x94,0x81,0x91,0x81,0x61,
- 0x1C,0x12,0x82,
- //3
- 0x68,0x02,0x92,0x82,0x42,
- 0x5C,0x12,0x62,
- 0x58,0x02,0x42,0x51,0x41,0x22,
- 0x4C,0x62,0x52,
- //4
- 0x66,0x82,0x92,0x82,0x61,0x51,0x41,0x51,
- 0x6C,0x52,0x62,
- 0x53,0x63,0x52,0x42,0x42,0x22,
- 0x1C,0x12,0x22,
- //5
- 0x42,0x44,0x51,0x61,0x82,0x84,0x61,0x81,
- 0x96,0x82,0x66,0x51,0x61,
- 0x56,0x42,0x22,0x42,0x82,0x62,
- 0x5C,0x62,0x52,
- //6
- 0x66,0x82,0x92,0x82,0x61,0x51,0x41,0x51,
- 0x6C,0x52,0x62,
- 0x56,0x62,0x52,0x42,0x42,0x22,
- 0x1C,0x12,0x22,
- //7
- 0x42,0x44,0x51,0x61,0x82,0x84,0x61,0x81,
- 0x96,0x82,0x66,0x51,0x61,
- 0x56,0x62,0x92,0x82,0x62,0x52,
- 0x4C,0x62,0x61,0x81,
- //8
- 0x9C,0x81,0x91,0x81,0x61,
- 0x6C,0x82,0x62,
- 0x56,0x42,0x24,0x42,0x52,
- 0x6C,0x62,0x61,0x81,
- //9
- 0x9C,0xB2,0x92,
- 0x8C,0x82,0x92,
- 0xB2,0xB2,0xB2,0x92,0xD4,0xC1,0xD1,0xC1,0xB1,
- 0xCC,0xB2,0xB1,0xC1,
- //A
- 0xDC,0xD2,0xC1,0xB1,
- 0x9C,0x92,0x91,0xC1,
- 0x92,0x84,0x92,0x82,0x62,0x51,0x61,0x51,0x41,
- 0x48,0x48,
- //B
- 0x42,0x41,0x51,0x66,0x82,0x91,0xB1,
- 0x92,0x86,0x88,
- 0x42,0x41,0x51,0x66,0x42,0x41,0x51,
- 0x22,0x16,0x18,
- 0x86,0x62,0x58,
- //C
- 0x83,0x91,0x62,0x82,0x58,
- 0x52,0x62,0x52,0x42,0x22,0x12,0x62,0x52,
- 0x4C,0x62,0x52,
- //6
- 0x66,0x82,0x92,0x82,0x61,0x51,0x41,0x51,
- 0x6C,0x52,0x62,
- 0x56,0x62,0x52,0x42,0x42,0x22,
- 0x1C,0x12,0x22,
- //7
- 0x42,0x44,0x51,0x61,0x82,0x84,0x61,0x81,
- 0x96,0x82,0x66,0x51,0x61,
- 0x56,0x62,0x92,0x82,0x62,0x52,
- 0x4C,0x62,0x61,0x81,
- //8
- 0x9C,0x81,0x91,0x81,0x61,
- 0x6C,0x82,0x62,
- 0x56,0x42,0x24,0x42,0x52,
- 0x6C,0x62,0x61,0x81,
- //9
- 0x9C,0xB2,0x92,
- 0x8C,0x82,0x92,
- 0xB2,0xB2,0xB2,0x92,0xD4,0xC1,0xD1,0xC1,0xB1,
- 0xCC,0xB2,0xB1,0xC1,
- //A
- 0xDC,0xD2,0xC1,0xB1,
- 0x9C,0x92,0x91,0xC1,
- 0x92,0x84,0x92,0x82,0x62,0x51,0x61,0x51,0x41,
- 0x4C,0x62,0x61,0x81,
- //8
- 0x9C,0x81,0x91,0x81,0x61,
- 0x6C,0x82,0x62,
- 0x56,0x42,0x24,0x42,0x52,
- 0x6C,0x62,0x61,0x81,
- //9
- 0x9C,0xB2,0x92,
- 0x8C,0x82,0x92,
- 0xB2,0xB2,0xB2,0x92,0xD4,0xC1,0xD1,0xC1,0xB1,
- 0xCC,0xB2,0xB1,0xC1,
- //A
- 0xDC,0xD2,0xC1,0xB1,
- 0x9C,0x92,0x91,0xC1,
- 0x92,0x84,0x92,0x82,0x62,0x51,0x61,0x51,0x41,
- 0x4C,0x62,0x61,0x81,
- //D
- 0x66,0x51,0x61,0x86,0x61,0x81,
- 0x52,0x62,0x52,0x42,0x28,
- 0x82,0x91,0x01,0x62,0x11,0x52,0x11,0x01,0x62,0x54,
- 0x48,0x48,0x00};
- code uchar SONG1 [ ]={
- //2.两只蝴蝶
- //0
- 0x08,0x08,
- //1 [326]
- 0x51,0x61,0x81,0x61,
- 0x94,0x8C,
- 0x02,0x42,0x51,0x41,0x21,0x41,0x02,0x42,0x51,0x41,0x21,0x51,
- 0x04,0x03,0x11,0x21,0x41,0x52,0x51,0x41,0x21,0x41,
- 0x62,0x82,0x02,0x62,0x62,0x52,0x62,0x82,
- //2
- 0x94,0x93,0x81,0x86,0x81,0x91,
- 0xB2,0xB2,0xB2,0xC2,0xC2,0xB2,0xB4,
- 0x04,0x02,0x82,0x71,0x61,0x51,0x61,0x51,0x41,0x21,0x41,
- 0x42,0x52,0x62,0x82,0x84,0x62,0x52,
- //3
- 0x68,0x02,0x52,0x62,0x52,
- 0x48,0x04,0x22,0x42,
- 0x54,0x52,0x62,0x52,0x42,0x22,0x42,
- 0x18,0x04,0x62,0x52,
- 0x68,0x02,0x52,0x62,0x52,
- //4
- 0x48,0x04,0x22,0x42,
- 0x54,0x52,0x62,0x52,0x42,0x22,0x42,
- 0x58,0x04,0x62,0x52,
- //3
- 0x68,0x02,0x52,0x62,0x52,
- 0x48,0x04,0x22,0x42,
- 0x54,0x52,0x62,0x52,0x42,0x22,0x42,
- 0x18,0x04,0x62,0x82,
- 0x88,0x02,0x82,0x92,0x82,
- //4
- 0x68,0x04,0x52,0x52,
- 0x54,0x52,0x62,0x52,0x42,0x22,0x42,
- 0x42,0x42,0x4C,
- //5
- 0x04,0x04,0x02,0x82,0x82,0x92,
- 0xB2,0xA2,0x92,0x64,0x52,0x62,
- 0x68,0x02,0x62,0x62,0x82,
- 0x94,0x96,0x22,0x62,0x52,
- 0x58,0x04,0x62,0x82,
- //6
- 0x82,0x62,0x84,0x02,0xB2,0xB2,0xA2,
- 0x92,0xA2,0x66,0x92,0x92,0xA2,
- 0x92,0x82,0x62,0x52,0x52,0x62,0x52,0x62,
- 0x88,0x02,0x82,0x82,0x92,
- 0xB2,0xA2,0x92,0x64,0x52,0x62,
- 0x68,0x02,0x62,0x62,0x82,
- 0x94,0x96,0x22,0x62,0x52,
- 0x58,0x04,0x62,0x82,
- //6
- 0x82,0x62,0x84,0x02,0xB2,0xB2,0xA2,
- 0x92,0xA2,0x66,0x92,0x92,0xA2,
- 0x92,0x82,0x62,0x52,0x52,0x12,0x12,0x22,
- 0x48,0x02,0x82,0x82,0x92,
- 0xB2,0xA2,0xA2,0x92,0x64,0x52,0x62,
- //A
- 0x68,0x02,0x62,0x62,0x82,
- 0x94,0x96,0x22,0x62,0x52,
- 0x58,0x04,0x62,0x82,
- 0x82,0x62,0x84,0x02,0xB2,0xB2,0xA2,
- 0x92,0xA2,0x66,0x92,0x92,0xA2,
- //B
- 0x92,0x82,0x62,0x52,0x52,0x12,0x12,0x22,
- 0x4C,0x62,0x82,
- 0x82,0x62,0x84,0x02,0xB2,0xB2,0xA2,
- 0x92,0xA2,0x66,0x92,0x92,0xA2,
- //C
- 0x92,0x82,0x62,0x52,0x52,0x12,0x12,0x22,0x4C,
- 0x62,0x12,0x52,0x42,0x44,0x62,0x82,
- 0x84,0x92,0xB2,0xC2,0xB2,0xB2,0xBC,0x00};
- code uchar SONG2 [ ]={
- //3.祝你平安
- //0
- 0x08,0x08,
- //1
- 0x62,0x82,0x81,0x62,0x81,0x88,
- 0x62,0x42,0x42,0x21,0x41,0x48,
- 0x62,0x82,0x81,0x93,0x88,0x51,0x61,
- //2
- 0x52,0x62,0x82,0x51,0x61,0x58,
- 0x62,0x42,0x42,0x21,0x61,0x66,0x51,0x61,
- 0x62,0x42,0x42,0x21,0x61,0x68,
- //3
- 0x51,0x61,0x51,0x51,0x52,0x41,0x21,0x51,0x62,0x51,0x54,
- 0x11,0x11,0x81,0x81,0x51,0x63,0x48,
- //1
- 0x62,0x82,0x81,0x62,0x81,0x88,
- 0x62,0x42,0x42,0x21,0x41,0x48,
- 0x62,0x82,0x81,0x93,0x88,0x51,0x61,
- //2
- 0x52,0x62,0x82,0x51,0x61,0x58,
- 0x62,0x42,0x42,0x21,0x61,0x66,0x51,0x61,
- 0x62,0x42,0x42,0x21,0x61,0x68,
- //3
- 0x51,0x61,0x51,0x51,0x52,0x41,0x21,0x51,0x62,0x51,0x54,
- 0x11,0x11,0x81,0x81,0x51,0x63,0x48,
- 0x08,0x08,
- //4
- 0xb2,0xb2,0x62,0x82,0x86,0x61,0x51,
- 0x42,0x42,0x92,0x82,0x88,
- 0x92,0x92,0x92,0x46,0x21,0x41,
- //5
- 0x82,0x62,0x62,0x52,0x58,
- 0xb2,0xb2,0x62,0x82,0x86,0x61,0x51,
- 0x42,0x42,0x92,0x82,0x88,
- //6
- 0x62,0x52,0x41,0x42,0x22,0x51,0x62,0x51,0x54,
- 0x11,0x11,0x81,0x81,0x51,0x51,0x62,0x48,0x00};
- code uchar SONG3 [ ]={
- //4.一个师傅三个徒弟
- //0
- 0x08,0x08,
- //1
- 0xd2,0xe2,0xd2,0xe2,0xd2,0xe2,0xd2,0xb2,
- 0xa8,0x68,
- 0xd2,0xe2,0xd2,0xe2,0xd2,0xc2,0xb2,0xa2,
- //2
- 0xd8,0xd8,
- 0xd8,0xd8,
- 0x64,0x64,0x28,
- 0x44,0x22,0x12,0x24,0x04,
- //3
- 0x22,0x42,0x42,0x42,0x44,0x42,0x22,
- 0x44,0x52,0x62,0x68,
- 0x64,0x84,0x24,0x44,
- 0x24,0x22,0x12,0x68,
- //4
- 0x52,0x52,0x52,0x62,0x14,0x34,
- 0x28,0x28,
- 0x92,0x92,0x92,0x92,0x64,0x81,0x83,
- 0x82,0x82,0x82,0x62,0x92,0x82,0x04,
- //5
- 0x72,0x72,0x72,0x72,0x74,0x41,0x43,
- 0x42,0x42,0x52,0x42,0x52,0x62,0x64,
- 0x92,0x92,0x92,0x92,0x64,0x81,0x83,
- //6
- 0x82,0x82,0x82,0x62,0x92,0x82,0x04,
- 0x92,0x92,0x92,0x92,0xb4,0x91,0x83,
- 0x82,0x82,0x82,0x82,0x62,0x82,0x84,
- //7
- 0x52,0x52,0x42,0x52,0x62,0x52,0x42,0x51,0x51,
- 0x62,0x52,0x62,0x82,0x88,
- 0x44,0x54,0x64,0x84,0x84,0x34,
- 0x28,0x28,
- 0x64,0x64,0x28,
- 0x44,0x22,0x12,0x24,0x04,
- //3
- 0x22,0x42,0x42,0x42,0x44,0x42,0x22,
- 0x44,0x52,0x62,0x68,
- 0x64,0x84,0x24,0x44,
- 0x24,0x22,0x12,0x68,
- //4
- 0x52,0x52,0x52,0x62,0x14,0x34,
- 0x28,0x28,
- 0x92,0x92,0x92,0x92,0x64,0x81,0x83,
- 0x82,0x82,0x82,0x62,0x92,0x82,0x04,
- //5
- 0x72,0x72,0x72,0x72,0x74,0x41,0x43,
- 0x42,0x42,0x52,0x42,0x52,0x62,0x64,
- 0x92,0x92,0x92,0x92,0x64,0x81,0x83,
- //6
- 0x82,0x82,0x82,0x62,0x92,0x82,0x04,
- 0x92,0x92,0x92,0x92,0xb4,0x91,0x83,
- 0x82,0x82,0x82,0x82,0x62,0x82,0x84,
- //7
- 0x52,0x52,0x42,0x52,0x62,0x52,0x42,0x51,0x51,
- 0x62,0x52,0x62,0x82,0x88,
- //8
- 0x42,0x52,0x42,0x51,0x51,0x62,0x52,0x62,0x92,
- 0x98,0x98,0x00};
- code uchar SONG4 [ ]={
- //5.梦醒时分
- //0
- 0x08,0x08,
- //1
- 0x21,0x41,0x81,0x61,0x62,0x21,0x41,0x81,0x62,0x81,0x81,0x91,0xa1,0xb1,
- 0x82,0x81,0x81,0x81,0x93,0x68,
- //2
- 0x21,0x41,0x81,0x61,0x62,0x21,0x41,0x81,0x62,0x81,0x91,0xa1,0xa1,0x91,
- 0xc6,0x91,0x91,0x86,
- //3
- 0x44,0x54,0x62,0x61,0x61,0x51,0x52,
- 0x62,0x81,0x61,0x62,0x61,0x81,0x92,0x92,0x92,0xa2,
- //4
- 0x82,0x64,0x61,0x51,0x42,0x41,0x41,0x41,0x21,0x22,
- 0x62,0x81,0x41,0x44,0x51,0x53,0x52,0x42,0x62,
- //5
- 0x62,0x54,0x41,0x51,0x62,0x61,0x61,0x62,0x52,
- 0x62,0x81,0x61,0x62,0x61,0x81,0x92,0x91,0x91,0x92,0xa2,
- //6
- 0x84,0x64,0x61,0x81,0x81,0x81,0x92,0xb2,0xb1,0x91,0x92,
- 0x72,0x54,0x81,0x81,0x92,0xb2,0xb2,0x92,
- //7
- 0xb2,0xc6,0xc6,0x01,0x81,0x81,0x81,
- 0xd2,0xd2,0xd2,0xd2,0xc2,0xc1,0xc1,0xc2,0xb1,0xa1,
- //8
- 0xb2,0xb1,0xb1,0xb2,0xc2,0x62,0x84,0x81,0x81,
- 0x92,0xb2,0xb2,0xb2,0xb2,0xc3,0x91,0xb2,0xb1,0xb1,
- //9
- 0xc2,0xc1,0xc1,0xb2,0xb2,0xd2,0xc1,0x81,0x01,0x81,0x81,0x81,
- 0xd2,0xd2,0xd2,0xf2,0xc2,0xc1,0xc2,0xb1,0xa1,
- //a
- 0xb2,0xb1,0xb1,0xb2,0xc2,0x62,0x84,0x81,0x81,
- 0x92,0xb1,0xb1,0xb2,0xb2,0xc2,0x91,0xb1,0x02,0xb1,0xb1,
- //b
- 0xc2,0xc1,0xb1,0xc1,0xb1,0xb2,0xd4,0xc3,0xb1,
- 0xb8,0xb8,0x00};
- code uchar SONG5 [ ]={
- //6.祈祷
- //0
- 0x08,0x08,
- //1
- 0x84,0x92,0xf2,0xd8,
- 0xc4,0xb2,0xa2,0x98,
- 0xc4,0xb2,0xf2,0xd2,0xc4,
- 0xd8,0xd8,
- 0x14,0x22,0x82,0x68,
- 0x54,0x42,0x32,0x28,
- //2
- 0x14,0x22,0x42,0x44,0x14,
- 0x28,0x28,
- 0x28,0x28,
- 0x14,0x22,0x42,0x54,0x52,0x62,
- //3
- 0x58,0x42,0x22,0x24,
- 0x22,0x22,0x42,0x52,0x64,0x62,0x52,
- 0x58,0x58,
- 0x14,0x22,0x42,0x54,0x52,0x82,
- //4
- 0x68,0x52,0x42,0x44,
- 0x24,0x22,0x42,0x44,0x42,0x22,
- 0x28,0x28,
- 0x14,0x22,0x42,0x54,0x52,0x62,
- //3
- 0x58,0x42,0x22,0x24,
- 0x22,0x22,0x42,0x52,0x64,0x62,0x52,
- 0x58,0x58,
- 0x14,0x22,0x42,0x54,0x52,0x82,
- //4
- 0x68,0x52,0x42,0x44,
- 0x24,0x22,0x42,0x44,0x42,0x22,
- 0x28,0x28,
- //5
- 0x22,0x62,0x52,0x62,0x42,0x52,0x62,0x82,
- 0x94,0x92,0x82,0x94,0xb2,0xa2,
- 0x94,0x84,0x64,0x84,
- //7
- 0x98,0x98,
- 0x92,0x82,0x92,0xb2,0xd8,
- 0xc8,0xc8,
- 0xa8,0xa8,
- 0x14,0x22,0x42,0x54,0x52,0x62,
- //3
- 0x58,0x42,0x22,0x24,
- 0x22,0x22,0x42,0x52,0x64,0x62,0x52,
- 0x58,0x58,
- 0x14,0x22,0x42,0x54,0x52,0x82,
- //4
- 0x68,0x52,0x42,0x44,
- 0x24,0x22,0x42,0x44,0x42,0x22,
- 0x28,0x28,
-
- 0x14,0x22,0x42,0x54,0x52,0x62,
- //3
- 0x58,0x42,0x22,0x24,
- 0x22,0x22,0x42,0x52,0x64,0x62,0x52,
- 0x58,0x58,
- 0x14,0x22,0x42,0x54,0x52,0x82,
- //4
- 0x68,0x52,0x42,0x44,
- 0x24,0x22,0x42,0x44,0x42,0x22,
- 0x28,0x28,
- //6
- 0x94,0x92,0x82,0x84,0x82,0x62,
- 0x88,0x88,
- 0x54,0x52,0x52,0x54,0x82,0x62,
- 0x54,0x64,0x54,0x64,
- //8
- 0x94,0x92,0xa2,0xb2,0xa2,0x92,0x82,
- 0x94,0x94,0x94,0x74,
- 0x84,0x84,0x84,0x84,0x00};
- code uchar SONG6 [ ]={
- //7.春天的故事
- //0
- 0x08,0x08,
- //1
- 0x02,0x12,0x22,0x12,
- 0x68,
- 0x02,0x12,0x22,0x12,
- 0x58,
- 0x02,0x12,0x22,0x12,
- 0x58,0x52,0x52,0x62,0x92,
- //2
- 0x88,
- 0x88,
- 0x82,0x81,0x81,0x91,0x81,0x91,0x81,
- 0x88,
- 0x88,
- 0x52,0x61,0x61,0x61,0x31,0x21,0x41,
- //3
- 0x18,
- 0x18,
- 0x02,0x62,0x12,0x22,
- 0x43,0x51,0x61,0x81,0x52,
- 0x58,
- 0x58,
- //4
- 0x12,0x81,0x81,0x81,0x61,0x51,0x61,
- 0x32,0x02,0x21,0x31,0x11,0x21,
- 0x18,
- 0x18,
- 0x12,0x82,0x81,0x61,0x52,
- //5
- 0x46,0x21,0x41,
- 0x53,0x51,0x61,0x31,0x21,0x41,
- 0x18,
- 0x22,0x48,0x52,
- 0x62,0x84,0x62,
- //6
- 0x91,0x92,0x91,0x81,0x91,0x61,0x61,
- 0x53,0x21,0x41,0x51,0x61,0x51,
- 0x58,
- 0x58,
- 0x63,0x51,0x82,0x32,
- //7
- 0x24,0x12,0x62,
- 0x13,0x21,0x32,0x61,0x81,
- 0x58,
- 0x63,0x81,0x82,0x32,
- 0x24,0x12,0x62,
- //8
- 0x33,0x31,0x21,0x31,0x12,
- 0x18,
- 0x86,0x81,0x91,
- 0x81,0x91,0x44,0x32,
- 0x22,0x72,0x81,0x91,0x51,
- //9
- 0x58,
- 0x86,0x81,0x91,
- 0x81,0x91,0x44,0x32,
- 0x22,0x92,0x91,0x81,0x91,0x81,
- 0x88,
- //a
- 0x02,0x81,0x91,0x11,0x91,0x81,0x91,
- 0x46,0x21,0x41,
- 0x53,0x61,0x31,0x51,0x22,
- 0x28,
- 0x22,0x62,0x12,0x21,0x21,
- //b
- 0x43,0x51,0x62,0x81,0x81,
- 0x81,0x31,0x21,0x41,0x14,
- 0x18,
- 0x02,0x62,0x12,0x21,0x21,
- //c
- 0x43,0x51,0x62,0xb1,0x21,
- 0x81,0x61,0x84,0x62,
- 0x53,0x61,0x81,0x31,0x21,0x41,
- 0x56,0x61,0x81,
- //d
- 0x13,0x21,0x32,0x61,0x81,
- 0x52,0x32,0x21,0x31,0x12,
- 0x16,0x22,
- 0x18,
- 0x12,0x82,0x81,0x61,0x52,
- //5
- 0x46,0x21,0x41,
- 0x53,0x51,0x61,0x31,0x21,0x41,
- 0x18,
- 0x22,0x48,0x52,
- 0x62,0x84,0x62,
- //6
- 0x91,0x92,0x91,0x81,0x91,0x61,0x61,
- 0x53,0x21,0x41,0x51,0x61,0x51,
- 0x58,
- 0x58,
- 0x63,0x51,0x82,0x32,
- //7
- 0x24,0x12,0x62,
- 0x13,0x21,0x32,0x61,0x81,
- 0x58,
- 0x63,0x81,0x82,0x32,
- 0x24,0x12,0x62,
- //8
- 0x33,0x31,0x21,0x31,0x12,
- 0x18,
- 0x86,0x81,0x91,
- 0x81,0x91,0x44,0x32,
- 0x22,0x72,0x81,0x91,0x51,
- //9
- 0x58,
- 0x86,0x81,0x91,
- 0x81,0x91,0x44,0x32,
- 0x22,0x92,0x91,0x81,0x91,0x81,
- 0x88,
- //a
- 0x02,0x81,0x91,0x11,0x91,0x81,0x91,
- 0x46,0x21,0x41,
- 0x53,0x61,0x31,0x51,0x22,
- 0x28,
- 0x22,0x62,0x12,0x21,0x21,
- //b
- 0x43,0x51,0x62,0x81,0x81,
- 0x81,0x31,0x21,0x41,0x14,
- 0x18,
- 0x02,0x62,0x12,0x21,0x21,
- //c
- 0x43,0x51,0x62,0xb1,0x21,
- 0x81,0x61,0x84,0x62,
- 0x53,0x61,0x81,0x31,0x21,0x41,
- 0x56,0x61,0x81,
- //d
- 0x13,0x21,0x32,0x61,0x81,
- 0x52,0x32,0x21,0x31,0x12,
- 0x16,0x22,
- 0x18,
- 0x82,0x81,0x81,0x91,0x81,0x91,0x81,
- //e
- 0x88,
- 0x88,
- 0x82,0x81,0x81,0x91,0x81,0x91,0x81,
- 0x88,
- 0x88,
- 0x12,0x81,0x81,0x81,0x61,0x51,0x61,
- //f
- 0xa2,0x02,0x21,0x31,0x11,0x21,
- 0x18,
- 0x18,
- 0xa4,0x92,0xa2,
- 0x64,0x84,
- 0x88,
- 0x88,
- 0x88,
- 0x00};
- code uchar SONG7 [ ]={
- //8.好大一棵树
- //0
- 0x08,0x08,
- //1
- 0xdc,0xc2,0xd2,
- 0xc2,0x92,0xb2,0xa2,0xa2,0x82,
- 0x22,0x92,0xb2,0xd2,0xd2,0xc4,0x92,
- 0x94,0xd2,0xc2,0xb2,0xc2,0xc4,
- //2
- 0xe2,0xf2,0xfc,
- 0x62,0x82,0x83,0x61,0x86,0x02,
- 0x92,0xb2,0xb3,0x91,0x86,0x02,
- //3
- 0x92,0xb1,0xb1,0x02,0x92,0x82,0xb1,0x61,0x62,0x02,
- 0x52,0x62,0x52,0x41,0x51,0x54,0x04,
- 0x62,0x82,0x83,0x61,0x86,0x02,
- //4
- 0x92,0xb2,0xb3,0x91,0x86,0x02,
- 0x92,0xb1,0xb1,0x02,0xb1,0x91,0x81,0x81,0xb1,0x61,0x04,
- 0x52,0x62,0x61,0x52,0x41,0x46,0x02,
- 0x62,0x82,0x83,0x61,0x86,0x02,
- 0x92,0xb2,0xb3,0x91,0x86,0x02,
- //3
- 0x92,0xb2,0xb2,0x92,0x81,0x81,0xb1,0x61,0x62,0x61,0x61,
- 0x52,0x64,0x51,0x41,0x54,0x04,
- 0x62,0x82,0x83,0x61,0x86,0x02,
- //4
- 0x92,0xb2,0xb3,0x91,0x86,0x02,
- 0x92,0xb2,0xb2,0x92,0x82,0xb1,0x61,0x04,
- 0x52,0x62,0x61,0x51,0x51,0x41,0x46,0x02,
- //5
- 0x92,0xb2,0xb3,0x91,0xa8,
- 0x82,0xb2,0xb3,0x91,0x88,
- 0x42,0x42,0x42,0x52,0x62,0x51,0x61,0x64,
- //6
- 0x52,0x52,0x51,0x92,0x81,0x88,
- 0x92,0xb2,0xb3,0x91,0xb8,
- 0x82,0xb2,0xb3,0x91,0x88,
- //7
- 0x42,0x52,0x62,0x82,0x92,0x81,0x91,0x94,
- 0x82,0x62,0x51,0x63,0x48,
- 0x42,0x52,0x62,0x82,0x92,0xa1,0xb1,0x04,
- //8
- 0x84,0xb4,0xb2,0xc6,
- 0xcc,0xb4,
- 0xb8,0xb8,
- 0xb8,0xb8,
- 0xb4,0x04,0x04,0x04,
- 0x00};
- code uchar SONG8 [ ]={
- //9.爱就一个字
- //0
- 0x08,0x08,
- //1
- 0x82,0x81,0x81,0x82,0xb1,0xb1,0xb2,0x92,0x93,0x91,
- 0x82,0x91,0x81,0x82,0x71,0x61,0x72,0x82,0x84,
- //2
- 0x82,0x81,0x81,0x82,0xb2,0xb2,0x92,0x03,0x91,
- 0x82,0xc2,0xc2,0xa1,0xb1,0xb4,0xd2,0xc2,
- //3
- 0xb4,0xb1,0xc1,0xd1,0xa1,0xa4,0x03,0x81,
- 0x91,0x81,0x91,0x81,0x92,0xb2,0xf2,0xd1,0xc1,0xd4,0xc4,
- //4
- 0xa4,0xd2,0xf1,0xb1,0xb4,0x01,0xb1,0xc1,0xd1,
- 0xe2,0xd1,0xb1,0xb3,0xd1,0xe2,0xd1,0xb1,0xe2,0xd1,0xb1,
- //5
- 0xd3,0xe1,0xd1,0xc4,0xb4,0x94,
- 0x82,0x81,0x81,0x82,0xb2,0xb2,0x92,0x03,0x91,
- 0x82,0x91,0x81,0x82,0x71,0x61,0x72,0x86,
- //6
- 0x82,0x81,0x81,0x82,0xb2,0xb2,0x92,0x02,0x92,
- 0x82,0xc2,0xc2,0xb1,0xd1,0xd4,0xd2,0xc2,
- 0xb4,0xb1,0xc1,0xd1,0xa1,0xa4,0x03,0x81,
- //7
- 0x91,0x81,0x91,0x81,0x92,0xb2,0xf2,0xd1,0xc1,0xd2,0xc2,
- 0xa4,0xd2,0xf1,0xb1,0xb4,0x01,0xb1,0xc1,0xd1,
- //8
- 0xe2,0xd1,0xb1,0xb3,0xd1,0xe2,0xd1,0xb1,0xe2,0xd1,0xb1,
- 0xf6,0xf2,0xf2,0x81,0x91,0x81,0x91,0xd1,
- //9
- 0x03,0x81,0x91,0x81,0x91,0xc1,0x03,0x81,0x91,0x81,0x91,0xb1,
- 0xb2,0xb1,0xb1,0xc2,0xd1,0xa1,0xa4,0x03,0xa1,
- //a
- 0x03,0x81,0x91,0x81,0x91,0xd1,
- 0x03,0x81,0x91,0x81,0x91,0xb1,0x03,0x81,0x91,0x81,0x91,0xb1,
- 0xb2,0xb1,0xb1,0xc2,0xd1,0xf1,0xf4,0x03,0xd1,
- //b
- 0xd2,0xe1,0xf1,0xc1,0xb2,0x81,0xd2,0xe1,0xf1,0xc2,0xb2,
- 0x03,0x91,0xf1,0xf1,0xf1,0xf1,0xf2,0xd2,0xf4,0xf8,0x04,0x04,
- //1
- 0x82,0x81,0x81,0x82,0xb1,0xb1,0xb2,0x92,0x93,0x91,
- 0x82,0x91,0x81,0x82,0x71,0x61,0x72,0x82,0x84,
- //2
- 0x82,0x81,0x81,0x82,0xb2,0xb2,0x92,0x03,0x91,
- 0x82,0xc2,0xc2,0xa1,0xb1,0xb4,0xd2,0xc2,
- //3
- 0xb4,0xb1,0xc1,0xd1,0xa1,0xa4,0x03,0x81,
- 0x91,0x81,0x91,0x81,0x92,0xb2,0xf2,0xd1,0xc1,0xd4,0xc4,
- //4
- 0xa4,0xd2,0xf1,0xb1,0xb4,0x01,0xb1,0xc1,0xd1,
- 0xe2,0xd1,0xb1,0xb3,0xd1,0xe2,0xd1,0xb1,0xe2,0xd1,0xb1,
- //5
- 0xd3,0xe1,0xd1,0xc4,0xb4,0x94,
- 0x82,0x81,0x81,0x82,0xb2,0xb2,0x92,0x03,0x91,
- 0x82,0x91,0x81,0x82,0x71,0x61,0x72,0x86,
- //6
- 0x82,0x81,0x81,0x82,0xb2,0xb2,0x92,0x02,0x92,
- 0x82,0xc2,0xc2,0xb1,0xd1,0xd4,0xd2,0xc2,
- 0xb4,0xb1,0xc1,0xd1,0xa1,0xa4,0x03,0x81,
- //7
- 0x91,0x81,0x91,0x81,0x92,0xb2,0xf2,0xd1,0xc1,0xd2,0xc2,
- 0xa4,0xd2,0xf1,0xb1,0xb4,0x01,0xb1,0xc1,0xd1,
- //8
- 0xe2,0xd1,0xb1,0xb3,0xd1,0xe2,0xd1,0xb1,0xe2,0xd1,0xb1,
- 0xf6,0xf2,0xf2,0x81,0x91,0x81,0x91,0xd1,
- //9
- 0x03,0x81,0x91,0x81,0x91,0xc1,0x03,0x81,0x91,0x81,0x91,0xb1,
- 0xb2,0xb1,0xb1,0xc2,0xd1,0xa1,0xa4,0x03,0xa1,
- //a
- 0x03,0x81,0x91,0x81,0x91,0xd1,
- 0x03,0x81,0x91,0x81,0x91,0xb1,0x03,0x81,0x91,0x81,0x91,0xb1,
- 0xb2,0xb1,0xb1,0xc2,0xd1,0xf1,0xf4,0x03,0xd1,
- //b
- 0xd2,0xe1,0xf1,0xc1,0xb2,0x81,0xd2,0xe1,0xf1,0xc2,0xb2,
- //c
- 0x03,0x91,0xf1,0xf1,0xf1,0xf1,0xf2,0xd2,0xf4,
- 0xd2,0xc1,0xb1,0xc2,0xb5,0xb4,
- 0xbc,0x04,
- 0x00};
- code uchar SONG9 [ ]={
- //大约在冬季
- //0
- 0x08,0x08,
- //1
- 0xb6,0xa1,0x91,0xa8,
- 0x96,0x82,0x66,0x61,0x81,
- 0x94,0xa4,0xb4,0xc4,
- 0xf8,0xf8,
- //2
- 0x41,0x42,0x41,0x02,0x41,0x51,0x62,0x81,0x81,0x02,0x61,0x81,
- 0x92,0x61,0x61,0x52,0x51,0x61,0x64,0x02,0x61,0x51,
- //3
- 0x42,0x21,0x21,0x04,0x61,0x51,0x42,0x21,0x21,0x02,0x21,0x41,
- 0x52,0x51,0x51,0x51,0x61,0x51,0x81,0x84,0x04,
- //4
- 0x41,0x42,0x41,0x42,0x41,0x51,0x62,0x81,0x81,0x02,0x61,0x81,
- 0x91,0x61,0x61,0x61,0x61,0x52,0x52,0x61,0x62,0x02,0x02,0x61,0x51,
- //5
- 0x42,0x21,0x21,0x02,0x61,0x51,0x42,0x21,0x21,0x02,0x21,0x41,
- 0x51,0x51,0x51,0x51,0x52,0x11,0x21,0x24,0x04,
- //6
- 0x91,0x92,0x91,0x92,0x62,0x81,0x82,0x81,0x82,0x61,0x51,
- 0x42,0x42,0x41,0x52,0x41,0x64,0x04,
- //7
- 0x91,0x92,0x91,0x92,0x91,0xa1,0x91,0x82,0x81,0x02,0x61,0x81,
- 0x92,0x62,0x51,0x42,0x81,0x84,0x04,
- //8
- 0x41,0x42,0x41,0x02,0x41,0x51,0x62,0x81,0x81,0x02,0x61,0x81,
- 0x92,0x62,0x61,0x51,0x51,0x61,0x64,0x02,0x61,0x51,
- //9
- 0x42,0x21,0x21,0x02,0x61,0x51,0x42,0x21,0x21,0x02,0x21,0x41,
- 0x51,0x51,0x51,0x51,0x52,0x11,0x21,021,0x02,0x02,0x61,0x51,
- //a
- 0x42,0x21,0x21,0x02,0x61,0x51,0x42,0x21,0x21,0x02,0x21,0x41,
- 0x51,0x51,0x51,0x51,0x52,0x12,0x24,0x04,
- //b
- 0x24,0x14,0x74,0x64,
- 0x54,0x84,0x44,0x41,0x51,0x61,0x81,
- 0x94,0xa4,0xb4,0xc4,
- 0xf8,0xf8,
- //2
- 0x41,0x42,0x41,0x02,0x41,0x51,0x62,0x81,0x81,0x02,0x61,0x81,
- 0x92,0x61,0x61,0x52,0x51,0x61,0x64,0x02,0x61,0x51,
- //3
- 0x42,0x21,0x21,0x04,0x61,0x51,0x42,0x21,0x21,0x02,0x21,0x41,
- 0x52,0x51,0x51,0x51,0x61,0x51,0x81,0x84,0x04,
- //4
- 0x41,0x42,0x41,0x42,0x41,0x51,0x62,0x81,0x81,0x02,0x61,0x81,
- 0x91,0x61,0x61,0x61,0x61,0x52,0x52,0x61,0x62,0x02,0x02,0x61,0x51,
- //5
- 0x42,0x21,0x21,0x02,0x61,0x51,0x42,0x21,0x21,0x02,0x21,0x41,
- 0x51,0x51,0x51,0x51,0x52,0x11,0x21,0x24,0x04,
- //6
- 0x91,0x92,0x91,0x92,0x62,0x81,0x82,0x81,0x82,0x61,0x51,
- 0x42,0x42,0x41,0x52,0x41,0x64,0x04,
- //7
- 0x91,0x92,0x91,0x92,0x91,0xa1,0x91,0x82,0x81,0x02,0x61,0x81,
- 0x92,0x62,0x51,0x42,0x81,0x84,0x04,
- //8
- 0x41,0x42,0x41,0x02,0x41,0x51,0x62,0x81,0x81,0x02,0x61,0x81,
- 0x92,0x62,0x61,0x51,0x51,0x61,0x64,0x02,0x61,0x51,
- //9
- 0x42,0x21,0x21,0x02,0x61,0x51,0x42,0x21,0x21,0x02,0x21,0x41,
- 0x51,0x51,0x51,0x51,0x52,0x11,0x21,021,0x02,0x02,0x61,0x51,
- //a
- 0x42,0x21,0x21,0x02,0x61,0x51,0x42,0x21,0x21,0x02,0x21,0x41,
- //c
- 0x51,0x51,0x51,0x51,0x52,0x12,0x24,0x02,0x61,0x51,
- 0x42,0x21,0x21,0x02,0x61,0x51,0x42,0x21,0x21,0x02,0x21,0x41,
- //d
- 0x51,0x51,0x51,0x51,0x54,0x04,0x84,
- 0x91,0x81,0x96,0x98,
- 0x9c,0x04,
- 0x00};
- code uchar SONG0 [ ]={
- //10.生日快乐
- //0
- 0x08,0x08,
- //1
- 0x83,0x81,0x94,0x84,
- 0xb4,0xa8,
- 0x83,0x81,0x94,0x84,
- 0xc4,0xb8,
- //2
- 0x83,0x81,0xf4,0xd4,
- 0xb4,0xa4,0x94,
- 0xe3,0xe1,0xd4,0xb4,
- 0xc4,0xb8,
- //3
- 0x83,0x81,0x94,0x84,
- 0xb4,0xa8,
- 0x83,0x81,0x94,0x84,
- 0xc4,0xb8,
- //4
- 0x83,0x81,0xf4,0xd4,
- 0xb4,0xa4,0x94,
- 0xe3,0xe1,0xd4,0xb4,
- 0xc4,0xb8,
- 0x00};
- uchar hjsz;
- uchar ljsz;
- uchar jpm;
- uchar yfm;
- uchar t0 =0;
- uint i=0;
- sbit Speaker =P1^0;
- uint k;
- void Delay1()
- {
- for ( k=0;k<20000;k++);
- }
- void Lignt( )
- { uchar t;
- for(t=0;t<10;t++)
- {
- P2=0xff;
- Delay1();
- P2=0x00;
- Delay1();
- }
- }
- void Lignt1( )
- {
- P2=0xaa;
- Delay1();
- P2=0x55;
- Delay1();
- }
- void Delay(uchar t0)//延时
- {
- while(t0--) //决定节拍
- Lignt1();
- }
- void Delay2(uchar w0)//延时
- {
- while(w0--) //决定节拍
- Lignt();
- }
- void T0Int() interrupt 1//TIMER0
- {
- TL0 = ljsz;
- TH0 = hjsz;
- Speaker=!Speaker;
- }
- void ExtInt0() interrupt 0//INT0
- {
- if(t0>10)
- t0=0;
- i=0; // 全局变量,指向歌谱的第1个
- switch(t0++)
- {
- case 0 : TABLE=SONG;break; //选择第1首
- case 1 : TABLE=SONG1;break;//选择第2首
- case 2 : TABLE=SONG2;break;//选择第3首
- case 3 : TABLE=SONG3;break;//选择第4首
- case 4 : TABLE=SONG4;break;//选择第5首
- case 5 : TABLE=SONG5;break;//选择第6首
- case 6 : TABLE=SONG6;break;//选择第7首
- case 7 : TABLE=SONG7;break;//选择第8首
- case 8 : TABLE=SONG8;break;//选择第9首
- case 9 : TABLE=SONG9;break;//选择第10首
- }
- }
- void songsing()//发音程序
- {
- i=0;
- while(TABLE[i])
- {
- jpm=TABLE[i]&0x0f; //节拍值
- yfm=(TABLE[i]>>0x04)&0x0f;//简谱值
- if(yfm) //简谱为1,取计数值
- {
- yfm=yfm-1;
- hjsz=(uchar)(TABLE1[yfm]>>0x08);//取计数值高字节
- TH0 = hjsz;
- ljsz=(uchar)(TABLE1[yfm]); //取计数值低字节
- TL0 = ljsz;
- TR0 = 1; //启动TIMER0
- }
- else TR0 = 0; //简谱为0,不发音
- Delay(jpm); //节拍延时
- i++;
- }
- }
- void main(void)
- {
- TMOD =0X01;//设TIMER0在MODE1
- TCON =0X01;//外部中断INT0,下降沿触发
- IE =0x83;//开中断(INT0,TIMER0)
- IP =0x00;//设置中断优先级
- TABLE=SONG0;
- while(1)
- {
- Lignt( );
- songsing();//调用发音程序
- TR0 = 0;//停止TIMER0
- Delay2(1);
- TABLE=SONG0;// 更改歌曲0
- songsing();
- }
- }
复制代码
[ 本帖最后由 zhaojun_xf 于 2013-7-14 09:46 编辑 ] |