完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
/******************************************************************************/
/**程序名称:单片机播放欢乐颂与最炫民族风片段 /**其 他:用于时钟周期为12MHz的STC89C52单片机 /******************************************************************************/ #include ***it BUZZER = P3^2; #define uchar unsigned char #define uint unsigned int #define REST 36 //休止符 #define A 0 //低音1 #define AB 1 //低音1.5 #define B 2 //低音2 #define BC 3 //低音2.5 #define C 4 //低音3 #define D 5 //低音4 #define DE 6 //低音4.5 #define E 7 //低音5 #define EF 8 //低音5.5 #define F 9 //低音6 #define FG 10 //低音6.5 #define G 11 //低音7 #define L 12 //中音1 #define LM 13 //中音1.5 #define M 14 //中音2 #define MN 15 //中音2.5 #define N 16 //中音3 #define O 17 //中音4 #define OP 18 //中音4.5 #define P 19 //中音5 #define PQ 20 //中音5.5 #define Q 21 //中音6 #define QR 22 //中音6.5 #define R 23 //中音7 #define S 24 //高音1 #define SU 25 //高音1.5 #define U 26 //高音2 #define UV 27 //高音2.5 #define V 28 //高音3 #define W 29 //高音4 #define WX 30 //高音4.5 #define X 31 //高音5 #define XY 32 //高音5.5 #define Y 33 //高音6 #define YZ 34 //高音6.5 #define Z 35 //高音7 //音阶 uchar code m_note[][2] = { {248,136},{248,243},{249,88},{249,184},{250,18},{250,103},{250,184},{251,3},{251,75}, {251,143},{251,206},{252,11},{252,67},{252,121},{252,172},{252,219},{253,9},{253,51}, {253,91},{253,129},{253,165},{253,199},{253,231},{254,5},{254,33},{254,60},{254,85}, {254,109},{254,132},{254,153},{254,173},{254,192},{254,210},{254,227},{254,243},{255,2}, {0,0}, }; //音符(1对应三十二分音符,32对应全音符) uchar code display[][2] = { //欢乐颂 {N,8},{N,8},{O,8},{P,8},{P,8},{O,8},{N,8},{M,8},{L,8},{L,8},{M,8},{N,8},{N,12},{M,4},{M,8},{0xff,8}, {N,8},{N,8},{O,8},{P,8},{P,8},{O,8},{N,8},{M,8},{L,8},{L,8},{M,8},{N,8},{M,12},{L,4},{L,8},{0xff,8}, {M,8},{M,8},{N,8},{L,8},{M,8},{N,4},{O,4},{N,8},{L,8},{M,8},{N,4},{O,4},{N,8},{M,8},{L,8},{M,8},{E,8}, {N,8},{N,8},{O,8},{P,8},{P,8},{O,8},{N,8},{M,8},{L,8},{L,8},{M,8},{N,8},{M,12},{L,4},{L,8},{0xff,8}, {M,8},{M,8},{N,8},{L,8},{M,8},{N,4},{O,4},{N,8},{L,8},{M,8},{N,4},{O,4},{N,8},{M,8},{L,8},{M,8},{E,8}, {N,8},{N,8},{O,8},{P,8},{P,8},{O,8},{N,8},{M,8},{L,8},{L,8},{M,8},{N,8},{M,12},{L,4},{L,8},{0xff,8}, //乐谱(最炫民族风) {N,8},{F,4},{F,4},{L,8},{N,8},{M,4},{M,2},{N,2},{M,4},{L,4}, {M,4},{L,4},{F,8},{N,8},{F,4},{F,4},{L,8},{N,8}, {P,4},{M,2},{N,2},{M,4},{L,4},{M,4},{L,4},{G,4},{E,4}, {N,8},{F,4},{F,4},{L,8},{N,8},{M,4},{M,2},{N,2},{M,4},{L,4}, {M,4},{L,4},{F,4},{E,4},{N,8},{F,4},{F,4},{L,8},{N,8}, {P,4},{N,4},{0xff,24},//前奏 {F,8},{F,4},{E,4},{F,8},{F,4},{L,4},{L,8},{M,4},{L,4},{F,8}, {0xff,8},{L,8},{L,4},{E,4},{L,4},{M,4},{N,4},{P,4},{P,4},{N,4}, {M,8},{N,8},{0xff,8},{Q,4},{Q,4},{Q,4},{P,4},{N,4},{N,8},{L,4}, {F,4},{F,4},{F,4},{N,4},{M,8},{0xff,8},{N,4},{N,4},{P,4},{N,4}, {M,4},{N,4},{M,4},{L,4},{F,8},{E,8},{F,8},{0xff,8}, {F,8},{F,4},{E,4},{F,8},{F,4},{L,4},{L,8},{M,4},{L,4},{F,8}, {0xff,8},{L,8},{L,4},{E,4},{L,4},{M,4},{N,4},{P,4},{P,4},{N,4}, {M,8},{N,8},{0xff,8},{Q,4},{Q,4},{Q,4},{P,4},{N,4},{N,8},{L,4}, {F,4},{F,4},{F,4},{N,4},{M,8},{0xff,8},{N,4},{N,4},{P,4},{N,4}, {M,4},{N,4},{M,4},{L,4},{F,8},{E,8},{F,8},{0xff,8}, {N,4},{N,4},{P,4},{N,4},{N,4},{P,4},{P,4},{Q,4},{S,4},{Q,4}, {P,8},{Q,8},{0xff,8}, //此处有变调 {F,8},{F,4},{E,4},{F,8},{L,8},{M,4},{N,2},{M,2},{L,4},{M,4}, {N,8},{0xff,8},{F,4},{Q,4},{Q,4},{P,4},{M,4},{N,2},{M,2}, {L,4},{M,4},{N,8},{0xff,8},{0xff,16},{L,4},{F,4},{F,4},{L,4}, {M,8},{E,4},{E,4},{N,4},{P,4},{N,4},{M,4},{L,8},{0xff,8}, {F,4},{L,4},{M,4},{N,4},{M,4},{L,4},{E,4},{C,4},{F,8},{0xff,8},{0xff,16}, {F,8},{F,4},{E,4},{F,8},{L,8},{M,4},{N,2},{M,2},{L,4},{M,4}, {N,8},{0xff,8},{F,4},{Q,4},{Q,4},{P,4},{M,4},{N,2},{M,2}, {L,4},{M,4},{N,8},{0xff,8},{0xff,16},{L,4},{F,4},{F,4},{L,4}, {M,8},{E,4},{E,4},{N,4},{P,4},{N,4},{M,4},{L,12},{L,4}, {F,4},{L,4},{M,4},{N,4},{P,4},{N,4},{N,4},{P,4},{Q,8},{0xff,8},{0xff,8}, {Q,6}, {Q,2},{Q,4},{Q,4},{Q,6},{P,2},{N,4},{M,4},{M,6},{M,2},{N,6},{P,2},{N,6},{M,2}, {L,6},{F,2},{F,8},{F,4},{E,4},{F,8},{F,4},{L,4}, {M,4},{N,2},{M,2}, {L,4},{M,4},{N,8},{0xff,8}, {Q,4},{P,4},{N,4},{M,4},{P,4},{N,4},{M,4},{L,4},{L,8},{0xff,8},{F,2}, {A,2},{B,2},{C,2},{B,2}, {A,2}, {F,2},{A,2}, {N,4},{N,4},{P,4},{N,4},{N,4},{P,4},{P,4},{Q,4},{S,4},{Q,4}, {P,8},{Q,8},{0xff,8}, //此处有变调 {F,8},{F,4},{E,4},{F,8},{L,8},{M,4},{N,2},{M,2},{L,4},{M,4}, {N,8},{0xff,8},{F,4},{Q,4},{Q,4},{P,4},{M,4},{N,2},{M,2}, {L,4},{M,4},{N,8},{0xff,8},{0xff,16},{L,4},{F,4},{F,4},{L,4}, {M,8},{E,4},{E,4},{N,4},{P,4},{N,4},{M,4},{L,8},{0xff,8}, {F,4},{L,4},{M,4},{N,4},{M,4},{L,4},{E,4},{C,4},{F,8},{0xff,8},{0xff,16}, {F,8},{F,4},{E,4},{F,8},{L,8},{M,4},{N,2},{M,2},{L,4},{M,4}, {N,8},{0xff,8},{F,4},{Q,4},{Q,4},{P,4},{M,4},{N,2},{M,2}, {L,4},{M,4},{N,8},{0xff,8},{0xff,16},{L,4},{F,4},{F,4},{L,4}, {M,8},{E,4},{E,4},{N,4},{P,4},{N,4},{M,4},{L,12},{L,4}, {F,4},{L,4},{M,4},{N,4},{P,4},{N,4},{N,4},{P,4},{Q,8},{0xff,8},{0xff,8}, {0,0xff}, }; uchar time_h,time_l; void Delay(uchar x); void main() { uchar j; uint i; TMOD = 0x01; ET0 = 1; EA = 1; TR0 = 1; i = 0; j = 0; while(1) { while(display[i][1] != 0xff) { if(display[i][0] == 0xff) { TR0 = 0; Delay(display[i][1]); BUZZER = 1; } else { time_h = m_note[display[i][0]][0]; time_l = m_note[display[i][0]][1]; TH0 = time_h; TL0 = time_l; ET0 = 1; TR0 = 1; Delay(display[i][1]); TR0 = 0; ET0 = 0; BUZZER = 1; } i++; } i = 0; } } void Timer0() interrupt 1 { TR0 = 0; TH0 = time_h; TL0 = time_l; BUZZER = ~BUZZER; TR0 = 1; } void Delay(uchar x) { uint i,j; for(i = 0;i < x;i++) for(j = 0;j < 12000;j++); } |
|
相关推荐
5 个讨论
|
|
不错,程序复制后改了个输出口参数,就在本人的开发板上顺利运行了。只是,板上蜂鸣器音质太差了,声音也小,想搭个面包板用喇叭放下。
|
|
|
|
|
|
使用Keil建立完整的工程,并使用外部中断0触发数码管显示903
418 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-使用AHT20进行环境监测之AHT20传感器介绍
1083 浏览 0 评论
846 浏览 0 评论
886 浏览 1 评论
基于瑞萨FPB-RA4E2智能床头灯项目——1编译环境搭建与点亮驱动ws2812全彩LED
882 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11832 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-1 01:13 , Processed in 0.640920 second(s), Total 53, Slave 42 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号