#include <reg52.h> //51头文件
#include <intrins.h>//包含循环右移函数_cror头文件
#define uchar unsigned char //宏定义
#define uint unsigned int //宏定义
sbit LED1 = P1^0; //位定义LED1硬件接口
uchar i; //申明循环计数变量
uchar temp;//P1口状态暂存变量
//毫秒级延时函数
void delay(uint z)
{
uint x,y;
for(x = z; x > 0; x--)
for(y = 120; y > 0 ; y--);
}
//主函数
void main()
{
temp = 0x7f; //定义LED灯初始状态,从LED8开始亮
P1 = temp; //赋值给P1,点亮LED8
delay(1000); //延时1000毫秒
while(1) //大循环
{
for(i = 0; i < 8; i++)
{
temp = _cror_(temp,1);//循环右移,LED从左至右点亮
P1 = temp;
delay(1000);
}
}
}
|