请问一段代码的问题
#include<reg51.h>#define SHOW P0
sbit btnStart = P1^0;
sbit btnStop = P1^7;
sbit btnP = P1^1;
sbit btnR = P1^2;
sbit btnN = P1^3;
sbit btnD = P1^4;
sbit lwP = P2^0;
sbit lwN = P3^4;
sbit rwP = P2^1;
sbit rwN = P3^5;
int fStart = 0;
int fP = 0;
int fR = 0;
int fN = 0;
int fD = 0;
int segP = 0x8c;
int segR = 0x88;
int segN = 0xc8;
int segD = 0xa1;
void gearP();
void gearR();
void gearN();
void gearD();
void initial();
void delay(int time);
void main()
{
initial();
while(1)
{
if(btnStart == 0)
{
while(btnStart == 0)
{
;
}
fStart = 1;
}
if(btnStop == 0)
{
while(btnStop == 0)
{
;
}
fStart = 0;
}
if(fStart == 1)
{
if(btnP == 0)
{
while(btnP == 0)
{
;
}
fP = 1;
fR = 0;
fN = 0;
fD = 0;
}
if(btnR == 0)
{
while(btnR == 0)
{
;
}
fP = 0;
fR = 1;
fN = 0;
fD = 0;
}
if(btnN == 0)
{
while(btnN == 0)
{
;
}
fP = 0;
fR = 0;
fN = 1;
fD = 0;
}
if(btnD == 0)
{
while(btnD == 0)
{
;
}
fP = 0;
fR = 0;
fN = 0;
fD = 1;
}
if(fP == 1)
{
gearP();
}
if(fR == 1)
{
gearR();
}
if(fN == 1)
{
gearN();
}
if(fD == 1)
{
gearD();
}
}
else
{
initial();
}
}
}
void gearP()
{
SHOW = segP;
lwP = 1;
lwN = 1;
rwP = 1;
rwN = 1;
}
void gearR()
{
SHOW = segR;
lwP = 0;
lwN = 1;
rwP = 0;
rwN = 1;
delay(20);
lwP = 0;
lwN = 0;
rwP = 0;
rwN = 0;
delay(20);
}
void gearN()
{
SHOW = segN;
lwP = 0;
lwN = 0;
rwP = 0;
rwN = 0;
}
void gearD()
{
SHOW = segD;
lwP = 1;
lwN = 0;
rwP = 1;
rwN = 0;
}
void initial()
{
fStart = 0;
fP = 0;
fR = 0;
fN = 0;
fD = 0;
P0 = 0xff;
P1 = 0xff;
P2 = 0xff;
P3 = 0xff;
}
void delay(int time)
{
int i,j;
for(i=0;i<time;i++)
{
for(j=0;j<120;j++)
{
;
}
}
}
SHOW = segR;
lwP = 0;
lwN = 1;
rwP = 0;
rwN = 1;
delay(20);
lwP = 0;
lwN = 0;
rwP = 0;
rwN = 0;
delay(20);这段 为什么后面延时一定要加
lwP = 0;
lwN = 0;
rwP = 0;
rwN = 0;
delay(20);不是有delay(20);了吗
lwP = 0;
lwN = 1;
rwP = 0;
rwN = 1;这4个信号是一组的,所以为了防止忘记对他们其中哪个赋值,所以每次都是4个一起赋值。这仅仅是为了方便看代码,你也可以不对那些值没改变的信号赋值,
难道一个两帖子还要散两次分?嘎嘎 哥,你的问题是啥啊? maomingkun 发表于 2014-1-9 11:04 static/image/common/back.gif
哥,你的问题是啥啊?
if(btnR == 0)
{
while(btnR == 0)
{
;
}
fP = 0;
fR = 1;
fN = 0;
fD = 0;
}
这段请问一下 是不是btnR == 0就一直空循环在那 如果不是就执行
fP = 0;
fR = 1;
fN = 0;
fD = 0;这个呢???? 请问能不能把这个程序想干什么写上(还有注释)? 这场雨好安静 发表于 2014-1-9 13:50 static/image/common/back.gif
if(btnR == 0)
{
while(btnR == 0)
是啊,这个程序好像有问题 这场雨好安静 发表于 2014-1-9 13:50 static/image/common/back.gif
if(btnR == 0)
{
while(btnR == 0)
这个while确实是等待btnR变为非零才退出循环。因为你的程序一定存在中断处理程序,该中断里将btnR变为非零了。 太长不看:huffy::huffy::huffy::huffy::huffy: 坑这么长的 好长的代码呀。。看得头的晕了~~
页:
[1]