#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);
}
}
}
|