一个c语言程序关于10个led流水灯的

2025-04-10 14:44:08
推荐回答(1个)
回答1:

这是正确程序 ,望采纳。最好采用低电平触发  ,否则,单片机在上电的瞬间所有的LED灯会闪一下。

#include   

#include 


void Delay10ms(unsigned int c);       

main()

{


unsigned char i;


while (1)

{   P0=0x00;

    P2=0x00;

  while(1) 

  { P2 = 0x02;

   Delay10ms(50);

   P2 = P2 >>1;   

   Delay10ms(50);

if (P2 == 0x01)

{ P2 = 0x00;

  P0=0x80;

  Delay10ms(50);

  for(i=0;i<7;i++)

  {

    P0=P0>>1;

    Delay10ms(50); 

}

  if(P0==0x01)

  P0=0x00;


}

      

}

void Delay10ms(unsigned int c)  

{

    unsigned char a, b;


 for (;c>0;c--)

{

for (b=38;b>0;b--)

{

for (a=130;a>0;a--);

}

           

}       

}