找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 15173|回复: 10
收起左侧

蜂鸣器唱歌的小程序,,,源代码加电路图

  [复制链接]
ID:85338 发表于 2015-7-11 11:10 | 显示全部楼层 |阅读模式
小程序  可以用蜂鸣器唱歌  大家参考下
回复

使用道具 举报

ID:74784 发表于 2015-7-11 11:20 | 显示全部楼层
代码在哪????????????????
回复

使用道具 举报

ID:84735 发表于 2015-7-11 12:40 | 显示全部楼层
\.o.,o,oo.o.....oool
回复

使用道具 举报

ID:85603 发表于 2015-7-15 20:12 | 显示全部楼层
fdgsfsfsscsbdcs
回复

使用道具 举报

ID:80594 发表于 2015-7-17 11:23 | 显示全部楼层
?????、
回复

使用道具 举报

ID:79544 发表于 2015-7-23 14:57 | 显示全部楼层
lxa0 发表于 2015-7-11 11:20
代码在哪????????????????
  1. /******************************************************************************/
  2. /**程序名称:单片机播放欢乐颂与最炫民族风片段
  3. /**其    他:用于时钟周期为12MHz的STC89C52单片机
  4. /**由电子乐屋整理制作,更详细的制作资料请到电子乐屋下载http://hi.baidu.com/mifklrxdjqbadoq
  5. /******************************************************************************/
  6. #include<reg52.h>
  7. sbit BUZZER = P1^7;

  8. #define uchar unsigned char
  9. #define uint  unsigned int
  10. #define REST         36                        //休止符
  11. #define A                  0                  //低音1
  12. #define AB          1                  //低音1.5
  13. #define B                  2                  //低音2
  14. #define BC          3                  //低音2.5
  15. #define C                  4                  //低音3
  16. #define D                  5                  //低音4
  17. #define DE                 6                  //低音4.5
  18. #define E                 7                       //低音5
  19. #define EF          8                  //低音5.5
  20. #define F                  9                  //低音6
  21. #define FG          10          //低音6.5
  22. #define G                 11          //低音7
  23. #define L                  12          //中音1
  24. #define LM          13          //中音1.5
  25. #define M                  14          //中音2
  26. #define MN          15          //中音2.5
  27. #define N                  16                 //中音3
  28. #define O                  17          //中音4
  29. #define OP          18          //中音4.5
  30. #define P                  19          //中音5
  31. #define PQ          20          //中音5.5
  32. #define Q                  21          //中音6
  33. #define QR          22          //中音6.5
  34. #define R                  23          //中音7
  35. #define S                  24          //高音1
  36. #define SU          25          //高音1.5
  37. #define U                  26          //高音2
  38. #define UV          27          //高音2.5
  39. #define V                  28          //高音3
  40. #define W                  29          //高音4
  41. #define WX          30          //高音4.5
  42. #define X                  31          //高音5
  43. #define XY          32          //高音5.5
  44. #define Y                  33          //高音6
  45. #define YZ          34          //高音6.5
  46. #define Z                  35          //高音7

  47. //音阶
  48. uchar code m_note[][2] = {
  49. {248,136},{248,243},{249,88},{249,184},{250,18},{250,103},{250,184},{251,3},{251,75},
  50. {251,143},{251,206},{252,11},{252,67},{252,121},{252,172},{252,219},{253,9},{253,51},
  51. {253,91},{253,129},{253,165},{253,199},{253,231},{254,5},{254,33},{254,60},{254,85},
  52. {254,109},{254,132},{254,153},{254,173},{254,192},{254,210},{254,227},{254,243},{255,2},
  53. {0,0},
  54. };


  55. //音符(1对应三十二分音符,32对应全音符)
  56. uchar code display[][2] = {
  57. //欢乐颂
  58. {N,8},{N,8},{O,8},{P,8},{P,8},{O,8},{N,8},{M,8},{L,8},{L,8},{M,8},{N,8},{N,12},{M,4},{M,8},{0xff,8},
  59. {N,8},{N,8},{O,8},{P,8},{P,8},{O,8},{N,8},{M,8},{L,8},{L,8},{M,8},{N,8},{M,12},{L,4},{L,8},{0xff,8},
  60. {M,8},{M,8},{N,8},{L,8},{M,8},{N,4},{O,4},{N,8},{L,8},{M,8},{N,4},{O,4},{N,8},{M,8},{L,8},{M,8},{E,8},
  61. {N,8},{N,8},{O,8},{P,8},{P,8},{O,8},{N,8},{M,8},{L,8},{L,8},{M,8},{N,8},{M,12},{L,4},{L,8},{0xff,8},
  62. {M,8},{M,8},{N,8},{L,8},{M,8},{N,4},{O,4},{N,8},{L,8},{M,8},{N,4},{O,4},{N,8},{M,8},{L,8},{M,8},{E,8},
  63. {N,8},{N,8},{O,8},{P,8},{P,8},{O,8},{N,8},{M,8},{L,8},{L,8},{M,8},{N,8},{M,12},{L,4},{L,8},{0xff,8},
  64. //乐谱(最炫民族风)
  65. {N,8},{F,4},{F,4},{L,8},{N,8},{M,4},{M,2},{N,2},{M,4},{L,4},
  66. {M,4},{L,4},{F,8},{N,8},{F,4},{F,4},{L,8},{N,8},
  67. {P,4},{M,2},{N,2},{M,4},{L,4},{M,4},{L,4},{G,4},{E,4},
  68. {N,8},{F,4},{F,4},{L,8},{N,8},{M,4},{M,2},{N,2},{M,4},{L,4},
  69. {M,4},{L,4},{F,4},{E,4},{N,8},{F,4},{F,4},{L,8},{N,8},
  70. {P,4},{N,4},{0xff,24},//前奏
  71. {F,8},{F,4},{E,4},{F,8},{F,4},{L,4},{L,8},{M,4},{L,4},{F,8},
  72. {0xff,8},{L,8},{L,4},{E,4},{L,4},{M,4},{N,4},{P,4},{P,4},{N,4},
  73. {M,8},{N,8},{0xff,8},{Q,4},{Q,4},{Q,4},{P,4},{N,4},{N,8},{L,4},
  74. {F,4},{F,4},{F,4},{N,4},{M,8},{0xff,8},{N,4},{N,4},{P,4},{N,4},
  75. {M,4},{N,4},{M,4},{L,4},{F,8},{E,8},{F,8},{0xff,8},
  76. {F,8},{F,4},{E,4},{F,8},{F,4},{L,4},{L,8},{M,4},{L,4},{F,8},
  77. {0xff,8},{L,8},{L,4},{E,4},{L,4},{M,4},{N,4},{P,4},{P,4},{N,4},
  78. {M,8},{N,8},{0xff,8},{Q,4},{Q,4},{Q,4},{P,4},{N,4},{N,8},{L,4},
  79. {F,4},{F,4},{F,4},{N,4},{M,8},{0xff,8},{N,4},{N,4},{P,4},{N,4},
  80. {M,4},{N,4},{M,4},{L,4},{F,8},{E,8},{F,8},{0xff,8},
  81. {N,4},{N,4},{P,4},{N,4},{N,4},{P,4},{P,4},{Q,4},{S,4},{Q,4},
  82. {P,8},{Q,8},{0xff,8}, //此处有变调
  83. {F,8},{F,4},{E,4},{F,8},{L,8},{M,4},{N,2},{M,2},{L,4},{M,4},
  84. {N,8},{0xff,8},{F,4},{Q,4},{Q,4},{P,4},{M,4},{N,2},{M,2},
  85. {L,4},{M,4},{N,8},{0xff,8},{0xff,16},{L,4},{F,4},{F,4},{L,4},
  86. {M,8},{E,4},{E,4},{N,4},{P,4},{N,4},{M,4},{L,8},{0xff,8},
  87. {F,4},{L,4},{M,4},{N,4},{M,4},{L,4},{E,4},{C,4},{F,8},{0xff,8},{0xff,16},
  88. {F,8},{F,4},{E,4},{F,8},{L,8},{M,4},{N,2},{M,2},{L,4},{M,4},
  89. {N,8},{0xff,8},{F,4},{Q,4},{Q,4},{P,4},{M,4},{N,2},{M,2},
  90. {L,4},{M,4},{N,8},{0xff,8},{0xff,16},{L,4},{F,4},{F,4},{L,4},
  91. {M,8},{E,4},{E,4},{N,4},{P,4},{N,4},{M,4},{L,12},{L,4},
  92. {F,4},{L,4},{M,4},{N,4},{P,4},{N,4},{N,4},{P,4},{Q,8},{0xff,8},{0xff,8},

  93. {Q,6}, {Q,2},{Q,4},{Q,4},{Q,6},{P,2},{N,4},{M,4},{M,6},{M,2},{N,6},{P,2},{N,6},{M,2},
  94. {L,6},{F,2},{F,8},{F,4},{E,4},{F,8},{F,4},{L,4}, {M,4},{N,2},{M,2},        {L,4},{M,4},{N,8},{0xff,8},
  95. {Q,4},{P,4},{N,4},{M,4},{P,4},{N,4},{M,4},{L,4},{L,8},{0xff,8},{F,2}, {A,2},{B,2},{C,2},{B,2},
  96. {A,2}, {F,2},{A,2},

  97. {N,4},{N,4},{P,4},{N,4},{N,4},{P,4},{P,4},{Q,4},{S,4},{Q,4},
  98. {P,8},{Q,8},{0xff,8}, //此处有变调
  99. {F,8},{F,4},{E,4},{F,8},{L,8},{M,4},{N,2},{M,2},{L,4},{M,4},
  100. {N,8},{0xff,8},{F,4},{Q,4},{Q,4},{P,4},{M,4},{N,2},{M,2},
  101. {L,4},{M,4},{N,8},{0xff,8},{0xff,16},{L,4},{F,4},{F,4},{L,4},
  102. {M,8},{E,4},{E,4},{N,4},{P,4},{N,4},{M,4},{L,8},{0xff,8},
  103. {F,4},{L,4},{M,4},{N,4},{M,4},{L,4},{E,4},{C,4},{F,8},{0xff,8},{0xff,16},
  104. {F,8},{F,4},{E,4},{F,8},{L,8},{M,4},{N,2},{M,2},{L,4},{M,4},
  105. {N,8},{0xff,8},{F,4},{Q,4},{Q,4},{P,4},{M,4},{N,2},{M,2},
  106. {L,4},{M,4},{N,8},{0xff,8},{0xff,16},{L,4},{F,4},{F,4},{L,4},
  107. {M,8},{E,4},{E,4},{N,4},{P,4},{N,4},{M,4},{L,12},{L,4},
  108. {F,4},{L,4},{M,4},{N,4},{P,4},{N,4},{N,4},{P,4},{Q,8},{0xff,8},{0xff,8},
  109. {0,0xff},
  110. };
  111. uchar time_h,time_l;
  112. void Delay(uchar x);

  113. void main()
  114. {
  115.         uchar j;
  116.         uint i;
  117.         TMOD = 0x01;
  118.         ET0 = 1;
  119.         EA = 1;
  120.         TR0 = 1;
  121.         i = 0;
  122.         j = 0;
  123.         while(1)
  124.         {
  125.                 while(display[i][1] != 0xff)
  126.                 {
  127.                         if(display[i][0] == 0xff)
  128.                         {
  129.                                 TR0 = 0;
  130.                                 Delay(display[i][1]);
  131.                             BUZZER = 1;       
  132.                         }
  133.                         else
  134.                         {
  135.                                 time_h = m_note[display[i][0]][0];
  136.                                 time_l = m_note[display[i][0]][1];
  137.                                 TH0 = time_h;
  138.                                 TL0 = time_l;
  139.                                 ET0 = 1;
  140.                                 TR0 = 1;
  141.                                 Delay(display[i][1]);
  142.                                 TR0 = 0;
  143.                                 ET0 = 0;
  144.                             BUZZER = 1;       
  145.                         }                       
  146.                         i++;
  147.                 }
  148.                 i = 0;
  149.         }
  150. }

  151. void Timer0() interrupt 1
  152. {
  153.         TR0 = 0;
  154.         TH0 = time_h;
  155.         TL0 = time_l;
  156.         BUZZER = ~BUZZER;
  157.         TR0 = 1;
  158. }

  159. void Delay(uchar x)
  160. {
  161.         uint i,j;
  162.         for(i = 0;i < x;i++)
  163.                 for(j = 0;j < 12000;j++);
  164. }
复制代码
回复

使用道具 举报

ID:86380 发表于 2015-7-31 09:48 | 显示全部楼层
唱得好听吗?
回复

使用道具 举报

ID:140363 发表于 2016-11-8 11:59 | 显示全部楼层
有电路图吗
回复

使用道具 举报

ID:272432 发表于 2018-1-6 20:21 | 显示全部楼层
什么基于51单片机数码管的时钟
回复

使用道具 举报

ID:280994 发表于 2018-2-2 23:11 | 显示全部楼层
乐谱是怎么来的?
回复

使用道具 举报

ID:275479 发表于 2018-2-3 07:19 | 显示全部楼层
对啊  乐谱怎么来的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表