帮忙找一下哪个地方错了
程序代码:
//stc89c52 #include "reg51.h" #include"74HC595.H" #define Key P1 #define Out1 P3 #define Out2 P2 //#define indicator P0 #define uint unsigned int #define uchar unsigned char #define PowerUP 0x200 //上电 #define PlayAddress 0xe00 //播放地址 #define PlayR 0xf00 //播放开始 #define Stop 0x300 //停止操作 sfr P4=0xe8;//STC单片机 sbit KeyA=P1^0; //8个手掌按键 sbit KeyB=P1^1; sbit KeyC=P1^2; sbit KeyD=P1^3; sbit KeyE=P1^4; sbit KeyF=P1^5; sbit KeyG=P1^6; sbit KeyH=P1^7; sbit ModeKey=P3^5; sbit SS = P4^0;//语音芯片控制端 sbit MOSI = P4^1; sbit SCLK = P4^2; sbit ISD_Int = P4^3; //模式按键 //sbit SS=P3^7; //三个声音控制输出口 //sbit SCLK=P3^4; //sbit MOSI=P3^6; sbit LOut1=P3^1; sbit LOut2=P3^0; sbit Out1LED1=P2^0; //按键A~F灯光输出控制端口 sbit Out1LED2=P2^1; sbit Out1LED3=P2^2; sbit Out1LED4=P2^3; sbit Out1LED5=P2^4; sbit Out1Red=P2^5; sbit Out1Green=P2^6; sbit Out1Blue=P2^7; sbit Out1Yellow=P3^2; bit Sound1=0,Sound2=0,Sound3=0,Sound4=0,Sound5=0,Sound6=0,Sound7=0,Sound8=0; uchar K1=0,K2=0,K3=0,K4=0,K5=0,K6=0,LED=0x80,Mode=0; uint code PlayAddressTeam[64]={ 0x00,0x97,0x179,0x2D2,0x07,0xF4,0x1D9,0x2B7, 0x16,0xB3,0x196,0x2F2,0x24,0x111,0x1F5,0x2D3, 0x30,0xD0,0x1A9,0x31E,0x42,0x12F,0x211,0x2F0, 0x46,0xEB,0x1E2,0x33B,0x5F,0x14B,0x22D,0x30C, 0x56,0x108,0x210,0x359,0x7D,0x167,0x249,0x325, 0x69,0x123,0x226,0x395,0x9B,0x181,0x265,0x342, 0x74,0x13F,0x267,0x3CB,0xB9,0x19C,0x280,0x35B, 0x91,0x15D,0x2A3,0x3E9,0xD6,0x1BB,0x28C,0x376}; void Delay10ms() { unsigned char a,b,c; for(c=1;c>0;c--) for(b=38;b>0;b--) for(a=130;a>0;a--); } void WriteCategory(uint abc,def) //写入24位数据 { uint m,n,j; uchar i; SS=1; SCLK=0; MOSI=0; n=abc; m=def; SS=0; for(i=0;i<12;i++) { SCLK=0; j=m&0x001; if(j==0)MOSI=0; else MOSI=1; SCLK=1; m=m>>1; } for(i=0;i<12;i++) { SCLK=0; j=n&0x001; if(j==0)MOSI=0; else MOSI=1; SCLK=1; n=n>>1; } SS=1; } void PowerUpCategory(void) //上电 { WriteCategory(PowerUP,0); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); } void ModeKeyCategory() //模式选择 { ModeKey=1; if(ModeKey==0) { Delay10ms(); if(ModeKey==0) { LED=LED>>1; Mode=Mode+8; } if(Mode>56)Mode=0; if(LED==0)LED=0x80; while(ModeKey==0); } HC595_Play(LED); //indicator=LED; } void PlayCategory(uint cp) //播放 { WriteCategory(Stop,0); Delay10ms(); Delay10ms(); Delay10ms(); WriteCategory(PlayAddress,cp); //写地址 WriteCategory(PlayR,0); //写播放指令 Delay10ms(); } void Timer0int()interrupt 1 { TH0=60; TL0=171; if(KeyA==1) { K1++; if(K1>=40)K1=0; } if(KeyB==1) { K2++; if(K2>=40)K2=0; } if(KeyC==1) { K3++; if(K3>=40)K3=0; } if(KeyD==1) { K4++; if(K4>=40)K4=0; } if(KeyE==1) { K5++; if(K5>=40)K5=0; } if(KeyF==1)K6++; } void Key1_6Act(void) { if(KeyA==1) //按键1动作 { if(K1<=20)Out1LED1=1; else Out1LED1=0; if(Sound1==0) { PlayCategory(PlayAddressTeam[Mode+0]); } Sound1=1; } else if(KeyA==0) { Out1LED1=0; Sound1=0; } if(KeyB==1) //按键2动作 { if(K2<=20)Out1LED2=1; else Out1LED2=0; if(Sound2==0) { PlayCategory(PlayAddressTeam[Mode+1]); } Sound2=1; } else if(KeyB==0) { Out1LED2=0; Sound2=0; } if(KeyC==1) //按键3动作 { if(K3<=20)Out1LED3=1; else Out1LED3=0; if(Sound3==0) { PlayCategory(PlayAddressTeam[Mode+2]); } Sound3=1; } else if(KeyC==0) { Out1LED3=0; Sound3=0; } if(KeyD==1) //按键4动作 { if(K4<=20)Out1LED4=1; else Out1LED4=0; if(Sound4==0) { PlayCategory(PlayAddressTeam[Mode+3]); } Sound4=1; } else if(KeyD==0) { Out1LED4=0; Sound4=0; } if(KeyE==1) //按键5动作 { if(K5<=20)Out1LED5=1; else Out1LED5=0; if(Sound5==0) { PlayCategory(PlayAddressTeam[Mode+4]); } Sound5=1; } else if(KeyE==0) { Out1LED5=0; Sound5=0; } if(KeyF==1) //按键6动作 { if(K6<20) { Out1Red=1; Out1Green=0; Out1Blue=0; Out1Yellow=0; } else if((K6<40)&&(K6>=20)) { Out1Red=0; Out1Green=1; Out1Blue=0; Out1Yellow=0; } else if((K6<60)&&(K6>=40)) { Out1Red=0; Out1Green=0; Out1Blue=1; Out1Yellow=0; } else if((K6<80)&&(K6>=60)) { Out1Red=0; Out1Green=0; Out1Blue=0; Out1Yellow=1; } else if(K6>=80)K6=0; if(Sound6==0) { PlayCategory(PlayAddressTeam[Mode+5]); } Sound6=1; } else if(KeyF==0) { Out1Red=0; Out1Green=0; Out1Blue=0; Out1Yellow=0; Sound6=0; } } void Key7_8Act(void) { if(KeyG==1) //按键7动作 { Delay10ms(); LOut1=0; if(Sound7==0) { PlayCategory(PlayAddressTeam[Mode+6]); } Sound7=1; } else if(KeyG==0) { LOut1=1; Sound7=0; } if(KeyH==1) //按键8动作 { Delay10ms(); LOut2=0; if(Sound8==0) { PlayCategory(PlayAddressTeam[Mode+7]); } Sound8=1; } else if(KeyH==0) { LOut2=1; Sound8=0; } } main() { //indicator=0x01; //模式指示灯 Key=0xff; //按键ABCDEFGH Out1=0; //声音及串行输出 Out2=0; //按键1~6输出 ModeKey=1; //模式选择按键 TMOD=0x01; ET0=1; EA=1; Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); Delay10ms(); PowerUpCategory(); HC595_Init(); TR0=1; while(1) { ModeKeyCategory(); Key1_6Act(); Key7_8Act(); //HC595_Play(LED); } }