求一个用C语言编写的51单片机音乐程序代码。

关于圣诞节的,比如《平安夜》、《圣诞老人来了》。。。 谢谢!

#include <reg52.h>
sbit speaker=P2^2;
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, 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,
} ;
// 音阶频率表 低八位
code 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;t1<t;t1++)
{
for(t2=0;t2<8000;t2++)
{
;
}
}
TR0=0;
}
void t0int() interrupt 1
{
TR0=0;
speaker=!speaker;
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;//IE=0x82 //CPU开中断,CT0开中断
while(1)
{
i=0;
while(i<75){ //音乐数组长度 ,唱完从头再来
k=sszymmh[i]+7*sszymmh[i+1]-1;
timer0h=FREQH[k];
timer0l=FREQL[k];
time=sszymmh[i+2];
i=i+3;
song();
}
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-12-05
第2个回答  2011-12-05
我给你传一份!追问

关于圣诞节的哦,有的话传到505232035@qq.com,加分哟。。

求一个用C语言编写的51单片机音乐程序代码。
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, 5,1,1, 5,2,2, 3,2,2, 1,2,2, 7,1,2, 6,1,2,4,2,1, 4...

求单片机 音乐播放的c代码
0x20,0x2B,0x40,0x20,0x20,0x1C,0x10,0x18,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,0x20,0x2B,0x40,0x20,0x30,0x1C,0x10,0x18,0x20,0x15,0x20,0x1C,0x20,0x20,0x20,0x26,0x40,0x20,0x20,0x2B,0x20,0x26,0x20,0x20,0x20,0x30,0x80,0x20,0x30,0x1C,0x10,...

求一个51单片机C语言程序编程
unsigned chari,NO;void main(void) \/* 主函数*\/ { SCON=0x40; \/*方式1只发送,不接收*\/ TMOD=0x20;TH1=0xfd; \/*给定时器T1赋初值,波特率为9600*\/ TL1=0xfd;TR1=1;k=1;NO=0;while(1){ if(k==0){while(k==0);NO=(NO+1)%4;} switch (NO){case 0 :P0=0xff;b...

谁能给我几首51单片机流行歌曲 的源代码!
--[endif]-->程序代码:(以下代码奏出八月桂花香这首曲子) ORG 0000H LJMP START ORG 000BH INC 20H ;中断服务,中断计数器加1 MOV TH0, #0DBH MOV TL0, #0FFH ;11.0592M晶振,形成10毫秒中断 RETISTART: MOV SP, #50H ...

求51单片机蜂鸣器程序
开关C语言程序:sbit P2^0=KEY;sbit P2^1=BEEP;unsigned char KEYNUM=0;void main(){while(1){if(KEY==0)\/\/开关按下;{KEYNUM++; }if(KEYNUM==1)\/\/第一次按下;{BEEP=1; \/\/蜂鸣器响 }if(KEYNUM==2)\/第二次按下;{BEEP=0; \/\/蜂鸣器不响KEYNUM=0; }}} 51单片机,编写延时...

求51单片机蜂鸣程序代码
MUSIC1:NOP CLR A MOVC A,@A+DPTR ;查表取代码 JZ END0 ;是00H,则结束 CJNE A,#0FFH,MUSIC5 LJMP MUSIC3 MUSIC5:NOP MOV R6,A INC DPTR MOV A,B MOVC A,@A+DPTR ;取节拍代码送R7 MOV R7,A SETB TR0 ;启动计数 MUSIC2:NOP CPL SPK MOV A,R6 MOV R3,A LCALL DEL MOV A,...

单片机音乐程序代码
控制音频1234567MOV A,R1MOVC A,@A+DPTRMOV T0H,AINC DPTRMOV A,R1MOVC A,@A+DPTRMOV T0L,ALJMP LOOPLOOP1:JB P0.1,LOOP2MOV A,R1ADD A,#2MOVC A,@A+DPTRMOV T0H,AINC DPTRMOV A,R1ADD A,#2MOVC A,@A+DPTRMOV T0L,ALJMP LOOPLOOP2:JB P0.2,LOOP3MOV A,R1ADD A,#...

用C语言编写8051单片机程序
second++;P2=~P2;\/\/流水灯全部以1S速度闪烁 if(second==3)stop=1;\/\/判断3秒时间到,关闭中断,停止闪烁,数码管熄灭 } } rate++;P0=0XFF;\/\/消隐 if(rate==3)rate=0;P0=num_disp[buf[rate]];P1=bit_sel[rate];buf[0]=one;buf[1]=ten;\/\/因为百位没有变,所以不用赋值 } ...

51单片机蜂鸣器程序是什么?
51单片机蜂鸣器程序为:include"reg52.h"typedef unsigned char u8;typedef unsigned int u16;sbit beep=P1^5;void delay(u16 i){ while(i--);} void main(){ while(1){ beep=~beep;delay(1000);\/\/控制音调频率 beep=~beep;\/控制声音大小 delay(10);} } ...

用51单片机C语言编写程序实现6位共阴极数码管循环显示0123456789ABCDEF...
include<reg51.h># define uint unsigned int# define uchar unsigned charcode uchar shu[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, \/* 0 1 2 3 4 56 7*\/0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71}; \/\/数码管段选 \/* 8 9a b c def*\/...

相似回答