您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > 单片机音乐流水灯论文的电路图及源程序
音乐流水灯电路图音乐流水灯程序:#includeREG52.H#includeSoundPlay.hunsignedcharRunMode;//**********************************SystemFuction*************************************************voidDelay1ms(unsignedintcount){unsignedinti,j;for(i=0;icount;i++)for(j=0;j120;j++);}unsignedcharcodeLEDDisplayCode[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,//0~70x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF};voidDisplay(unsignedcharValue){P1=LEDDisplayCode[Value];}voidLEDFlash(unsignedcharCount){unsignedchari;bitFlag;for(i=0;iCount;i++){Flag=!Flag;if(Flag)Display(RunMode);elseDisplay(0x10);Delay1ms(100);}Display(RunMode);}unsignedcharGetKey(void){unsignedcharKeyTemp,CheckValue,Key=0x00;CheckValue=P2&0x32;if(CheckValue==0x32)return0x00;Delay1ms(10);KeyTemp=P2&0x32;if(KeyTemp==CheckValue)return0x00;if(!(CheckValue&0x02))Key|=0x01;if(!(CheckValue&0x10))Key|=0x02;if(!(CheckValue&0x20))Key|=0x04;returnKey;}unsignedintTimer0Count,SystemSpeed,SystemSpeedIndex;voidInitialTimer2(void){T2CON=0x00;//16BitAuto-ReloadModeTH2=RCAP2H=0xFC;//重装值,初始值TL2=RCAP2L=0x18;ET2=1;//定时器2中断允许TR2=1;//定时器2启动EA=1;}unsignedintcodeSpeedCode[]={1,2,3,5,8,10,14,17,20,30,40,50,60,70,80,90,100,120,140,160,180,200,300,400,500,600,700,800,900,1000};//30voidSetSpeed(unsignedcharSpeed){SystemSpeed=SpeedCode[Speed];}voidLEDShow(unsignedintLEDStatus){P1=~(LEDStatus&0x00FF);P0=~((LEDStatus8)&0x00FF);}voidInitialCPU(void){RunMode=0x00;Timer0Count=0;SystemSpeedIndex=9;P1=0x00;P0=0x00;P2=0xFF;P3=0x00;Delay1ms(500);P1=0xFF;P0=0xFF;P2=0xFF;P3=0xFF;SetSpeed(SystemSpeedIndex);Display(RunMode);}//Mode0unsignedintLEDIndex=0;bitLEDDirection=1,LEDFlag=1;voidMode_0(void){LEDShow(0x0001LEDIndex);LEDIndex=(LEDIndex+1)%16;}//Mode1voidMode_1(void){LEDShow(0x8000LEDIndex);LEDIndex=(LEDIndex+1)%16;}//Mode2voidMode_2(void){if(LEDDirection)LEDShow(0x0001LEDIndex);elseLEDShow(0x8000LEDIndex);if(LEDIndex==15)LEDDirection=!LEDDirection;LEDIndex=(LEDIndex+1)%16;}//Mode3voidMode_3(void){if(LEDDirection)LEDShow(~(0x0001LEDIndex));elseLEDShow(~(0x8000LEDIndex));if(LEDIndex==15)LEDDirection=!LEDDirection;LEDIndex=(LEDIndex+1)%16;}//Mode4voidMode_4(void){if(LEDDirection){if(LEDFlag)LEDShow(0xFFFELEDIndex);elseLEDShow(~(0x7FFFLEDIndex));}else{if(LEDFlag)LEDShow(0x7FFFLEDIndex);elseLEDShow(~(0xFFFELEDIndex));}if(LEDIndex==15){LEDDirection=!LEDDirection;if(LEDDirection)LEDFlag=!LEDFlag;}LEDIndex=(LEDIndex+1)%16;}//Mode5voidMode_5(void){if(LEDDirection)LEDShow(0x000FLEDIndex);elseLEDShow(0xF000LEDIndex);if(LEDIndex==15)LEDDirection=!LEDDirection;LEDIndex=(LEDIndex+1)%16;}//Mode6voidMode_6(void){if(LEDDirection)LEDShow(~(0x000FLEDIndex));elseLEDShow(~(0xF000LEDIndex));if(LEDIndex==15)LEDDirection=!LEDDirection;LEDIndex=(LEDIndex+1)%16;}//Mode7voidMode_7(void){if(LEDDirection)LEDShow(0x003FLEDIndex);elseLEDShow(0xFC00LEDIndex);if(LEDIndex==9)LEDDirection=!LEDDirection;LEDIndex=(LEDIndex+1)%10;}//Mode8voidMode_8(void){LEDShow(++LEDIndex);}voidTimer0EventRun(void){if(RunMode==0x00){Mode_0();}elseif(RunMode==0x01){Mode_1();}elseif(RunMode==0x02){Mode_2();}elseif(RunMode==0x03){Mode_3();}elseif(RunMode==0x04){Mode_4();}elseif(RunMode==0x05){Mode_5();}elseif(RunMode==0x06){Mode_6();}elseif(RunMode==0x07){Mode_7();}elseif(RunMode==0x08){Mode_8();}}voidTimer2(void)interrupt5using3{TF2=0;//中断标志清除(Timer2必须软件清标志!)if(++Timer0Count=SystemSpeed){Timer0Count=0;Timer0EventRun();}}unsignedcharMusicIndex=0;voidKeyDispose(unsignedcharKey){if(Key&0x01){LEDDirection=1;LEDIndex=0;LEDFlag=1;RunMode=(RunMode+1)%10;Display(RunMode);if(RunMode==0x09)TR2=0;elseTR2=1;}if(Key&0x02){if(RunMode==0x09){MusicIndex=(MusicIndex+MUSICNUMBER-1)%MUSICNUMBER;}else{if(SystemSpeedIndex0){--SystemSpeedIndex;SetSpeed(SystemSpeedIndex);}else{LEDFlash(6);}}}if(Key&0x04){if(RunMode==0x09){MusicIndex=(MusicIndex+1)%MUSICNUMBER;}else{if(SystemSpeedIndex28){++SystemSpeedIndex;SetSpeed(SystemSpeedIndex);}else{LEDFlash(6);}}}}//*****************************Music******************************************************//挥着翅膀的女孩unsignedcharcodeMusic_Girl[]={0x17,0x02,0x17,0x03,0x18,0x03,0x19,0x02,0x15,0x03,0x16,0x03,0x17,0x03,0x17,0x03,0x17,0x03,0x18,0x03,0x19,0x02,0x16,0x03,0x17,0x03,0x18,0x02,0x18,0x03,0x17,0x03,0x15,0x02,0x18,0x03,0x17,0x03,0x18,0x02,0x10,0x03,0x15,0x03,0x16,0x02,0x15,0x03,0x16,0x03,0x17,0x02,0x17,0x03,0x18,0x03,0x19,0x02,0x1A,0x03,0x1B,0x03,0x1F,0x03,0x1F,0x03,0x17,0x03,0x18,0x03,0x19,0x02,0x16,0x03,0x17,0x03,0x18,0x03,0x17,0x03,0x18,0x03,0x1F,0x03,0x1F,0x02,0x16,0x03,0x17,0x03,0x18,0x03,0x17,0x03,0x18,0x03,0x20,0x03,0x20,0x02,0x1F,0x03,0x1B,0x03,0x1F,0x66,0x20,0x03,0x21,0x03,0x20,0x03,0x1F,0x03,0x1B,0x03,0x1F,0x66,0x1F,0x03,0x1B,0x03,0x19,0x03,0x19,0x03,0x15,0x03,0x1A,0x66,0x1A,0x03,0x19,0x03,0x15,0x03,0x15,0x03,0x17,0x03,0x16,0x66,0x17,0x04,0x18,0x04,0x18,0x03,0x19,0x03,0x1F,0x03,0x1B,0x03,0x1F,0x66,0x20,0x03,0x21,0x03,0x20,0x03,0x1F,0x03,0x1B,0x03,0x1F,0x66,0x1F,0x03,0x1B,0x03,0x19,0x03,0x19,0x03,0x15,0x03,0x1A,0x66,0x1A,0x03,0x19,0x03,0x19,0x03,0x1F,0x03,0x1B,0x03,0x1F,0x00,0x1A,0x03,0x1A,0x03,0x1A,0x03,0x1
本文标题:单片机音乐流水灯论文的电路图及源程序
链接地址:https://www.777doc.com/doc-4383019 .html