第1个回答 2013-07-05
//=======================
// 8个LED 闪烁
// 用来回循环亮
//-------------------------------------
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar i ;
//--------------------------------
void DelayMS(uint ms)
{
uchar t;
while(ms--) for (t=0;t<120;t++);
}
//----------------------------------
void main()
{
P2= 0xfe;
while (1)
{
for ( i = 0; i < 7; i++)
{P2 =_crol_(P2,1); //左移
DelayMS(200);
}
for ( i = 0; i < 7; i++)
{P2 =_cror_(P2,1); //右移
DelayMS(200);
}
}
}