栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

51单片机仿真例程-蜂鸣器

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

51单片机仿真例程-蜂鸣器

通过单片机定时器输出方波,不同的频率声调不同。

#include
sbit beep = P1^5;


unsigned char code music_h[]={0xfc,0xfc,0xfc,0xfd,0xfd,0xfd,0xfe};
unsigned char code music_l[]={0x44,0xbe,0x0a,0x34,0x83,0xc8,0x06};
                            		//ad
int i;




void delay(int b)
{
  int time;
  while(--b!=0)
  {
  	 for(time=0;time<125;time++);
  
  }



}
void music(unsigned char m)
{
   int j;
   for(j=0;j<800;j++)
   {
   	while(!TF0);
	TH0=music_h[m-1];
	TL0=music_l[m-1];
	beep=~beep;
	TF0=0;

   }




}
void music_c(unsigned char m)
{
   int j;
   for(j=0;j<100;j++)
   {
   	while(!TF0);
	TH0=music_h[m-1];
	TL0=music_l[m-1];
	TF0=0;

   }




}
void main ()
{
   TMOD=0x1;
   TH0=0xfc;
   TL0=0x44;
   TR0=1;
   EA=1;
   ET0=1;
   while(1)
   {
   	delay(1000);

   	music(1);
	music_c(1);	
	music(1);
	music_c(1);
	music(5);
	music_c(1);
	music(5);
	music_c(1);
	music(6);
	music_c(1);
	music(6);
	music_c(1);
	music(5);
	music_c(5);
	music_c(5);
	music(4);
	music_c(1);
	music(4);
	music_c(1);
	music(3);
	music_c(1);
	music(3);
	music_c(1);
	music(2);
	music_c(1);
	music(2);
	music_c(1);
	music(1);
	music_c(1);								
			


	delay(1000);

	

	

   
   
   
   }





}

效果:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/297250.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号