c语言,类似打字程序,敲一字母,扬声器就清脆的响一下,如何实现。在线等,实现就给分

fogg 2005-07-18 11:08:42
while (1)
{
getch();
sound(1000);
delay(100);
nosound();
}

只是第一次按键时清脆,后面按键,扬声器声音很小,且沉闷
...全文
353 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
antijpn 2005-07-18
  • 打赏
  • 举报
回复
不要用专有函数,要是用专有函数还不如写汇编
jsjjms 2005-07-18
  • 打赏
  • 举报
回复
control = inportb(0x61); /*从扬声器读出控制信息*/

outportb(0x61,(control)|(0x3));/*写入扬声器,使之发声 */
jsjjms 2005-07-18
  • 打赏
  • 举报
回复
下面是在TC下实现。

int handle,control;
.....
song[] =
{.....各种频率...,你可以通过键盘输入并编码}
void interrupt music()
{
static int note = 0,dur = 8,fre,flag = 0;
flag++;
fre = song[note];
dur = song[note+1];
if(fre)
{
flag = 0;
outportb(0x43,0xb6); /*打开计数器*/
fre =(unsigned)(1193180L/fre);/*计算频率*/
outportb(0x42,(char)fre);
outportb(0x42,(char)(fre>>8));
control = inportb(0x61);
outportb(0x61,(control)|(0x3));
note = note+2;
if(note>134)note = 0;
}

这只是一个大概的过程.
antijpn 2005-07-18
  • 打赏
  • 举报
回复
ascii的0x07的确是响铃,但是这个似乎和楼主的要求差的远了点,TC2里面的sound可以指定频率的
qfeng_zhao 2005-07-18
  • 打赏
  • 举报
回复
up...
arden1019 2005-07-18
  • 打赏
  • 举报
回复
有个字符是可以响的吧。ascii 7
rabo 2005-07-18
  • 打赏
  • 举报
回复
MessageBeep
zaisheng09 2005-07-18
  • 打赏
  • 举报
回复
up~~
antijpn 2005-07-18
  • 打赏
  • 举报
回复
C标准库里面没有控制扬声器的函数,可能某些平台相关的库里面附带了一些使用扬声器的函数,譬如ncurses里面的beep之类的……
zx_name 2005-07-18
  • 打赏
  • 举报
回复
把sound(1000)改成sound(5000)就清脆许多
rabo 2005-07-18
  • 打赏
  • 举报
回复
The MessageBeep function plays a waveform sound. The waveform sound for each sound type is identified by an entry in the registry.


BOOL MessageBeep(
UINT uType
);

Value Meaning
-1 Simple beep. If the sound card is not available, the sound is generated using the speaker.
MB_ICONASTERISK SystemAsterisk
MB_ICONEXCLAMATION SystemExclamation
MB_ICONHAND SystemHand
MB_ICONQUESTION SystemQuestion
MB_OK SystemDefault

cqpp 2005-07-18
  • 打赏
  • 举报
回复
BOOL Beep( DWORD dwFreq, DWORD dwDuration );

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧