ai thu gọn đoạn code này giúp e với . . . e mới viết xong nhưng còn gà nên nó dài wa . . hihi
#include <REGX51.H>
sbit led1 = P3^0;
sbit led2 = P3^1;
sbit led3 = P3^2;
sbit led4 = P3^3;
sbit led5 = P3^4;
sbit led6 = P3^5;
sbit led7 = P3^6;
sbit led8 = P3^7;
void huy ( unsigned long ms )
{
while ( ms--);
}
void main ( void )
{
int i;
{
P3=1;
huy ( 25000);
for ( i=1; i<=7;i++)
{
P3=P3<<1;
huy ( 25000);
}
{
led8=1; //led 8 sang
led1=1;
huy(25000);
led1=0;
led2=1;
huy(25000);
led2=0;
led3=1;
huy(25000);
led3=0;
led4=1;
huy(25000);
led4=0;
led5=1;
huy(25000);
led5=0;
led6=1;
huy(25000);
led6=0;
led7=1;
huy(25000);
led7=0;
}
for ( i=2; i<=2;i++) //led 7,8 sang
{
led8=1;
led7=1;
led1=1;
huy(25000);
led1=0;
led2=1;
huy(25000);
led2=0;
led3=1;
huy(25000);
led3=0;
led4=1;
huy(25000);
led4=0;
led5=1;
huy(25000);
led5=0;
led6=1;
huy(25000);
led6=0;
}
for ( i=2; i<=2;i++) //led 6,7,8 sang
{
led8=1;
led7=1;
led6=1;
led1=1;
huy(25000);
led1=0;
led2=1;
huy(25000);
led2=0;
led3=1;
huy(25000);
led3=0;
led4=1;
huy(25000);
led4=0;
led5=1;
huy(25000);
led5=0;
led6=1;
}
for ( i=2; i<=2;i++) //led 5,6,7,8 sang
{
led8=1;
led7=1;
led6=1;
led5=1;
led1=1;
huy(25000);
led1=0;
led2=1;
huy(25000);
led2=0;
led3=1;
huy(25000);
led3=0;
led4=1;
huy(25000);
led4=0;
}
for ( i=2; i<=2;i++) //4,5,6,7,8 sang
{
led8=1;
led7=1;
led6=1;
led5=1;
led4=1;
led1=1;
huy(25000);
led1=0;
led2=1;
huy(25000);
led2=0;
led3=1;
huy(25000);
led3=0;
}
for ( i=2; i<=2;i++) //led 3,4,5,6,7,8 sang
{
led8=1;
led7=1;
led6=1;
led5=1;
led3=1;
led1=1;
huy(25000);
led1=0;
led2=1;
huy(25000);
led2=0;
}
for ( i=2; i<=2;i++) //led 2,3,4,5,6,7,8 sang
{
led8=1;
led7=1;
led6=1;
led5=1;
led4=1;
led3=1;
led2=1;
led1=1;
huy(25000);
led1=0;
} // 8 led sang
for ( i=2; i<=2;i++)
{
led8=1;
led7=1;
led6=1;
led5=1;
led4=1;
led3=1;
led2=1;
led1=1;
}
}
}
#include <REGX51.H>
sbit led1 = P3^0;
sbit led2 = P3^1;
sbit led3 = P3^2;
sbit led4 = P3^3;
sbit led5 = P3^4;
sbit led6 = P3^5;
sbit led7 = P3^6;
sbit led8 = P3^7;
void huy ( unsigned long ms )
{
while ( ms--);
}
void main ( void )
{
int i;
{
P3=1;
huy ( 25000);
for ( i=1; i<=7;i++)
{
P3=P3<<1;
huy ( 25000);
}
{
led8=1; //led 8 sang
led1=1;
huy(25000);
led1=0;
led2=1;
huy(25000);
led2=0;
led3=1;
huy(25000);
led3=0;
led4=1;
huy(25000);
led4=0;
led5=1;
huy(25000);
led5=0;
led6=1;
huy(25000);
led6=0;
led7=1;
huy(25000);
led7=0;
}
for ( i=2; i<=2;i++) //led 7,8 sang
{
led8=1;
led7=1;
led1=1;
huy(25000);
led1=0;
led2=1;
huy(25000);
led2=0;
led3=1;
huy(25000);
led3=0;
led4=1;
huy(25000);
led4=0;
led5=1;
huy(25000);
led5=0;
led6=1;
huy(25000);
led6=0;
}
for ( i=2; i<=2;i++) //led 6,7,8 sang
{
led8=1;
led7=1;
led6=1;
led1=1;
huy(25000);
led1=0;
led2=1;
huy(25000);
led2=0;
led3=1;
huy(25000);
led3=0;
led4=1;
huy(25000);
led4=0;
led5=1;
huy(25000);
led5=0;
led6=1;
}
for ( i=2; i<=2;i++) //led 5,6,7,8 sang
{
led8=1;
led7=1;
led6=1;
led5=1;
led1=1;
huy(25000);
led1=0;
led2=1;
huy(25000);
led2=0;
led3=1;
huy(25000);
led3=0;
led4=1;
huy(25000);
led4=0;
}
for ( i=2; i<=2;i++) //4,5,6,7,8 sang
{
led8=1;
led7=1;
led6=1;
led5=1;
led4=1;
led1=1;
huy(25000);
led1=0;
led2=1;
huy(25000);
led2=0;
led3=1;
huy(25000);
led3=0;
}
for ( i=2; i<=2;i++) //led 3,4,5,6,7,8 sang
{
led8=1;
led7=1;
led6=1;
led5=1;
led3=1;
led1=1;
huy(25000);
led1=0;
led2=1;
huy(25000);
led2=0;
}
for ( i=2; i<=2;i++) //led 2,3,4,5,6,7,8 sang
{
led8=1;
led7=1;
led6=1;
led5=1;
led4=1;
led3=1;
led2=1;
led1=1;
huy(25000);
led1=0;
} // 8 led sang
for ( i=2; i<=2;i++)
{
led8=1;
led7=1;
led6=1;
led5=1;
led4=1;
led3=1;
led2=1;
led1=1;
}
}
}
Comment