① 如何用c语言编一个发出声音的程序
这个唱 多来米法少
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
main()
{
Beep(523,500);
Beep(587,500);
Beep(659,500);
Beep(698,500);
Beep(784,500);
Beep(880,500);
Beep(980,500);
Beep(1060,500);
Sleep(500);
Beep(523,500);
Beep(587,500);
Beep(659,500);
Beep(698,500);
Beep(784,500);
}
② c语言主板发声程序
while (c==('Y'|'y'));
改成:
while ( c == 'Y' || c == 'y' ));
③ 单片机用C语言让蜂鸣器发出两种声调,怎么编程
让蜂鸣器发出两种不同的声调很容易,只要给蜂鸣器的控制信号发送不同频率的脉冲就可以实现了,以下以延时方式来做。
#include<reg51.h>
#define
uchar
unsigned
char
#define
uint
unsigned
int
sbit
SPK=P1^0;
sbit
K1=P1^7;
//发声函数
void
Alarm(uchar
t)
{
uchari,j;
for(i=0;i<200;i++)
{
SPK=~SPK;
for(j=0;j<t;j++);
//由参数t行成不同的频率
}
}
voidmain()
{
SPK=0;
while(1)
{
if(K1==1)
{
Alarm(90);
Alarm(120);
}
}
}
④ 求c语言程序:按键的时候发声,松开后就不响
要是你需要的是汇编就好了!
⑤ c语言:发声的问题
不同型号笔记本上蜂鸣器不一样!有的是直接的蜂鸣器!有的则是用声卡模拟,受bios控制!C下发声程序走蜂鸣器,直接控制硬件,声卡模拟不了的!你换IBM的本本试试!一般都可以正常发声!
⑥ C语言 用 \a 发出系统声音(嘟嘟嘟嘟……)
int max = 1000;//这里可以自己定义要响的次数.
int count = 0;
while(count < max)
{
printf("\a");
count++;
}
⑦ 帮忙编写一个C语言程序,运行是可以播放出声音,要能运行无错误的,非常着急,这是要交的作业,谢谢!
/*
学习内容:1、应用定时器。2、用io口控制交流蜂鸣器发声。3、结合声乐原理播放音乐。
程序效果:下载此程序后会听到蜂鸣器响起《八月桂花香》曲子。
*/
//*******soundplay.h**********
#include<reg51.h>
#ifndef __SOUNDPLAY_H_REVISION_FIRST__
#define __SOUNDPLAY_H_REVISION_FIRST__
#define byte unsigned char
#define word unsigned int
sbit led1=P0^0;
sbit led2=P0^1;
sbit led3=P0^2;
sbit led4=P0^3;
sbit led5=P0^4;
sbit led6=P0^5;
sbit led7=P0^6;
sbit led8=P0^7;
sbit led_k=P2^7; //8个发光二极管阴极端
sbit shu1=P2^6; //第1位数码管共阴端
sbit shu2=P2^5; //第2位数码管共阴端
sbit shu3=P2^4; //第3位数码管共阴端
sbit shu4=P2^3; //第4位数码管共阴端
sbit speaker=P3^3; //蜂鸣器控制端
word counter=0;
byte code array[]=
{
0x18, 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
};
#endif
byte data count=0;
void init_com()
{
TMOD=0x01;
TH0=0xff;
TL0=0xff;
EA=1;
ET0=1;
}
void timer0(void) interrupt 1 using 3
{
counter=counter+1; //节拍次数计数
TH0=0xd8; //定义单位节拍的延时大小
TL0=0xef;
}
void delay(byte n)
{
byte i;
while(n--)
for(i=0;i<125;i++); //延时1毫秒
}
void sound_delay(byte n)
{
byte i;
while(n--)
{
for(i=0;i<2;i++);
}
}
void main()
{
word i;
byte sound_signal;//定义音符大小
byte sound_pace;//定义节拍大小
led_k=0; /*关闭8个led的总开关*/
shu1=shu2=shu3=shu4=0; /*关闭数码管,否则数码管会拉低P0口电平,导致流水灯不亮*/
init_com() ;
//array[i]=0x00 代表歌曲演唱完毕
//array[i]=0xff 代表是休止符
sound_delay(10);
while(1)
{
i=0;
while(array[i]!=0x00)
{
//如果是休止符,延时100ms,并终止本次循环,进入下一个循环
if(array[i]==0xff)
{
TR0=0;
i++;
delay(100);
//continue;
}
//从表中取得 音符大小
sound_signal=array[i];
i=i+1;
//从表中取得 节拍大小
sound_pace=array[i];
TR0=1;
//当节拍数未达到时候,继续循环,产生该音调的声音
while(counter!=sound_pace)
{
speaker=~speaker;
sound_delay(sound_signal);
}
i++;
counter=0;//节拍计数器置0,进入下一个音调
}
delay(10); //歌曲演唱完毕后,延时一段时间
}
}
⑧ 怎样用C语言以最简单的方式让电脑蜂鸣器发出声音
你的代码改成 printf("\007");
这样试试看!
补充一下,还有是有的机子本身就屏蔽了这个声音,像我的电脑,这个声音就发不出来。
⑨ ubuntu 如何在C语言的程序里面让扬声器或者蜂鸣器发声
试试这个
intspeaker(unsignedintfreq,unsignedintdelay)
{staticintflag=0,bit;
if(flag==0)
{
flag=1;
iopl(3);
}
outb(0xb6,0x43);
outb((freq&0xff),0x42);
outb((freq>>8),0x42);
bit=inb(0x61);
outb(3|bit,0x61);
usleep(10000*delay);
outb(0xfc|bit,0x61);
}
#include<sys/io.h>
#include<unistd.h>
main()
{
inti;
for(i=0;i<1;i++)
{
speaker(2000,40);
sleep(2);
}
speaker(1000,40);
}
希望对你有帮助。
⑩ 不用旋律只是单调的发声蜂鸣器用C语言怎么的程序
Windows下蜂鸣器发生函数API:
BOOL Beep(DWORD dwFreq,DWORD dwDuration);
第一个参数是发音频率:范围37~32767第二个参数是发声时间:毫秒
例如:Beep( 750, 300 );