《蜂鸣器生日快乐歌.doc》由会员分享,可在线阅读,更多相关《蜂鸣器生日快乐歌.doc(2页珍藏版)》请在三一文库上搜索。
1、/*/* SC5204单片机实验板实验例程 */*蜂鸣器生日快乐歌 */* 2012年5月 */* 作者:雷国强 */* 邮箱: */*【声明】此程序仅用于学习与参考,引用请注明版权和作者信息! */* */*/ / 生日快乐歌 /*/#include sbit Buzzer=P37; unsigned char timer0h,timer0l,time; /生日歌code unsigned char sszymmh=5,1,1, 5,1,1, 6,1,2, 5,1,2, 1,2,2, 7,1,4, 5,1,1, 5,1,1, 6,1,2, 5,1,2, 2,2,2, 1,2,4, 5,1,1
2、, 5,1,1, 5,2,2, 3,2,2, 1,2,2, 7,1,2, 6,1,2, 4,2,1, 4,2,1, 3,2,2, 1,2,2, 2,2,2, 1,2,4; / 音阶频率表 高八位code unsigned char FREQH= 0xF2,0xF3,0xF5,0xF5,0xF6,0xF7,0xF8, 0xF9,0xF9,0xFA,0xFA,0xFB,0xFB,0xFC,0xFC, /1,2,3,4,5,6,7,8,i 0xFC,0xFD,0xFD,0xFD,0xFD,0xFE, 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFF, ; / 音阶频率表 低八位c
3、ode unsigned char FREQL= 0x42,0xC1,0x17,0xB6,0xD0,0xD1,0xB6, 0x21,0xE1,0x8C,0xD8,0x68,0xE9,0x5B,0x8F, /1,2,3,4,5,6,7,8,i 0xEE,0x44, 0x6B,0xB4,0xF4,0x2D, 0x47,0x77,0xA2,0xB6,0xDA,0xFA,0x16, ;void delay(unsigned char t) unsigned char t1; unsigned long t2; for(t1=0;t1t;t1+) for(t2=0;t28000;t2+) ; TR0=0
4、; void t0int() interrupt 1 TR0=0; Buzzer=!Buzzer; TH0=timer0h; TL0=timer0l; TR0=1; void song() TH0=timer0h; TL0=timer0l; TR0=1; delay(time); void main(void) unsigned char k,i; TMOD=1; /置CT0定时工作方式1 EA=1; ET0=1; /CPU开中断,CT0开中断 while(1) i=0; while(i75) /音乐数组长度 ,唱完从头再来 k=sszymmhi+7*sszymmhi+1-1; timer0h=FREQHk; timer0l=FREQLk; time=sszymmhi+2; i=i+3; song();