51单片机蜂鸣器实现歌曲《起风了》代码

 《起风了》原唱:买辣椒也用券
于2022年1月23日晚正式回归,如果林俊杰,周深都是怀念、悲哀、青春等那么买辣椒也用券则唱出青春美好时光,怀念过往岁月,美好时光的纪念磁带,原来以2018年那种美好回忆没有疫情,生活无忧无虑,岁月神偷的过往,可我们2018年的时光如今早已回不去......


#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit voice=P1^5;   //单片机开发板型号不同需要修改为所对应的蜂鸣器管脚
uchar code sound[]={0xff,
                    0x2b,0x30,0x30,0x10,0x2b,0x30,0x30,0x10,0x2b,0x20,0x26,0x20,0x20,0x20,
                    0x26,0x20,0x2b,0x30,0x30,0x10,0x2b,0x30,0x30,0x10,0x2b,0x10,0x26,0x10,
                    0x2b,0x10,0x30,0x10,0x40,0x20,0x40,0x20,0x2b,0x30,0x30,0x10,0x2b,0x30,
                    0x30,0x10,0x2b,0x20,0x26,0x20,0x20,0x20,0x26,0x20,0x2b,0x30,0x26,0x10,
                    0x2b,0x20,0x30,0x20,0x2b,0x20,0x2b,0x20,0xff,0x20,0xff,0x20,0x2b,0x30,
					0x30,0x10,0x2b,0x30,0x30,0x10,0x2b,0x20,0x26,0x20,0x20,0x20,0x26,0x20,
					0x2b,0x30,0x26,0x10,0x2b,0x20,0x30,0x20,0x39,0x20,0x39,0x20,0x26,0x10,
					0x2b,0x10,0x30,0x10,0x2b,0x10,0x30,0x20,0x30,0x20,0x26,0x10,0x2b,0x10,
					0x30,0x10,0x2b,0x10,0x30,0x30,0x20,0x10,0x26,0x10,0x2b,0x10,0x30,0x10,
					0x2b,0x10,0x30,0x20,0x30,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,0x30,0x20,0x1c,0x20,0x20,0x10,0x1c,0x10,
                    0x1c,0x30,0x30,0x10,0x19,0x20,0x1c,0x10,0x19,0x10,0x19,0x20,0x19,0x20,
                    0x1c,0x10,0x19,0x10,0x19,0x20,0x26,0x20,0x18,0x10,0x15,0x10,0x18,0x10,
                    0x19,0x10,0x1c,0x20,0x20,0x20,0x1c,0x20,0x20,0x10,0x1c,0x10,0x1c,0x10,
                    0x20,0x10,0x1c,0x10,0x20,0x10,0x1c,0x20,0x20,0x10,0x2b,0x10,0x2b,0x10,
                    0x20,0x20,0x20,0x10,0x26,0x20,0x26,0x20,0x30,0x20,0x2b,0x20,0x26,0x20,
                    0x30,0x20,0x1c,0x20,0x20,0x10,0x1c,0x10,0x1c,0x30,0x30,0x10,0x19,0x20,
                    0x1c,0x10,0x19,0x10,0x19,0x20,0x19,0x20,0x1c,0x10,0x19,0x10,0x19,0x20,
                    0x26,0x20,0x18,0x10,0x15,0x10,0x18,0x10,0x19,0x10,0x1c,0x20,0x20,0x20,
                    0x1c,0x20,0x13,0x10,0x13,0x10,0x13,0x20,0x20,0x20,0x1c,0x20,0x13,0x10,
                    0x13,0x10,0x13,0x10,0x20,0x20,0x1c,0x10,0x1c,0x20,0x1c,0x20,0x1c,0x20,
                    0x1c,0x20,0xff,0x20,0xff,0x20,  0x18,0x20,0x15,0x20,0x13,0x20,0x0e,0x10,0x10,0x10,0x10,0x20,0x0e,0x10,
                    0x10,0x10,0x10,0x20,0x0e,0x10,0x10,0x10,0x10,0x20,0x19,0x10,0x18,0x10,
                    0x18,0x20,0x0e,0x10,0x10,0x10,0x10,0x20,0x0e,0x10,0x10,0x10,0x10,0x20,
                    0x0e,0x10,0x10,0x10,0x10,0x10,0x13,0x30,0x15,0x20,0x18,0x10,0x1c,0x10,
                    0x1c,0x10,0x18,0x20,0x1c,0x10,0x15,0x10,0x18,0x10,0x1c,0x20,0x1c,0x10,
                    0x18,0x30,0x13,0x20,0x13,0x20,0x13,0x10,0x12,0x10,0x13,0x20,0x13,0x10,
                    0x15,0x20,0xff,0x20,0xff,0x20,0x18,0x20,0x15,0x20,0x13,0x20,0x0e,0x10,0x10,0x10,
                    0x10,0x20,0x0e,0x10,0x10,0x10,0x10,0x20,0x0e,0x10,0x10,0x10,0x10,0x20,
                    0x15,0x20,0x13,0x20,0x0e,0x10,0x10,0x10,0x10,0x20,0x0e,0x10,0x10,0x10,
                    0x10,0x20,0x0e,0x10,0x10,0x10,0x10,0x10,0x13,0x30,0x15,0x20,0x18,0x10,
                    0x1c,0x10,0x1c,0x10,0x13,0x30,0x15,0x20,0x18,0x10,0x1c,0x10,0x1c,0x10,
                    0x18,0x30,0x18,0x20,0x18,0x20,0xff,0x20,0xff,0x20,0x1c,0x10,0x13,0x10,
                    
                    0x15,0x20,0x18,0x10,0x1c,0x10,0x1c,0x10,0x13,0x30,0x15,0x20,0x18,0x10,
                    0x1c,0x10,0x1c,0x10,0x18,0x30,0x18,0x20,0x18,0x20,0x18,0x20,0x18,0x20,0x00,
                   };
uchar zdjs=0, jp;
del(yj);
void main(void)
  {
      uint dpjs=0;
      uchar yj;
      TMOD=0x01,IE=0x82;
      TH0=0xd8, TL0=0xef;
   TR0=1;
while(1)
   {  
      zdjs=0;
      dpjs++; yj=sound[dpjs]; 
     dpjs++; jp=sound[dpjs];
   while(zdjs!=jp)
       { 
      if(yj!=0xff)
   {
             if(yj!=0)
               {
             voice=!voice;
                 del(yj);
                }
                else
          {
          dpjs=0; 
                      break;
                     }
    }
    else
      {
        voice=0;
                 del(jp);
    }
      }
       }
   }
time0() interrupt 1  using 1
      {
         TH0=0xd8, TL0=0xef;
         zdjs++;
           }
del(yj)
    {
      uchar yj2=2;
       while(yj!=0)
         {      
               while(yj2!=0)
                  {
                     yj2--;
                     }
                  yj2=2;
             yj--;  
       }
   
     }

  • 130
    点赞
  • 529
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 42
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 42
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骑神马驾浮云

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值