作者:靓仔瞳瞳

【51单片机】LED灯合集(下)

八、8位LED左移

#include<reg52.h> //包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义


void Delay(unsigned int t); //函数声明

/*------------------------------------------------
                    主函数
------------------------------------------------*/
void main (void)
{
                  
unsigned char i;  //定义一个无符号字符型局部变量 i 取值范围 0~255
Delay(50000);
P1=0xfe;           //赋初始值
for(i=0;i<8;i++)   //加入 for循环,表明for循环大括号中的程序循环执行8次
  {
   Delay(50000);
   P1<<=1;
  }
while (1)         //主循环
  {
                   //主循环中添加其他需要一直工作的程序
  }
}
/*------------------------------------------------
 延时函数,含有输入参数 unsigned int t,无返回值
 unsigned int 是定义无符号整形变量,其值的范围是
 0~65535
------------------------------------------------*/
void Delay(unsigned int t)
{
 while(--t);
}

九、8位LED右移

#include<reg52.h> //包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义


void Delay(unsi
lock