流水燈是很多初學者學習的一個程序,可以這么說是一個必學程序,舉個很簡單的它的應用,很多生產線都需要用到左移,右移的操作,也許流水燈的程序就是最簡單的,也稱得上比較經典的例子吧。
程序:#include<reg52.h>
#include<intrins.h>
#define uni unsigned int
#define unc unsigned char
void delay(int);
unc tems;
void main()
{
tems = 0xfe;
P1 = tems;//給P1口賦值
while(1)
{
tems = _cror_(tems,1);//移位操?
delay(300);
P1 = tems;
}
}
void delay(int z)//延時子程序
{
uni x,y;
for(x=z;x>0;x--)
for(y=500;y>0;y--);
}