|
#include <reg52.h> //51頭文件
#include <intrins.h>//包含循環(huán)右移函數(shù)_cror頭文件
#define uchar unsigned char //宏定義
#define uint unsigned int //宏定義
sbit LED1 = P1^0; //位定義LED1硬件接口
uchar i; //申明循環(huán)計(jì)數(shù)變量
uchar temp;//P1口狀態(tài)暫存變量
//毫秒級(jí)延時(shí)函數(shù)
void delay(uint z)
{
uint x,y;
for(x = z; x > 0; x--)
for(y = 120; y > 0 ; y--);
}
//主函數(shù)
void main()
{
temp = 0x7f; //定義LED燈初始狀態(tài),從LED8開始亮
P1 = temp; //賦值給P1,點(diǎn)亮LED8
delay(1000); //延時(shí)1000毫秒
while(1) //大循環(huán)
{
for(i = 0; i < 8; i++)
{
temp = _cror_(temp,1);//循環(huán)右移,LED從左至右點(diǎn)亮
P1 = temp;
delay(1000);
}
}
}
|
|