51单片机实现流水灯
选材
芯片:AT89C51,仿真工具Professional7.8,代码编写工具Keil5
代码
#include <reg52.h>//51单片机的C语言库
#include <intrins.h>//为加入左右移动函数的库
void Delay(unsigned int x){
unsigned char i;
while(x--){
for(i=121;i>0;i--);
}
}
unsigned int j;
void main(){
P0 = 0xfe;
Delay(150);
while(1){
for(j=0;j<7;j++)
{
P0=_crol_(P0,1);//左移
Delay(150);
}
for(j=0;j<7;j++)
{
P0=_cror_(P0,1);//右移
Delay(150);
}
}
}
仿真图示
完成后实现左右移动的流水灯