單片機(jī)流水燈三個(gè)點(diǎn)亮方向
三、斜向點(diǎn)亮(從P0~P3口斜向點(diǎn)亮)
include reg52.h //此處使用的為89S52的芯片
void delay(unsigned int second)
{
unsigned int i,j; //定義為unsigned防止負(fù)數(shù),習(xí)慣問題
for(i=0;isecond;i++)
{
for(j=0;j200000;j++);
}
}
void main(void)
{
unsigned i;
while(1)
{
for(i=0;i8;i++)
{
P0=0x01i;
delay(100);
P0=0;
P1=0x01(i7?i+1:i-7); //此處反映了當(dāng)i為7時(shí);0x01左移0位,亮P0.0的燈
delay(100);
P1=0;
P2=0x01(i6?i+2:i-6); //此處反映了當(dāng)i大于6時(shí);0ix01左移i-6位,亮P0.(i-6)的燈
delay(100);
P2=0:
P3=0x01(i5?i+3:i-5; //同上
delay(100);
P3=0:
}
}
}
評(píng)論