A. 如何用单片机做音响
用一个三极管就行了,要的话我给你电路图,刚做好,效果还不错
B. 单片机怎样用于音响中
单片机用于音响中,用单片机做一个简单的播放器:外接一个蜂鸣器,将曲谱存进单片机,控制播放的花样。
旋转编码器的解码
旋转编码器(外形参见图II-1.0)在音响中多用于取代普通的滑动电阻电位器作为音量/音调控制的编码输入。它使用寿命长达100万次,比普通电位器长得多,而且不会因为机械磨损造成阻值的偏差,影响声道的平衡。其调节的精度仅仅取决于与MCU配合的音量控制芯片的控制级数,与本身的旋转角度无关,这也是普通电位器无法做到的,因此旋转编码器也大量地用于精密仪器的调节上。
旋转编码器内部就是两个长寿命开关,可以根据旋转方向产生不同相位信号。电路如图II-1.1所示:当我们顺时针旋转时,开关A的输出信号A signal相位超前;如果我们逆时针旋转时,则是开关B的输出信号B signal相位超前,我们把A/B端分别接到MCU的两个输入端口,并在MCU内设置一个音量计数器;就可以用软件来判别是顺时针旋转还是逆时针旋转,以此判断是增加还是减少音量计数器的值,最后把这个计数值送到相应的电子音量控制芯片就可以实现音量(或者其他需要增量/减量的)控制了。
由于旋转编码器是随时改变的,软件也要能够跟踪各个瞬时的状态变化,为了判断旋转编码器的相位我们还需要用三个标志位(Bit变量)来记住开关A,B的“瞬时状态”。
C. 单片机高手进(做电子音响)
楼上说的da做我还真没有看懂,da不是出电平的吗?这里要做频率,用da不用定时器恐怕不可能做到。还有,我敢说8032做这个绰绰有余。
另外楼主说的已经很清楚了,这个设计毫无难度可言,只要你会用单片机就能做,如果用汇编写我可以给个流程图:
a,b是我起的名字,用来表示定时器的待装值,你可以选r0,r1
主程序(在这里死循环)
{1.检测按键并去抖,没有检测到按键就clr
tr0关定时器,这句必须有,然后返回主程序继续循环吧.不知道你的按键是怎么做的所以没法写
2.分辨按键,进入对应的子程序
3.子程序1(所有子程序除了定时器初值不同外全部一样)
{将对应定时器初值送入a,b,开定时器,返回主程序.一共就这3句}
}
定时期中断程序:
{将ab内容装入tl0,th0,一共就2句}
当然任何汇编的开头设置中断向量,绝对跳转,设置中断和堆栈初值的语句我就省了.
程序解释:(似乎没的解释)
检测到按键就把事先计算好的初值装入ab并打开定时器,此时定时器过极短时间打开(这里没有设初值是因为按键第1次后再检测到会影响到定时期自己装初值,从而影响频率.所以这里不设初值,任由初值为任何值都会在人类无法感到的短时间内溢出并开始装入正确的初值),开始按正常频率装入初值、并发出对应频率的声音,然后继续检测按键,检测不到按键就关定时期,检测到别的按键重新装入ab值,发出新的声音.
D. 求一51单片机音响程序
这个一个模拟电子琴的程序,供参考
T0H EQU 30H
T0L EQU 31H
ORG 0000H
LJMP MAIN
ORG 000BH
LJMP T0ISR
ORG 0030H
MAIN:
MOV SP,#5FH
MOV TMOD,#01H
SETB ET0
SETB EA
LOOP:
MOV DPTR,#FREQ
MOV A,P2 ;控制高中低音区
MOV R1,#0
ANL A,#03H
JB ACC.0,LOOP01
MOV R1,#14
SJMP LOOP0
LOOP01:
JB ACC.1,LOOP0
MOV R1,#28
LOOP0:
JB P0.0,LOOP1 ;控制音频1234567
MOV A,R1
MOVC A,@A+DPTR
MOV T0H,A
INC DPTR
MOV A,R1
MOVC A,@A+DPTR
MOV T0L,A
LJMP LOOP
LOOP1:
JB P0.1,LOOP2
MOV A,R1
ADD A,#2
MOVC A,@A+DPTR
MOV T0H,A
INC DPTR
MOV A,R1
ADD A,#2
MOVC A,@A+DPTR
MOV T0L,A
LJMP LOOP
LOOP2:
JB P0.2,LOOP3
MOV A,R1
ADD A,#4
MOVC A,@A+DPTR
MOV T0H,A
INC DPTR
MOV A,R1
ADD A,#4
MOVC A,@A+DPTR
MOV T0L,A
LJMP LOOP
LOOP3:
JB P0.3,LOOP4
MOV A,R1
ADD A,#6
MOVC A,@A+DPTR
MOV T0H,A
INC DPTR
MOV A,R1
ADD A,#6
MOVC A,@A+DPTR
MOV T0L,A
LJMP LOOP
LOOP4:
JB P0.4,LOOP5
MOV A,R1
ADD A,#8
MOVC A,@A+DPTR
MOV T0H,A
INC DPTR
MOV A,R1
ADD A,#8
MOVC A,@A+DPTR
MOV T0L,A
LJMP LOOP
LOOP5:
JB P0.5,LOOP6
MOV A,R1
ADD A,#10
MOVC A,@A+DPTR
MOV T0H,A
INC DPTR
MOV A,R1
ADD A,#10
MOVC A,@A+DPTR
MOV T0L,A
LJMP LOOP
LOOP6:
JB P0.6,LOOP7
MOV A,R1
ADD A,#12
MOVC A,@A+DPTR
MOV T0H,A
INC DPTR
MOV A,R1
ADD A,#12
MOVC A,@A+DPTR
MOV T0L,A
LJMP LOOP
LOOP7:
CLR TR0
LJMP LOOP
;-----------------------------
T0ISR:
CLR TR0
MOV TH0,T0H
MOV TL0,T0L
SETB TR0
CPL P3.0
RETI
;-----------------------------
FREQ:
DB 0F2H,03DH ;低音1
DB 0F3H,0BDH ;低音2
DB 0F5H,014H ;低音3
DB 0F5H,0B1H ;低音4
DB 0F6H,0D0H ;低音5
DB 0F7H,0D1H ;低音6
DB 0F8H,0B5H ;低音7
DB 0F9H,01EH ;中音1
DB 0F9H,0DEH ;中音2
DB 0FAH,08AH ;中音3
DB 0FAH,0D8H ;中音4
DB 0FBH,068H ;中音5
DB 0FBH,0E8H ;中音6
DB 0FCH,05AH ;中音7
DB 0FCH,08FH ;高音1
DB 0FCH,0EFH ;高音2
DB 0FDH,045H ;高音3
DB 0FDH,06CH ;高音4
DB 0FDH,0B4H ;高音5
DB 0FDH,0F4H ;高音6
DB 0FEH,029H ;高音7
;-----------------------------
END
E. 51单片机做音响
喇叭4欧姆的只影响效率,不影响输出的,可以使用
F. 怎样用单片机控制音响的音量
单片机控制音响的音量的方式有两种:
一种是控制音响音量的采用马达电位器,单片机控制马达顺时针或逆时针转动,实现音量控制。和传统的电位器相比相当于在普通电位器基础上增加了马达实现音量控制,这类电位器的尺寸比较大,而且因为马达经常转动,故障率相对较高。
还有种是采用集成电路来实现:用专用的音量控制集成电路加上编码开关(也叫数字电位器)配合单片机程序实现对音量控制。例如PTC(台湾普城 http://www.princeton.com.tw)品牌的PT2313等,和马达控制相比较有可靠性高,体积小的优点。
G. 单片机电子音响
我以《两只蝴蝶》为例:#include <reg51.h>
#define led P1
#define SYSTEM_OSC 11059200
#define SOUND_SPACE 4/5
sbit BeepIO = P3^5; unsigned int code FreTab[12] = { 262,277,294,311,330,349,369,392,415,440,466,494 };
unsigned char code SignTab[7] = { 0,2,4,5,7,9,11 };
unsigned char code LengthTab[7]= { 1,2,4,8,16,32,64 };
unsigned char Sound_Temp_TH0,Sound_Temp_TL0;
unsigned char Sound_Temp_TH1,Sound_Temp_TL1;unsigned char code Music_Girl[];
unsigned char code Music_Same[];
unsigned char code Music_Two[];
void InitialSound(void)
{
BeepIO = 1;
Sound_Temp_TH1 = (65535-(1/1200)*SYSTEM_OSC)/256;(10ms的初装值)
Sound_Temp_TL1 = (65535-(1/1200)*SYSTEM_OSC)%256;
TH1 = Sound_Temp_TH1;
TL1 = Sound_Temp_TL1;
TMOD |= 0x11;
ET0 = 1;
ET1 = 0;
TR0 = 0;
TR1 = 0;
EA = 1;
}void BeepTimer0(void) interrupt 1
{
BeepIO = !BeepIO;
TH0 = Sound_Temp_TH0;
TL0 = Sound_Temp_TL0;
}
void Play(unsigned char *Sound,unsigned char Signature,unsigned Octachord,unsigned int Speed)
{
unsigned int NewFreTab[12];
unsigned char i,j;
unsigned int Point,LDiv,LDiv0,LDiv1,LDiv2,LDiv4,CurrentFre,Temp_T,SoundLength;
unsigned char Tone,Length,SL,SH,SM,SLen,XG,FD;
for(i=0;i<12;i++)
{
j = i + Signature;
if(j > 11)
{
j = j-12;
NewFreTab[i] = FreTab[j]*2;
}
else
NewFreTab[i] = FreTab[j]; if(Octachord == 1)
NewFreTab[i]>>=2;
else if(Octachord == 3)
NewFreTab[i]<<=2;
} SoundLength = 0;
while(Sound[SoundLength] != 0x00)
{
SoundLength+=2;
}Point = 0;
Tone = Sound[Point];
Length = Sound[Point+1]; LDiv0 = 12000/Speed;
LDiv4 = LDiv0/4;
LDiv4 = LDiv4-LDiv4*SOUND_SPACE;
TR0 = 0;
TR1 = 1;
while(Point < SoundLength)
{
SL=Tone%10;
SM=Tone/10%10;
SH=Tone/100;
CurrentFre = NewFreTab[SignTab[SL-1]+SH];
if(SL!=0)
{
if (SM==1) CurrentFre >>= 2;
if (SM==3) CurrentFre <<= 2;
Temp_T = 65536-(50000/CurrentFre)*10/(12000000/SYSTEM_OSC);
Sound_Temp_TH0 = Temp_T/256;
Sound_Temp_TL0 = Temp_T%256;
TH0 = Sound_Temp_TH0;
TL0 = Sound_Temp_TL0 + 12;
}
SLen=LengthTab[Length%10];
XG=Length/10%10;(0普通1连音2顿音)
FD=Length/100;
LDiv=LDiv0/SLen;
if (FD==1)
LDiv=LDiv+LDiv/2;
if(XG!=1)
if(XG==0)
if (SLen<=4)
LDiv1=LDiv-LDiv4;
else
LDiv1=LDiv*SOUND_SPACE;
else
LDiv1=LDiv/2;
else
LDiv1=LDiv;
if(SL==0) LDiv1=0;
LDiv2=LDiv-LDiv1;
if (SL!=0)
{
TR0=1;
for(i=LDiv1;i>0;i--)
{
while(TF1==0);
TH1 = Sound_Temp_TH1;
TL1 = Sound_Temp_TL1;
TF1=0;
}
}
if(LDiv2!=0)
{
TR0=0; BeepIO=1;
for(i=LDiv2;i>0;i--)
{
while(TF1==0);
TH1 = Sound_Temp_TH1;
TL1 = Sound_Temp_TL1;
TF1=0;
}
}
Point+=2;
Tone=Sound[Point];
Length=Sound[Point+1];
}
BeepIO = 1;
}
#endif
void delay();
void main(void)
{
unsigned int n;
while(1)
{
led=0xfe;
delay();
for(n=0;n<6;n++)
{
led=led<<1;
delay();
}
}
}
void delay()
{
unsigned int m;
for(m=0;m<20000;m++)
{
}
InitialSound();
Play(Music_Two,11,2,300);
Play(Music_Girl,11,2,300);
Play(Music_Same,12,2,400);
}
unsigned char code Music_Two[]={ 0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03,
0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02,
0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03,
0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x16,0x03,
0x17,0x01, 0x16,0x03, 0x17,0x03, 0x16,0x03, 0x15,0x01,
0x10,0x03, 0x15,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03,
0x16,0x03, 0x15,0x03, 0x10,0x03, 0x15,0x03, 0x16,0x01,
0x17,0x03, 0x16,0x03, 0x17,0x01, 0x16,0x03, 0x17,0x03,
0x16,0x03, 0x15,0x01, 0x10,0x03, 0x15,0x03, 0x16,0x02,
0x16,0x0D, 0x17,0x03, 0x16,0x03, 0x15,0x03, 0x10,0x03,
0x10,0x0E, 0x15,0x04, 0x0F,0x01, 0x17,0x03, 0x19,0x03,
0x19,0x01, 0x19,0x03, 0x1A,0x03, 0x19,0x03, 0x17,0x01,
0x16,0x03, 0x16,0x03, 0x16,0x02, 0x16,0x0D, 0x17,0x03,
0x16,0x03, 0x15,0x03, 0x10,0x03, 0x10,0x0D, 0x15,0x00,
0x19,0x03, 0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03,
0x1B,0x03, 0x1A,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x03,
0x16,0x0D, 0x17,0x01, 0x17,0x03, 0x17,0x03, 0x19,0x03,
0x1A,0x02, 0x1A,0x02, 0x10,0x03, 0x17,0x0D, 0x16,0x03,
0x16,0x01, 0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03,
0x19,0x02, 0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E,
0x1B,0x04, 0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E,
0x1B,0x04, 0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03,
0x17,0x0D, 0x16,0x03, 0x17,0x03, 0x19,0x01, 0x19,0x03,
0x19,0x03, 0x1A,0x03, 0x1F,0x03, 0x1B,0x03, 0x1B,0x03,
0x1A,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x03, 0x16,0x03,
0x17,0x01, 0x17,0x03, 0x17,0x03, 0x19,0x03, 0x1A,0x02,
0x1A,0x02, 0x10,0x03, 0x17,0x0D, 0x16,0x03, 0x16,0x01,
0x17,0x03, 0x19,0x03, 0x19,0x03, 0x17,0x03, 0x19,0x03,
0x1F,0x02, 0x1B,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
0x17,0x02, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
0x17,0x16, 0x1A,0x03, 0x1A,0x03, 0x1A,0x0E, 0x1B,0x04,
0x1A,0x03, 0x19,0x03, 0x17,0x03, 0x16,0x03, 0x0F,0x02,
0x10,0x03, 0x15,0x00, 0x00,0x00 };
H. 单片机,组合音响
单机片你可以设置组合音响啊只能认你自己安装
I. 单片机怎么控制喇叭出声音
。一般来说用的是三极管驱动扬声器,然后让单片机控制三极管的基极要有硬件电路图才能说原理。
J. 51单片机实验 电子音响
0FEH是数字,H表示这个数字是16进制的数,FE就是这个数字,是一个八位的数字,换算2进制是11111110,0是数字前坠,如果整个数字串的第一个数字是字母的话,单片机会当成命令来识别,所以就要加个0表示这是一个数字,让单片机能更好的识别,在这个表里面都好像0FEH就是用来做时间的