用单片机p2口接八个发光二极管 实现流水灯控制 画出电路图 编写程序

2024-11-01 09:20:13
推荐回答(2个)
回答1:

#include

#define uchar unsigned char

#define uint unsigned int


uint num=0,i=0;

uchar code LED[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};

void main()

{

     EA=1;

     ET0=1;

     TMOD=0x01;

     TH0=(65536-50000)/256;

     TL0=(65536-50000)%256;

     TR0=1;

     P1=0;

     while(1)

     {

          if(num==2)

          {

              num=0;

              P1=LED[i];

             i++;

             if(i>7) i=0;

         }

     }

}

void time0() interrupt 1

{

    num++;

    TH0=(65536-50000)/256;

    TL0=(65536-50000)%256;

}

回答2:

#include
#include
void delay(int a)
{
while(a--);
}
main()
{
P2=0xfe;
while(1)
{
P2=_crol_(P2,1);
delay(30000);
}
}