#define uint unsigned int
delay(uint);
void main()
{
WDTCTL = 0x5A80;
uint ch[8] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uint i,j;
P2DIR = 0xff;
P2OUT = 0xff; //低电平点亮
while(1)
{
for(i=0;i<8;i++)
{
P2OUT = ch[i];
delay(50000);
}
for(j=6;j>0;j--)
{
P2OUT = ch[j];
delay(50000);
}
}
}
void delay(uint z)
{
uint a;
for(a=0;a
1.这是较为简单的流水灯程序,没有使用定时器,只是简单的延时;
若要精确延时,需要设置定时器A或B.
2.也可以通过移位操作来实现流水灯,移位操作放入中断内最好