单片机LED流水灯循环问题

#include<reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uint temp,i,cishu;
void delay(uint);
void main()
{
temp=0xfe;
P1=temp;
cishu=0; //为次数 赋值0
while(cishu<2) // 规定流水灯来回循环2次
{
cishu++; //每一次循环 次数 +1

for(i=7;i>0;i--) { temp=_crol_(temp,1); delay(300); P1=temp; } //左移
for(i=7;i>0;i--) { temp=_cror_(temp,1); delay(300); P1=temp; } //右移

}
delay(300);
temp=0xff; //两次循环结束后 跳出while,执行此处的 P1口全部灭
P1=temp;

}
void delay(uint z)
{
uint x,y;
for(x=100;x>0;x--)
for(y=z;y>0;y--);
}
出现的问题是 LED 灯一直来回的循环不停止了。。。 我用while(cishu<2) 来限制程序执行的次数 但是 好像这个while(cishu<2) 并没有 作用 请问这程序错在哪了?

#include<reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
uint temp,i,cishu;
void delay(uint);
void main()
{
temp=0xfe;
P1=temp;
cishu=0; //为次数 赋值0
while(cishu<2) // 规定流水灯来回循环2次
{
cishu++; //每一次循环 次数 +1

for(i=7;i>0;i--) { temp=_crol_(temp,1); delay(300); P1=temp; } //左移
for(i=7;i>0;i--) { temp=_cror_(temp,1); delay(300); P1=temp; } //右移

}
delay(300);
temp=0xff; //两次循环结束后 跳出while,执行此处的 P1口全部灭
P1=temp;
while(1);
}
void delay(uint z)
{
uint x,y;
for(x=100;x>0;x--)
for(y=z;y>0;y--);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-06-11
程序好像没得错吧 我没看出来 不过实验板会循环执行烧写的程序,所以 你可以看看 把跳出循环完的时间延时多一点 看看 是不是按照程序来的
相似回答