• 大小: 2KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-07-05
  • 语言: 其他
  • 标签: 单片机  

资源简介

利用定时器和蜂鸣器唱歌,注释详细,正常编译通过,已经在单片机中测试过。

资源截图

代码片段和文件信息

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

unsigned char code SONG[] ={      //祝你平安
0x260x200x200x200x200x200x260x100x200x100x200x800x260x200x300x20
0x300x200x390x100x300x100x300x800x260x200x200x200x200x200x1c0x20
0x200x800x2b0x200x260x200x200x200x2b0x100x260x100x2b0x800x260x20
0x300x200x300x200x390x100x260x100x260x600x400x100x390x100x260x20
0x300x200x300x200x390x100x260x100x260x800x260x200x2b0x100x2b0x10
0x2b0x200x300x100x390x100x260x100x2b0x100x2b0x200x2b0x400x400x20
0x200x100x200x100x2b0x100x260x300x300x800x180x200x180x200x260x20
0x200x200x200x400x260x200x2b0x200x300x200x300x200x1c0x200x200x20
0x200x800x1c0x200x1c0x200x1c0x200x300x200x300x600x390x100x300x10
0x200x200x2b0x100x260x100x2b0x100x260x100x260x100x2b0x100x2b0x80
0x180x200x180x200x260x200x200x200x200x600x260x100x2b0x200x300x20
0x300x200x1c0x200x200x200x200x800x260x200x300x100x300x100x300x20
0x390x200x260x100x2b0x100x2b0x200x2b0x400x400x100x400x100x200x10
0x200x100x2b0x100x260x300x300x800x00
                                  //路边的野华不要采
0x300x1C0x100x200x400x1C0x100x180x100x200x100x1C0x100x180x400x1C
0x200x200x200x1C0x200x180x200x200x800xFF0x200x300x1C0x100x180x20
0x150x200x1C0x200x200x200x260x400x200x200x2B0x200x260x200x200x20
0x300x800xFF0x200x200x1C0x100x180x100x200x200x260x200x2B0x200x30
0x200x2B0x400x200x200x1C0x100x180x100x200x200x260x200x2B0x200x30
0x200x2B0x400x200x300x1C0x100x180x200x150x200x1C0x200x200x200x26
0x400x200x200x2B0x200x260x200x200x200x300x800x200x300x1C0x100x20
0x100x1C0x100x200x200x260x200x2B0x200x300x200x2B0x400x200x150x1F
0x050x200x100x1C0x100x200x200x260x200x2B0x200x300x200x2B0x400x20
0x300x1C0x100x180x200x150x200x1C0x200x200x200x260x400x200x200x2B
0x200x260x200x200x200x300x300x200x300x1C0x100x180x400x1C0x200x20
0x200x260x400x130x600x180x200x150x400x130x400x180x800x00

};

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 ij;
    for( i =0;i < x;i++ )
    {
        for( j =0;j<3;j++ );
    }
}

/*-------------------------------------------------
功能:歌曲播放子程序i为播放哪一段曲目
-------------------------------------------------*/
void Play_Song(unsigned char i)
{
unsigned char Temp1Temp2;
unsigned int Addr;
Count = 0; //中断计数器清0
Addr = i * 217;
while(1)
{
Temp1 = SONG[Addr++];

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        3704  2006-04-15 06:18  fengmingqi.c
     文件        1748  2018-08-17 11:55  fengmingqi.hex

评论

共有 条评论