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就是用來做時間的