那个用单片机编写《小草》程序的人在吗

2019-03-24 19:56发布

可不可以吧《小草》的单片机程序发给我啊? 234901369@qq.com 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
6条回答
常见泽1
1楼-- · 2019-03-25 04:44
没看到过 就是蜂鸣器放小草?
fennairenwei
2楼-- · 2019-03-25 09:35
 精彩回答 2  元偷偷看……
jckimi
3楼-- · 2019-03-25 12:47
囧。。。这个应该很简单啊。。。
dreamflysuccess
4楼-- · 2019-03-25 18:44
怎么编写呢?谢谢
yxf01
5楼-- · 2019-03-25 21:11

论坛有个前辈发的蜂鸣器取模的工具软件,直接找个简谱对照着把简谱输入进去转换好了在KEIL里参照其他的例程就可以了吧?

我才接触单片机,正在学,现在也只会点亮一只发光管。

下边是个例程

 

 

#include "reg52.h"
unsigned char Count;
sbit _Speak =P2^3 ;   //讯响器控制脚 

unsigned char code SONG[] ={      //祝你平安
0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x10,0x20,0x10,0x20,0x80,0x26,0x20,0x30,0x20,
0x30,0x20,0x39,0x10,0x30,0x10,0x30,0x80,0x26,0x20,0x20,0x20,0x20,0x20,0x1c,0x20,
0x20,0x80,0x2b,0x20,0x26,0x20,0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x80,0x26,0x20,
0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x60,0x40,0x10,0x39,0x10,0x26,0x20,
0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x80,0x26,0x20,0x2b,0x10,0x2b,0x10,
0x2b,0x20,0x30,0x10,0x39,0x10,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x20,
0x20,0x10,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x18,0x20,0x18,0x20,0x26,0x20,
0x20,0x20,0x20,0x40,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20,
0x20,0x80,0x1c,0x20,0x1c,0x20,0x1c,0x20,0x30,0x20,0x30,0x60,0x39,0x10,0x30,0x10,
0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x10,0x26,0x10,0x26,0x10,0x2b,0x10,0x2b,0x80,
0x18,0x20,0x18,0x20,0x26,0x20,0x20,0x20,0x20,0x60,0x26,0x10,0x2b,0x20,0x30,0x20,
0x30,0x20,0x1c,0x20,0x20,0x20,0x20,0x80,0x26,0x20,0x30,0x10,0x30,0x10,0x30,0x20,
0x39,0x20,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x10,0x40,0x10,0x20,0x10,
0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x00,
                                  //路边的野华不要采
0x30,0x1C,0x10,0x20,0x40,0x1C,0x10,0x18,0x10,0x20,0x10,0x1C,0x10,0x18,0x40,0x1C,
0x20,0x20,0x20,0x1C,0x20,0x18,0x20,0x20,0x80,0xFF,0x20,0x30,0x1C,0x10,0x18,0x20,
0x15,0x20,0x1C,0x20,0x20,0x20,0x26,0x40,0x20,0x20,0x2B,0x20,0x26,0x20,0x20,0x20,
0x30,0x80,0xFF,0x20,0x20,0x1C,0x10,0x18,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,
0x20,0x2B,0x40,0x20,0x20,0x1C,0x10,0x18,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,
0x20,0x2B,0x40,0x20,0x30,0x1C,0x10,0x18,0x20,0x15,0x20,0x1C,0x20,0x20,0x20,0x26,
0x40,0x20,0x20,0x2B,0x20,0x26,0x20,0x20,0x20,0x30,0x80,0x20,0x30,0x1C,0x10,0x20,
0x10,0x1C,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,0x20,0x2B,0x40,0x20,0x15,0x1F,
0x05,0x20,0x10,0x1C,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,0x20,0x2B,0x40,0x20,
0x30,0x1C,0x10,0x18,0x20,0x15,0x20,0x1C,0x20,0x20,0x20,0x26,0x40,0x20,0x20,0x2B,
0x20,0x26,0x20,0x20,0x20,0x30,0x30,0x20,0x30,0x1C,0x10,0x18,0x40,0x1C,0x20,0x20,
0x20,0x26,0x40,0x13,0x60,0x18,0x20,0x15,0x40,0x13,0x40,0x18,0x80,0x00,

};

void Time0_Init()
{
 TMOD = 0x01;
 IE   = 0x82;
 TH0  = 0xD8;
 TL0  = 0xEF;  //12MZ晶振,10ms
}

void Time0_Int() interrupt 1
{
 TH0 = 0xD8;
 TL0 = 0xEF;
 Count++;   //长度加1
}

/*-------------------------------------------------
功能:1MS延时子程序
-------------------------------------------------*/
void Delay_xMs(unsigned int x)
{
    unsigned int i,j;
    for( i =0;i < x;i++ )
    {
        for( j =0;j<3;j++ );
    }
}

/*-------------------------------------------------
功能:歌曲播放子程序i为播放哪一段曲目
-------------------------------------------------*/
void Play_Song(unsigned char i)
{
 unsigned char Temp1,Temp2;
 unsigned int Addr;
 Count = 0;      //中断计数器清0
 Addr = i * 217;
 while(1)
 {
  Temp1 = SONG[Addr++];
     if ( Temp1 == 0xFF )          //休止符
     {
      TR0 = 0;
      Delay_xMs(100);
     }
     else if ( Temp1 == 0x00 )   //歌曲结束符
     {
      return;
     }
     else
     {
      Temp2 = SONG[Addr++];
      TR0 = 1;
     while(1)
     {
       _Speak = ~_Speak;
       Delay_xMs(Temp1);
       if ( Temp2 == Count )
       {
        Count = 0;
        break;
       }
      }
     }
 }
}
/*-------------------------------------------------
功能:主程序
-------------------------------------------------*/
void main()
{
 Time0_Init();   //定时器0中断初始化
 while(1)
 {
  Play_Song(0);  //播放
 }
}

 

 

上边例程为郭天祥老师的51单片机套件中的例程,在这说明下。

[ 本帖最后由 yxf01 于 2011-5-31 20:45 编辑 ]
yxf01
6楼-- · 2019-03-26 01:21

蜂鸣器要用无源的,有源的蜂鸣器声音非常非常的差

[ 本帖最后由 yxf01 于 2011-5-31 20:31 编辑 ]

一周热门 更多>