资源描述:
《单片机驱动蜂鸣器音乐生日快乐的播放程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、;音乐生日快乐的播放;P1.6是喇叭输出端口,用杜邦线连接到J42插针B1针脚,喇叭即播放音乐numtimequ20hgeweiequ21hshiweiequ22hscanledequ23horg000hjmpstartorg00bhjmptim0org100hstart:;JBP3.7,$;检测播放按键是否按下movtmod,#00000001bmovie,#10000010bmovnumtim,#01hstart0:mov30h,#00hnext:mova,30hmovdptr,#tablemovca,@a+dptrmovr2,ajzend0anla,#0fhmovr5,amova,r2
2、swapaanla,#0fhjnzsingclrtr0jmpd1sing:decamov22h,arlamovdptr,#table1movca,@a+dptrmovth0,amov21h,amova,22hrlaincamovca,@a+dptrmovtl0,amov20h,asetbtr0d1:lcalldelayinc30hjmpnextend0:clrtr0jmpstart0tim0:pushaccpushpswmovtl0,20hmovth0,21hcplp1.6;由该口输出音频数据poppswpopaccretidelay:movr7,#02hd2:movr4,#187d3:mo
3、vr3,#248djnzr3,$djnzr4,d3djnzr7,d2djnzr5,delayrettable1:;音乐码表dw64260,64400,64524,64580dw64684,64777,64820,64898dw64968,65030,65058,65110dw65157,65178,65217table:db82h,01h,81h,94h,84hdb0b4h,0a4h,04hdb82h,01h,81h,94h,84hdb0c4h,0b4h,04hdb82h,01h,81h,0f4h,0d4hdb0b4h,0a4h,94hdb0e2h,01h,0e1h,0d4h,0b4hdb0
4、c4h,0b4h,04hdb82h,01h,81h,94h,84hdb0b4h,0a4h,04hdb82h,01h,81h,94h,84hdb0c4h,0b4h,04hdb82h,01h,81h,0f4h,0d4hdb0b4h,0a4h,94hdb0e2h,01h,0e1h,0d4h,0b4hdb0c4h,0b4h,04hdb00TABLE2:DB0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90Hend另外的一个C文件。#include#defineucharunsignedchar#defineuintunsignedintsbitB
5、EEP=P2^6;voidMusic(ucharnumber);voiddelay10us(uchartime);voiddelay50us(uchartime);ucharcodeSOUNDLONG[]=//控制音调{18,6,24,24,24,48,18,6,24,24,24,48,18,6,24,24,24,24,24,18,6,24,24,24,48,0};ucharcodeSOUNDTONE[]=//控制音色{212,212,190,212,159,169,212,212,190,212,142,159,212,212,106,126,159,169,190,119,119,126
6、,159,142,159,0//生日快乐end};voidPlay_Music(){uintk,n;uintSoundLong,SoundTone;uinti,j,m;do{if(i>=25)i=0;SoundLong=SOUNDLONG[i];SoundTone=SOUNDTONE[i];i++;for(n=0;n7、
8、(
9、SOUNDTONE[j]!=0));}//延时程序voiddelay10us(uchartime){uchara,b,c;for(a=0;a