51单片机c语言音乐代码天空之城,蜂鸣器版天空之城(示例代码)

1 #include

2 #include

3 #define qdo 262

4 #define qre 294

5 #define qmi 330 //q前缀为低音,1后缀为高音,s前缀为半音阶

6 #define qfa 349

7 #define qso 392

8 #define qla 440

9 #define qsi 494

10 #define do 523

11 #define re 578

12 #define mi 659

13 #define fa 698

14 #define so 784

15 #define la 880

16 #define si 988

17 #define do1 1046

18 #define re1 1175

19 #define mi1 1318

20 #define fa1 1480

21 #define so1 1568

22 #define la1 1760

23 #define si1 1976

24 #define sqdo 277

25 #define sqre 311

26 #define sqfa 370

27 #define sqso 415

28 #define sqla 466

29 #define sdo 554

30 #define sre 622

31 #define sfa 740

32 #define sso 831

33 #define sla 932

34 #define sdo1 1046

35 #define sre1 1245

36 #define sfa1 1480

37 #define sso1 1661

38 #define sla1 1865

39

40 intmain()41 {42 int pai=400,ban=200;43 int ting=128;44

45 Sleep(1000);46

47 Beep(la,ban);48 Beep(si,ban);49 Sleep(ting);50

51 Beep(do1,pai+ban);52 Beep(si,ban);53 Sleep(ting);54 Beep(do1,pai);55 Sleep(ting);56 Beep(mi1,pai);57 Sleep(ting);58

59 Beep(si,3*pai);60 Sleep(ting);61 Beep(mi,ban);62 Beep(mi,ban);63

64 Beep(la,ban+pai);65 Beep(so,ban);66 Sleep(ting);67 Beep(la,pai);68 Sleep(ting);69 Beep(do1,pai);70 Sleep(ting);71

72 Beep(so,2*pai);73 Sleep(ting);74 Sleep(pai);75 Beep(mi,ban);76 Sleep(ting/2);77 Beep(mi,ban);78 Sleep(ting/2);79

80 Beep(fa,pai+ban);81 Beep(mi,ban);82 Sleep(ting);83 Beep(fa,ban);84 Beep(do1,ban+pai);85 Sleep(ting);86

87 Beep(mi,2*pai);88 Sleep(ting);89 Sleep(ban);90 Beep(do1,ban);91 Sleep(ting/2);92 Beep(do1,ban);93 Sleep(ting/2);94 Beep(do1,ban);95 Sleep(ting/2);96

97 Beep(si,ban+pai);98 Beep(sfa,ban);99 Sleep(ting);100 Beep(sfa,pai);101 Beep(si,pai);102 Sleep(ting);103

104 Beep(si,2*pai);105 Sleep(ting);106 Sleep(pai);107 Beep(la,ban);108 Beep(si,ban);109 Sleep(ting);110

111 Beep(do1,pai+ban);112 Beep(si,ban);113 Sleep(ting);114 Beep(do1,pai);115 Sleep(ting);116 Beep(mi1,pai);117 Sleep(ting);118

119 Beep(si,2*pai);120 Sleep(ting);121 Sleep(pai);122 Beep(mi,ban);123 Sleep(20);124 Beep(mi,ban);125 Sleep(ting);126

127 Beep(la,pai+ban);128 Beep(so,ban);129 Sleep(ting);130 Beep(la,pai);131 Sleep(ting);132 Beep(do1,pai);133 Sleep(ting);134

135 Beep(so,3*pai);136 Sleep(ting+ban);137 Beep(mi,ban);138 Sleep(ting/2);139

140 Beep(fa,pai);141 Sleep(ting);142 Beep(do1,ban);143 Beep(si,ban);144 Sleep(20);145 Beep(si,pai);146 Sleep(ting);147 Beep(do1,pai);148 Sleep(ting);149

150 Beep(re1,ban);151 Sleep(20);152 Beep(re1,ban);153 Sleep(20);154 Beep(mi1,ban);155 Sleep(ting/2);156 Beep(do1,pai);157 Sleep(ting+pai);158

159 Beep(do1,pai);160 Beep(si,ban);161 Sleep(ting);162 Beep(la,ban);163 Sleep(20);164 Beep(la,ban);165 Sleep(ting);166 Beep(si,pai);167 Sleep(ting);168 Beep(sso,pai);169 Sleep(ting);170

171 Beep(sso,2*pai);172 Sleep(ting+pai);173 Beep(do1,ban);174 Beep(re1,ban);175 Sleep(ting);176

177 Beep(mi1,pai+ban);178 Beep(re1,ban);179 Sleep(ting);180 Beep(mi1,pai);181 Sleep(ting);182 Beep(fa1,pai);183 Sleep(ting);184

185 Beep(re1,2*pai);186 Sleep(pai+ting);187 Beep(so,ban);188 Sleep(20);189 Beep(so,ban);190 Sleep(ting);191

192 Beep(do1,ban);193 Beep(si,ban);194 Sleep(ting);195 Beep(do1,pai);196 Sleep(ting);197 Beep(mi1,pai);198 Sleep(ting);199

200 Beep(mi1,2*pai);201 Sleep(ting+2*pai);202

203 Beep(la,ban);204 Beep(si,ban);205 Sleep(ting);206 Beep(do1,pai);207 Sleep(ting);208 Beep(si,pai);209 Sleep(ting);210 Beep(re1,ban);211 Sleep(20);212 Beep(re1,ban);213 Sleep(ting);214

215 Beep(do1,pai+ban);216 Beep(so,ban);217 Sleep(20);218 Beep(so,pai);219 Sleep(pai+ting);220

221 Beep(fa1,pai);222 Sleep(ting);223 Beep(mi1,pai);224 Sleep(ting);225 Beep(re1,pai);226 Sleep(ting);227 Beep(do1,pai);228 Sleep(ting);229

230 Beep(mi1,4*pai);231

232 Beep(mi1,pai*2);233 Sleep(pai+ting);234 Beep(mi1,pai);235 Sleep(ting);236

237 Beep(la1,2*pai);238 Sleep(ting);239 Beep(so1,pai);240 Sleep(ting);241 Beep(so1,pai);242 Sleep(ting);243

244 Beep(mi1,ban);245 Sleep(ting/2);246 Beep(re1,ban);247 Sleep(ting);248 Beep(do1,pai);249 Sleep(ting+ban);250 Beep(do1,ban);251 Sleep(ting);252

253 Beep(re1,pai);254 Sleep(ting);255 Beep(do1,ban);256 Beep(re1,ban);257 Sleep(20);258 Beep(re1,ban);259 Sleep(ting);260 Beep(so1,pai);261 Sleep(ting);262

263 Beep(mi1,2*pai);264 Sleep(ting+pai);265 Beep(mi,pai);266 Sleep(ting);267

268 Beep(la1,2*pai);269 Sleep(ting);270 Beep(so1,2*pai);271 Sleep(ting);272

273 Beep(mi1,ban);274 Beep(re1,ban);275 Sleep(ting);276 Beep(do1,2*pai);277 Sleep(ting+ban);278 Beep(do1,ban);279 Sleep(ting);280

281 Beep(re1,pai);282 Sleep(ting);283 Beep(do1,ban);284 Beep(re1,ban);285 Sleep(20);286 Beep(re1,ban);287 Sleep(ting);288 Beep(si,pai);289 Sleep(ting);290

291 Beep(la,2*pai);292 Sleep(ting);293 Beep(la,ban);294 Beep(si,ban);295

296 Beep(do1,pai+ban);297 Beep(si,ban);298 Sleep(ting);299 Beep(do1,pai);300 Sleep(ting);301 Beep(mi1,pai);302 Sleep(ting);303

304 Beep(si,3*pai);305 Sleep(ting);306 Beep(mi,ban);307 Beep(mi,ban);308

309 Beep(la,ban+pai);310 Beep(so,ban);311 Sleep(ting);312 Beep(la,pai);313 Sleep(ting);314 Beep(do1,pai);315 Sleep(ting);316

317 Beep(so,2*pai);318 Sleep(ting);319 Sleep(pai);320 Beep(mi,ban);321 Sleep(ting/2);322 Beep(mi,ban);323 Sleep(ting/2);324

325 Beep(fa,pai+ban);326 Beep(mi,ban);327 Sleep(ting);328 Beep(fa,ban);329 Beep(do1,ban+pai);330 Sleep(ting);331

332 Beep(mi,2*pai);333 Sleep(ting);334 Sleep(ban);335 Beep(do1,ban);336 Sleep(ting/2);337 Beep(do1,ban);338 Sleep(ting/2);339 Beep(do1,ban);340 Sleep(ting/2);341

342 Beep(si,ban+pai);343 Beep(sfa,ban);344 Sleep(ting);345 Beep(sfa,pai);346 Beep(si,pai);347 Sleep(ting);348

349 Beep(si,2*pai);350 Sleep(ting);351 Sleep(pai);352 Beep(la,ban);353 Beep(si,ban);354 Sleep(ting);355

356 Beep(do1,pai+ban);357 Beep(si,ban);358 Sleep(ting);359 Beep(do1,pai);360 Sleep(ting);361 Beep(mi1,pai);362 Sleep(ting);363

364 Beep(si,2*pai);365 Sleep(ting);366 Sleep(pai);367 Beep(mi,ban);368 Sleep(20);369 Beep(mi,ban);370 Sleep(ting);371

372 Beep(la,pai+ban);373 Beep(so,ban);374 Sleep(ting);375 Beep(la,pai);376 Sleep(ting);377 Beep(do1,pai);378 Sleep(ting);379

380 Beep(so,3*pai);381 Sleep(ting+ban);382 Beep(mi,ban);383 Sleep(ting/2);384

385 Beep(fa,pai);386 Sleep(ting);387 Beep(do1,ban);388 Beep(si,ban);389 Sleep(20);390 Beep(si,pai);391 Sleep(ting);392 Beep(do1,pai);393 Sleep(ting);394

395 Beep(re1,ban);396 Sleep(20);397 Beep(re1,ban);398 Sleep(20);399 Beep(mi1,ban);400 Sleep(ting/2);401 Beep(do1,pai);402 Sleep(ting+pai);403

404 Beep(la,4*pai);405

406 Sleep(1000);407 main();408

409 }

你可能感兴趣的:(51单片机c语言音乐代码天空之城,蜂鸣器版天空之城(示例代码))