mọi người chỉ giáo hộ sao đoạn code này cảng P0 không sá #include<reg51.h>
unsigned int i,j;
void delay(unsigned int ms)
{
unsigned int a;
unsigned char b;
for(a=0;a<ms;a++)
{
for(b=0;b<125;b++)
{
}
}
}
void hu1(void)
{
P0=P1=P2=P3=0xff;
delay(300);
P0=P1=P2=P3=0x00;
delay(300);
}
void hu2(void)
{
unsigned char M[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};
unsigned char N[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
P0=P1=P2=P3=0x00;
for(i=0;i<8;i++)
{
P0=M[i];
delay(300);
}
for(i=0;i<8;i++)
{
P2=N[i];
delay(300);
}for(i=0;i<8;i++)
{
P3=N[i];
delay(300);
}for(i=0;i<8;i++)
{
P1=N[i];
delay(300);
}
}
void hu3(void)//sang day 2 ben
{
unsigned char M[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00} ;
unsigned char N[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00};
for(i=0;i<8;i++)
{
P1=P0=M[i];
delay(300);
}
for(i=0;i<8;i++)
{
P3=M[i];
delay(100);
P2=N[i];
delay(100);
}
for(i=0;i<8;i++)
{
P3=M[7-i];
delay(100);
P2=N[7-i];
delay(100);
}
P3=P2=0xff;
for(i=0;i<8;i++)
{
P1=P0=M[7-i];
delay(100);
}
}
main()
{
while(1)
{
hu1(); delay(1000);
hu2(); delay(1000);
hu3(); delay(1000);
}
}
ng
unsigned int i,j;
void delay(unsigned int ms)
{
unsigned int a;
unsigned char b;
for(a=0;a<ms;a++)
{
for(b=0;b<125;b++)
{
}
}
}
void hu1(void)
{
P0=P1=P2=P3=0xff;
delay(300);
P0=P1=P2=P3=0x00;
delay(300);
}
void hu2(void)
{
unsigned char M[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};
unsigned char N[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
P0=P1=P2=P3=0x00;
for(i=0;i<8;i++)
{
P0=M[i];
delay(300);
}
for(i=0;i<8;i++)
{
P2=N[i];
delay(300);
}for(i=0;i<8;i++)
{
P3=N[i];
delay(300);
}for(i=0;i<8;i++)
{
P1=N[i];
delay(300);
}
}
void hu3(void)//sang day 2 ben
{
unsigned char M[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00} ;
unsigned char N[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00};
for(i=0;i<8;i++)
{
P1=P0=M[i];
delay(300);
}
for(i=0;i<8;i++)
{
P3=M[i];
delay(100);
P2=N[i];
delay(100);
}
for(i=0;i<8;i++)
{
P3=M[7-i];
delay(100);
P2=N[7-i];
delay(100);
}
P3=P2=0xff;
for(i=0;i<8;i++)
{
P1=P0=M[7-i];
delay(100);
}
}
main()
{
while(1)
{
hu1(); delay(1000);
hu2(); delay(1000);
hu3(); delay(1000);
}
}
ng
Comment