程序和protrues仿真文件下载:
yinyuehe.rar
(66.54 KB, 下载次数: 95)
内置两首歌曲可切换,led会随音乐变化,可以切换led闪烁样式
源码预览:
- #include <reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit key1=P3^2;//?key1?????
- sbit key2=P3^3;//?key2?????
- sbit fm=P3^7;//??????IO?
- sbit key3=P3^5;//??/???
- //***************???????
- uchar code huayang1[]=
- {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf};
- uchar code huayang2[]=
- {0x7f,0xfe,0xbf,0xfd,0xdf,0xfb,0xef,0xf7,0xef,0xfb,0xdf,0xfd,0xbf,0xfe};
- uchar code huayang3[]=
- {0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x0,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
- uchar code huayang4[]={ 0x55,0xaa,0xcc,0x33,0x99,0x66,0x0f,0xf0};
- uchar count1;//????
- uchar count2;//????
- uchar timeh,timel,i,count3=0;
- //---------------------------??---------------------------------------
- //????:???????,???????,
- //??????????
- //1-7????C?,8-E?????,0????
- //???0?????
- uchar code qnzl[]={ //????
- 0x12,0x22,0x34,0x84,0x74,0x54,0x38,0x42,0x32,0x22,0x42,0x34,0x84,0x72,0x82,0x94,0xA8,0x08,//??
- 0x32,0x31,0x21,0x32,0x52,0x32,0x31,0x21,0x32,0x62,//????? ?????
- 0x32,0x31,0x21,0x32,0x82,0x71,0x81,0x71,0x51,0x32,0x22,//????? ??????
- 0x32,0x31,0x21,0x32,0x52,0x32,0x31,0x21,0x32,0x62,//????? ?????
- 0x32,0x31,0x21,0x32,0x83,0x82,0x71,0x72,0x02,//????????
- 0x63,0xA1,0xA2,0x62,0x92,0x82,0x52,//??????
- 0x31,0x51,0x63,0x51,0x63,0x51,0x63,0x51,0x62,0x82,0x7C,0x02,//???????????
- 0x61,0x71,0x82,0x71,0x62,0xA2,0x71,0x76,//???????
- 0x61,0x71,0x82,0x71,0x62,0x52,0x31,0x36,//???????
- 0x61,0x71,0x82,0x71,0x62,0xA3,0x73,0x62,0x53,//?????? ???
- 0x42,0x63,0x83,0x83,0x91,0x91,//??????
- 0x61,0x71,0x82,0x71,0x62,0x0A2,0x71,0x76,//???????
- 0x61,0x71,0x82,0x71,0x62,0x52,0x31,0x36,//???????
- 0x61,0x71,0x82,0x71,0x62,0xA3,0x73,0x62,0x53,//?????? ???
- 0x42,0x82,0x88,0x02,0x74,0x93,0x89,0xff//????//?????
- };
- uchar code jmszl[]={ //?????
- 0x12,0x12,0x22,0x32,0x31,0x22,0x21,0x22,//???????
- 0x21,0x31,0x51,0x52,0x31,0x52,0x61,0x15,0x14,//????????
- 0x51,0x52,0x31,0x52,0x62,0x13,0x11,0x13,0x32,0x28,0x08,0x28,//??????????
- 0x31,0x32,0x31,0x32,0x11,0x21,0x51,0x52,0x51,0x52,//??????????
- 0x51,0x51,0x31,0x32,0x31,0x32,0x81,0x72,0x63,//?????????
- 0x62,0x71,0x81,0x72,0x61,0x61,0x52,0x31,0x21,0x32,0x51,0x54,//???????????
- 0x22,0x12,0x11,0x12,0x11,0x12,0x12,0x14,0x26,0x32,0x26,//??????
- 0x32,0x61,0x51,0x51,0x31,0x31,0x21,0x31,0x51,0x61,0x51,0x31,0x51,//?????????????
- 0x02,0x32,0x81,0x81,0x81,0x81,0x62,0x52,0x34,//????????
- 0x31,0x81,0x81,0x81,0x61,0x91,0x82,//???????
- 0x51,0x51,0x51,0x51,0x31,0x61,0x53,//??????
- 0x21,0x11,0x21,0x11,0x22,0x11,0x21,0x26,//???????
- 0x32,0x61,0x51,0x51,0x31,0x31,0x21,0x31,0x51,0x61,0x51,0x31,0x51,0x52,//?????????????
- 0x31,0x31,0x81,0x81,0x81,0x61,0x91,0x81,0x61,0x31,0x56,//???????????
- 0x32,0x32,0x81,0x81,0x81,0x81,0x91,0x81,0x61,0x81,0x61,0x51,0x31,0x51,0x34,//???????????????
- 0x21,0x31,0x51,0x31,0x21,0x11,0x61,0x21,0x16,//?????????
- 0xff};
- uchar code hdqb[]={//????
- 0x68,0x68,0x31,0x21,0x31,0x21,0x31,0x21,0x31,0x21,0x31,0x21,0x31,0x21,0x31,0x21,0x31,0x21,0x64,0x82,0x92,0x82,0x62,0x54,0x64,0x02,0x12,0x22,0x32,0x52,0x82,0x32,0x34,0x62,0x68,0x68,0x08,0x64,0x82,0x92,0x82,0x62,0x54,0x58,0x58,0x58,0x58,//??
- 0x32,0x52,0x52,0x61,0x51,0x32,0x21,0x11,0x61,0x13,//??????????
- 0x32,0x12,0x61,0x51,0x12,0x22,0x31,0x23,//????????
- 0x32,0x52,0x52,0x61,0x51,0x32,0x21,0x11,0x61,0x21,0x12,//??????????
- 0x32,0x12,0x12,0x61,0x51,0x12,0x22,0x12,0x12, //????????
- 0x08,0x04,0x62,0x82,0x82,0x91,0x81,0x62,0x51,0x31,0x52,0x82,//??????????
- 0x62,0x51,0x31,0x52,0x81,0x81,0x62,0x51,0x31,0x51,0x23,//?????????
- 0x08,0x32,0x52,0x52,0x61,0x51,0x32,0x21,0x61,0x13,//??????????
- 0x32,0x12,0x11,0x22,0x11,0x18,0x18,//?????
- 0x32,0x52,0x52,0x61,0x51,0x32,0x21,0x11,0x61,0x13,//??????????
- 0x32,0x11,0x11,0x12,0x61,0x51,0x12,0x22,0x31,0x23,//????????
- 0x32,0x52,0x51,0x62,0x51,0x32,0x21,0x11,0x61,0x21,0x12,//??????????
- 0x32,0x11,0x11,0x12,0x61,0x51,0x12,0x22,0x12,0x12,//?????????
- 0x08,0x04,0x62,0x82,0x82,0x91,0x81,0x62,0x51,0x31,0x52,0x82,//??????????
- 0x62,0x51,0x31,0x52,0x82,0x62,0x51,0x31,0x61,0x53,//??????????
- 0x62,0x82,0x82,0x91,0x81,0x62,0x51,0x31,0x51,0xA2,0x91,//??????????
- 0x91,0x81,0x82,0x81,0x82,0x61,0x61,0x53,0x54,//?????
- 0xD1,0xC1,0xA1,0xC1,0xA1,0x91,0x81,0x91,//??
- 0x32,0x52,0x52,0x61,0x51,0x32,0x21,0x11,0x61,0x13,//??????????
- 0x32,0x12,0x12,0x61,0x51,0x11,0x22,0x31,0x24,//????????
- 0x32,0x52,0x52,0x61,0x51,0x32,0x21,0x11,0x51,0x61,0x11,0x31,//????????????
- 0x34,0x11,0x32,0x11,0x18,0x18,//???
- 0x08,0x08,0x38,0x58,0x36,0x22,0x18, 0xFF//?!?!
- };
- uchar code tzdn[]={//????
- 0xC6,0xC6,0xC6,0xA2,0xB2,0xC5,0xE6,0xD6,0xD6,0x02,0x92,0xA2,0xB6,0xB6,0xB6,0xB2,0xA2,0x82,0x86,0x86,//??
- 0x52,0x52,0x52,0x32,0x42,0x52,0x56,0x76,//????????
- 0x62,0x62,0x62,0x62,0x42,0x62,0x56,0x56,//???????
- 0x52,0x52,0x52,0x52,0x72,0x62,0x52,0x44,//????????
- 0x46,0x42,0x42,0x42,0x42,0x33,0x21,0x18,0x18,//???????
- 0x82,0x82,0x82,0x82,0x52,0x62,0x84,0x82,0xA6,//?????????
- 0x92,0x92,0x92,0x93,0x81,0x72,0x66,0x66,//???????
- 0x72, 0x72, 0x72, 0x72, 0x72,0x82,0x96,0x56,//????????
- 0x72,0x72,0x82,0x92,0x82,0x72,0x86,0x86,0xFF//???????
- };
- uchar code lnh[]={ //???
- 0x52,0x51,0x51,0x52,0x52,0x52,0x61,0x51,0x52,0x42,0x32,0x61,0x71,0x72,0x81,0x72,
- 0x52,//??????????????
- 0x02,0x51,0x51,0x62,0x11,0x11,0x12,0x22,0x32,0x52,//????????
- 0x02,0x01,0x51,0x42,0x51,0x21,0x22,0x12,0x24,0x04,//??????
- 0x52,0x51,0x51,0x52,0x52,0x52,0x61,0x51,0x52,0x42,0x32,0x61,0x71,0x72,0x82,0x72,0x52,//??????????????
- 0x02,0x51,0x51,0x62,0x11,0x11,0x12,0x22,0x32,0x52,//????????
- 0x02,0x01,0x51,0x42,0x51,0x21,0x22,0x12,0x14,//??????
- 0x82,0x72,0x62,0x71,0x81,0x82,0x92,0xA2,0x72,//????????
- 0x02,0x51,0x51,0x62,0xA1,0x91,0x92,0x82,0x84,//???????
- 0x82,0x72,0x62,0x71,0x81,0x82,0x92,0xA2,0x72,//????????
- 0x2,0x51,0x51,0x62,0xA1,0x91,0x92,0x82,0x88,0x08,//???????
- 0x08,0x04,0x02,0x81,0x81,0xC2,0xC1,0xC1,0xC2,0xC2,0xC2,0x71,0x71,//?????????
- 0x72,0x71,0x71,0xC2,0xC1,0xC1,0xC2,0xD2,0xC2,0x81,0x81,//?????????
- 0x82,0x81,0x91,0xA2,0x91,0xB2,0xA2,0xA2,0x91,0xB1,0xB2,0xA2,0xA2,0x91,0xB1,0xB2,0xA2,0xC4,//???????????????
- 0x02,0x81,0x81,0xC2,0xC1,0xC1,0xC2,0xC2,0xC2,0x71,0x71,//?????????
- 0x72,0x71,0x71,0xC2,0xC1,0xC1,0xC2,0xD2,0xC2,0x81,0x81,//?????????
- 0x82,0x81,0x91,0xA2,0x91,0xB1,0xB2,0xA2,0xA2,0x91,0x81,0x82,0x72,0x88, 0xFF//???????????
- };
- //----------------------------????????????---------------------------
- //??11.0592M???
- uchar code chuzhi[]={0xff,0xff,//??
- 0xFC,0x8E,0xFC,0xED,0xFD,0x43,0xFD,0x6A,0xFD,0xB3,0xFD,0xF3,0xFE,0x2D,//??C?1-7
- 0xFE,0x47,0xFE,0x76,0xFE,0xA1,0xFE,0xC7,0xFE,0xD9,0xFE,0xF9,0xFF,0x16//???1-7
- };
- uchar yinyue[]={0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x3f,0x9f,0xcf,0xe7,0xf3,0xf9,0xfc};
- //?????????LED??
- void delay1(uint z);//??1MS
- void delay(uint z);//??165MS,??????
- void song();
- void beep();//??????
- main()
- { uchar x;
- count1=0;//??????
- count2=1;//?????
- EA=1;//????
- EX0=1;//?????0
- IT0=1;//????0???????
- EX1=1;//?????1
- IT1=1;//????1???????
- TMOD=0x61;//???0?????1,???1?????2
- TH0=0;//T0???
- TL0=0;
- ET0=1;
- TH1= 0XFF;//T1???
- TL1=0xff;
- TR1= 1;//?T1??
- ET1=1;
- PT1=1;//?T1????
- while(1)
- {
- if(count1!=0)
- {
- switch(count1)//?????
- {
- case 1:
- for(x=0;x<14;x++)
- {
- P1=huayang1[x];
- beep();
- delay1(300);
- if(count1!=1)
- break;
- }
- break;
- case 2:
- for(x=0;x<16;x++)
- {
- P1=huayang2[x];
- beep();
- delay1(300);
- if(count1!=2)
- break;
- }
- break;
- case 3:
- for(x=0;x<8;x++)
- {
- P1=huayang3[x];
- beep();
- delay1(300);
- if(count1!=3)
- break;
- }
- break;
- case 4:
- for(x=0;x<14;x++)
- {
- P1=huayang4[x];
- beep();
- delay1(300);
- if(count1!=4)
- break;
- }
- break;
- }
- }
- else //??????
- {
- song();
- delay1(1000);
- }
- }
- }
- void int0() interrupt 0
- {
- count2=0;
- i=0;
- EA=0;//????
- delay1(1);//??
- if(key1==0)
- {
- EA = 0;
- count2=0;//???????
- count3=0;
- TR0=0;
- count1++;
- if(count1==5)
- count1=1;
- }
- EA=1;//????
- }
- void int1() interrupt 2
- {
- EA=0;//????
- delay1(1);//??
- if(key2==0)
- {
- count1=0;//??????
- TR0=1;
- i=0;//?????
- count2++;
- if(count2==6)
- count2=1;
- }
- EA=1;//????
- }
- void timer0() interrupt 1 //????????
- {
- TH0=timeh;
- TL0=timel;
- fm=~fm;
- }
- void timer1()interrupt 3 //??count3??
- {
- delay1(5);
- if(key3==0)
- {
- count3++;
- if(count3==3)
- count3=1;
- }
- }
- void song()
- {
- uint temp;
- uchar jp;//jp???
- i=0;
- while(1)
- {
- if(count3 == 1)//??
- {
- TR0 = 0;
- }
- if(count3 == 0 || count3 == 2)//??
- {
- EA = 1;
- TR0 = 1;
- if(count2==0)
- break;
- if(count2==1) //??
- temp=qnzl[i];
- if(count2==2)
- temp=jmszl[i];
- if(count2==3)
- temp=hdqb[i];
- if(count2==4)
- temp=tzdn[i];
- if(count2==5)
- temp=lnh[i];
- if(temp==0xff)
- break;
- jp=temp/16; //????4?
- P1=yinyue[jp];
- if(jp!=0)
- {
- timeh=chuzhi[jp*2];
- timel=chuzhi[jp*2+1];
- }
- else
- {
- TR0=0;
- fm=1;//????
- }
- delay(temp%16); //????4?
- TR0=0; //??????10MS
- fm=1;
- delay1(10);
- TR0=1;
- i++;
- }
- }
- i=0;
- TR0=0;
- fm=1;
- }
- void delay(uint z) //??165MS,??????
- { uint x,y;
- for(x=z;x>0;x--)
- for(y=19000;y>0;y--);
- }
- void delay1(uint z) //??1MS
- { uint x,y;
- for(x=z;x>0;x--)
- for(y=112;y>0;y--);
- }
- void beep() //??????
- { uchar i;
- for(i=0;i<50;i++)
- { fm=~fm;
- delay1(1);
- }
- fm=1;
- }
复制代码
|