(1)此程序灯亮过去之后不会灭,到最后变成全亮。
#include<reg52.h>
#include<intrins.h>
void Delay(unsigned int t)
{
while(t--);
}
void main()
{
unsigned int i;
while(1)
{
P1=0xfe;
for(i=0;i<8;i++)
{
Delay(10000);
P1<<=1;
}
}
/*P1=0xfe;
for(i=0;i<8;i++)
{
Delay(10000);
P1<<=1;
}
while(1);*/
}
(2)将上面程序稍作修改,灯亮过之后就会灭了。相当于调用_cror_()函数的效果。
#include<reg52.h>
#include<intrins.h>
void Delay(unsigned int t)
{
while(t--);
}
void main()
{
unsigned int i;
while(1)
{
P1=0xfe;
for(i=0;i<8;i++)
{
Delay(10000);
P1<<=1;
P1++;//在此处将刚亮完的灯置高电平,所以变暗。
}
}
/*P1=0xfe;
for(i=0;i<8;i++)
{
Delay(10000);
P1<<=1;
}
while(1);*/
}