自己写了个流水灯程序,编译有错误。keil 51单片机。
#include"reg51.h"#defineucharunsignedchar#defineuintunsignedintsbitP31=P3^1;delay();k...
#include"reg51.h"#define uchar unsigned char#define uint unsigned intsbit P31=P3^1;delay();keyscan();keyhandle();moveleft();moveright();
uint keyvalue,z=8,i;
void delay(uint time){uint i,j;for(i=0;i<time;i++)for(j=0;j<50;j++);}
keyscan(){P3=0xff;if(P3!=0xff){delay(20);if(P3!=0xff)keyvalue=(P3&0xff);}}
keyhandle(){switch(keyvalue){case 0xef:moveleft;break;//case 0xbf:;break;case 0xdf:moveright;break;default:break;}}
moveleft(){while(1){for(i=0;i<8;i++){P1=~z;delay(2000);z<<=1;if(z==0)z=1;if(P31==0){delay(20);if(P31==0)break;}}if(P31==0){delay(20);if(P31==0)break;}}}
moveright(){while(1){while(1){P1=~z;delay(2000);z>>=1;if(z==0)z=0xef;if(P31==0){delay(20);if(P31==0)break;}}if(P31==0){delay(20);if(P31==0)break;}}}
void main(){while(1){keyscan();keyhandle();}} 展开
uint keyvalue,z=8,i;
void delay(uint time){uint i,j;for(i=0;i<time;i++)for(j=0;j<50;j++);}
keyscan(){P3=0xff;if(P3!=0xff){delay(20);if(P3!=0xff)keyvalue=(P3&0xff);}}
keyhandle(){switch(keyvalue){case 0xef:moveleft;break;//case 0xbf:;break;case 0xdf:moveright;break;default:break;}}
moveleft(){while(1){for(i=0;i<8;i++){P1=~z;delay(2000);z<<=1;if(z==0)z=1;if(P31==0){delay(20);if(P31==0)break;}}if(P31==0){delay(20);if(P31==0)break;}}}
moveright(){while(1){while(1){P1=~z;delay(2000);z>>=1;if(z==0)z=0xef;if(P31==0){delay(20);if(P31==0)break;}}if(P31==0){delay(20);if(P31==0)break;}}}
void main(){while(1){keyscan();keyhandle();}} 展开
2个回答
展开全部
// 修改了好几处,哥们好好学习c语言,加油
#include"reg51.h"
#define uchar unsigned char
#define uint unsigned int
sbit P31=P3^1;
void delay(uint );
void keyscan();
void keyhandle();
void moveleft();
void moveright();
uint keyvalue,z=8,i;
void delay(uint time)
{
uint i,j;
for(i=0;i<time;i++)
for(j=0;j<50;j++);
}
void keyscan()
{
P3=0xff;
if(P3!=0xff)
{delay(20);if(P3!=0xff)keyvalue=(P3&0xff);}
}
void keyhandle()
{
switch(keyvalue)
{
case 0xef:moveleft();break;
//case 0xbf:;break;
case 0xdf:moveright();break;
default:break;
}
}
void moveleft()
{
while(1)
{
for(i=0;i<8;i++)
{P1=~z;delay(2000);
z<<=1;if(z==0)z=1;
if(P31==0){delay(20);if(P31==0)break;}}
if(P31==0){delay(20);if(P31==0)break;}
}
}
void moveright()
{
while(1)
{
while(1)
{P1=~z;delay(2000);
z>>=1;if(z==0)z=0xef;
if(P31==0){delay(20);if(P31==0)break;}}
if(P31==0){delay(20);if(P31==0)break;}
}
}
void main()
{
while(1)
{keyscan();
keyhandle();
}
}
更多追问追答
追问
是在所以函数名和声明之前加一个void?编译还是有2个错啊
追答
你用我的程序,不会有错。其他地方有修改。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询