130 likes | 225 Views
4-8 IO_speaker. 利用 HT66F50 中 PC4 腳位輸出特性 控制 speaker 發聲. 喇叭發聲原理 利用喇叭上的線圈通上電流造成薄膜振動 振動推動空氣產生聲音. LA 之頻率為 440KHz 每隔半音頻率增加為 1.059 倍 DO RE MI FA SOL LA TI DO’ TI=440KHz * 1.059 * 1.059 =493.9 Hz DO’= TI=440KHz * 1.059 * 1.059 * 1.059 =523Hz. 方波每一週期有 HIGH LOW 各一半. ;PROGRAM : 4-8.ASM
E N D
4-8 IO_speaker 利用HT66F50 中PC4腳位輸出特性 控制speaker 發聲
喇叭發聲原理 • 利用喇叭上的線圈通上電流造成薄膜振動 • 振動推動空氣產生聲音
LA之頻率為440KHz • 每隔半音頻率增加為1.059倍 • DO RE MI FA SOL LA TI DO’ • TI=440KHz * 1.059 * 1.059 =493.9 Hz • DO’= TI=440KHz * 1.059 * 1.059 * 1.059 =523Hz
;PROGRAM : 4-8.ASM ;FUNCTION: Generate Tone Do~Do PC4 I/O pin #INCLUDE HT66F50.INC ;-------------------------------------------------------------------- MY_DATA .SECTION 'DATA' ;== DATA SECTION == DEL1 DB ? PITCH DB ? COUNT1 DB ? COUNT2 DB ? ;-------------------------------------------------------------------- SPK_PORT EQU PC.4 ;define speak port SPK_PORTC EQU PCC.4 MY_CODE .SECTION AT 0 'CODE' ;== PROGRAM SECTION == ORG 00H ;HT-66F50 RESET VECTOR CLEAR SPK_PORTC ;PCC.4=0
MAIN: MOVE A,TAB_PITCH_DURATION MOVE TBLP,A ;Initial table pointer NEXT_PITCH: TABRDL PITCH ;Load Pitch/Duration to Pitch/TBLH CLEAR ACC XOR A,TBLH ; TBLH, read only SZ Z ; Is last tone JMP MAIN ;yes, restart MOV COUNT1,A ;No, load Duration to Count1 INC TBLP LOOP: MOVE A,10 MOVE COUNT2,A ;inner loop count
HI: SET SPK_PORT ;Set SPK_PORT High MOVE A,PITCH CALL DELAY ;Pitch delay CLR SPK_PORT ;Reset SPK_PORT Low MOVE A,PITCH CALL DELAY ;Pitch delay SDZ COUNT2 ;inner loop ok JUMP HI ;NO. SDZ CONUT1 ;Outer loop ok JMP LOOP ;No. JMP NEXT_PITCH ;yes, next pitch
ACC*10us ,(ACC*9+1) cycles DELAY PROC MOV DEL1,A ;SET DEL1 COUNTER DEL_1: TABRDL ACC TABRDL ACC TABRDL ACC SDZ DEL1 ;DEL1 DOWN COUNT JMP DEL_1 RET DELAY ENDP ORG LASTPAGE
1000000/(523*2*10) DO TONE523/(2*10) DURATION TAB_PITCH_DURATION: DC 1000000/(523*2*10)+(523)/(2*10))SHL 8 ;Do tone & Duration DC 1000000/(587*2*10)+(587)/(2*10))SHL 8 ;Re tone & Duration DC 1000000/(659*2*10)+(659)/(2*10))SHL 8 ;MI tone & Duration DC 1000000/(698*2*10)+(698)/(2*10))SHL 8 ;FA tone & Duration DC 1000000/(785*2*10)+(785)/(2*10))SHL 8 ;SoL tone & Duration DC 1000000/(880*2*10)+(880)/(2*10))SHL 8 ;LA tone & Duration DC 1000000/(988*2*10)+(988)/(2*10))SHL 8 ;SoL tone & Duration DC 1000000/(1047*2*10)+(1047)/(2*10))SHL 8 ;LA tone & Duration DC 0 ;Table end code END
SHL • 00111111 +20 SHL 8 00111111 (TBLP 顯示0至9) +00100000 =01011111 (after SHL Bit 14-8放置 TBLH 作為DELAY)
音調高低之參數 • F為產生之音調頻率 • 半週期時間為(2*F) -1 • Delay 時間 DEL1*10us • 產生F Hz 所需之DEL1為 (2F) -1/(10*10-6)=106/(2*F*10)
產生0.5秒之頻率F Hz所需脈波數為 F/2 • 8 bit problem • Two Loop 內圈10 外圈 F/(2*10)