新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 基于51单片机的各种花样的流水灯c51程序

基于51单片机的各种花样的流水灯c51程序

作者:时间:2012-09-11来源:网络收藏

/*-----------------------------------------------
功能:灯对称移动闪烁(双闪烁)

本文引用地址:http://www.eepw.com.cn/article/170895.htm

------------------------------------------------*/

#includeREG52.H>
#define uint unsigned int
void delay(uint);
main()
{
uint comp1=0xfe;
uint comp2=0x80;
P1=0x7e;
delay(30000);
while(1)
{
P1=0xff;
comp1=1;
comp1|=0x01;
comp2>>=1;
P1=comp1;
P1^=comp2;
delay(30000);
if(P1==0xe7)
{
comp1=1;
comp1|=0x01;
comp2>>=1;
}

if(comp1==0x7f)
{
comp1=0xfe;
comp2=0x80;
}
}
}
void delay(uint cnt)
{
while(cnt--);
}


/*-----------------------------------------------------------------

只循环一次,而没有一直循环下去,出错地方在:

通过添加一条测试语句:

if(comp1==0x7f)
{
comp1=0xfe; comp2=0x80;
P1=0x00; delay(30000);

}

发现if语句没有被执行,自然继续左右移动:

1111 11111111 1111^0000 0000==11111 1111

所以看起来是执行了一次while中的代码。

具体为什么不行,还不清楚……

更正下列代码后,能够实现功能。

if(P1==0x7e)
{
comp1=0xfe;
comp2=0x80;
}

或者:

if(comp2==0x01)
{
comp1=0xfe;
comp2=0x80;
}

--------------------------------------------------------------*/


上一页 1 2 3 下一页

评论


相关推荐

技术专区

关闭