;本程序的單片機(jī)晶振采用11.0592MHZ 本文引用地址:http://m.butianyuan.cn/article/201611/321867.htm;l程序中共有兩首歌,后面一首為世上只有媽媽好.兩首歌曲表的格式不同,若有任何疑問(wèn)請(qǐng)留言. ;刀郎的<<2002年的第一場(chǎng)雪>> SPK BIT P0.0
ORG 0000H LJMP MAIN ORG 000BH LJMP TIMER0 MAIN: MOV TMOD,#01H ;置CT0定時(shí)工作方式1 MOV IE,#82H;CPU開(kāi)中斷,CT0開(kāi)中斷 MOV R5,#0 PLAY: MOV A,R5 MOV DPTR,#TABLE1 MOVC A,@A+DPTR MOVR6,A INC R5 MOV A,R5 MOVC A,@A+DPTR MOVR7,A INC R5 MOV A,R5 MOVC A,@A+DPTR JNZ PLAY1 MOV R5,#0 LJMP NEXT PLAY1: MOV B,#3 MUL AB MOV R2,A MOV B,#7 MOV A,R7 MUL AB ADD A,R6 DEC A MOV R6,A MOV DPTR,#FREQH MOVC A,@A+DPTR MOV R4,A MOV DPTR,#FREQL MOV A,R6 MOVC A,@A+DPTR MOV R3,A LCALL SONG;調(diào)用音符播放程序 INC R5 SJMP PLAY;轉(zhuǎn)入調(diào)用下一個(gè)音符OV R3,A
MOV R5,#00H NEXT: MOV A,R5;R5存放取數(shù)的變地址 MOV DPTR,#TABLE ;DPTR置音高節(jié)拍表首地址 MOVC A,@A+DPTR ;從音高節(jié)拍表取中取音高高位參數(shù) MOV R4,A;R4存放音高高位參數(shù) INC R5 MOV A,R5 MOVC A,@A+DPTR ;從音高節(jié)拍表取中取音高低位參數(shù) MOV R3,A;R3存放音高低位參數(shù) INC R5 MOV A,R5 MOVC A,@A+DPTR ;從音高節(jié)拍表取中取節(jié)拍參數(shù) JNZ NEXT1 MOV R5,#00H LJMP PLAY;唱完后循環(huán)(節(jié)拍參數(shù)為#00H表示歌曲結(jié)束) NEXT1: MOV R2,A;R2存放節(jié)拍參數(shù) LCALL SONG;調(diào)用音符播放程序 INC R5 SJMP NEXT;轉(zhuǎn)入調(diào)用下一個(gè)音符 SONG: MOV TH0,R4 MOV TL0,R3 SETB TR0;啟動(dòng)CT0(開(kāi)始唱某一音符) DELAY: MOV R1,#85H;節(jié)拍延時(shí)(即某一音符唱多長(zhǎng)時(shí)間) DEL1: MOV R0,#0FFH DEL0: NOP NOP NOP DJNZ R0,DEL0 DJNZ R1,DEL1 DJNZ R2,DELAY CLR TR0;禁止CT0(某一音符唱完后停止) RET TIMER0:;定時(shí)中斷程序(用于決定某一音符唱多高) CPL SPK MOV TH0,R4 MOV TL0,R3 RETI TABLE: ;音高節(jié)拍表,休止符用"FFH,FFH",結(jié)束用節(jié)拍為00H表示 DB 0FFH,0FFH,01H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H DB 0FDH, 5BH,04H,0FDH, 08H,02H,0FCH,0ABH,02H,0FCH, 0BH,02H,0FCH, 0BH,02H,0FFH,0FFH,01H,0FCH, 0BH,02H DB 0FCH,0ABH,02H,0FCH,0ABH,02H,0FCH,0ABH,02H,0FCH,0ABH,02H,0FCH,0ABH,04H,0FCH,0ABH,02H,0FCH,0ABH,02H DB 0FBH, 8FH,02H,0FCH, 0BH,02H,0FCH, 0BH,04H,0FFH,0FFH,01H DB 0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,04H,0FDH, 08H,02H,0FDH, 08H,02H DB 0FDH, 5BH,04H,0FDH, 08H,02H,0FCH,0ABH,04H,0FDH, 08H,06H DB 0FBH,08FH,02H,0FBH,08FH,02H,0FBH,08FH,02H,0FBH,08FH,02H,0FBH,08FH,02H,0FBH, 03H,02H,0FAH, 14H,02H DB 0FCH,0ABH,04H,0FCH,0ABH,02H,0FCH,0ABH,02H,0FCH,0ABH,02H,0FCH, 0BH,02H,0FCH, 0BH,04H DB 0FFH,0FFH,01H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H,0FDH, 08H,02H DB 0FDH, 5BH,04H,0FDH, 08H,02H,0FCH,0ABH,04H,0FDH, 08H,06H DB 0FBH,08FH,02H,0FBH,08FH,02H,0FBH,08FH,02H,0FBH,08FH,02H,0FBH,08FH,02H,0FBH, 03H,02H,0FAH, 14H,02H DB 0FCH,0ABH,04H,0FCH,0ABH,02H,0FCH,0ABH,02H,0FCH,0ABH,02H,0FCH, 0BH,02H,0FCH, 0BH,04H, 00H, 00H,00H TABLE1: DB6,2,3,5,2,1,3,2,2, 5,2,2, 1,3,2, 6,2,1, 5,2,1 DB6,2,4,3,2,2,5,2,1, 6,2,1, 5,2,2, 3,2,2, 1,2,1 DB6,1,1,5,2,1,3,2,1, 2,2,4, 2,2,3, 3,2,1, 5,2,2 DB5,2,1,6,2,1,3,2,2, 2,2,2, 1,2,4, 5,2,3, 3,2,1 DB2,2,1,1,2,1,6,1,1, 1,2,1, 5,1,6, 0,0,0 ; 音階頻率表 FREQH: DB0F2H,0F3H,0F5H,0F5H,0F6H,0F7H,0F8H DB0F9H,0F9H,0FAH,0FAH,0FBH,0FBH,0FCH, 0FCH ;1,2,3,4,5,6,7,8,i DB0FCH,0FDH,0FDH,0FDH,0FDH,0FEH DB0FEH,0FEH,0FEH,0FEH,0FEH,0FEH,0FFH FREQL: DB42H, 0C1H, 17H, 0B6H,0D0H,0D1H,0B6H DB21H, 0E1H, 8CH, 0D8H,68H, 0E9H, 5BH,8FH ;1,2,3,4,5,6,7,8,i DB0EEH,44H,6BH,0B4H,0F4H,2DH DB47H, 77H,0A2H,0B6H,0DAH,0FAH,16H END
END |
評(píng)論