12个LED的流水灯
#include <reg52.h>
#define uchar unsigned char
sbit P0_0=P0^0;
sbit P0_1=P0^1;
sbit P0_2=P0^2;
sbit P0_3=P0^3;
sbit P0_4=P0^4;
sbit P0_5=P0^5;
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
sbit P1_4=P1^4;
sbit P1_5=P1^5;
void delay1s()
{
uchar i;
for(i=0;i<20;i++)
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
while(!TF0);
TF0=0;
}
}
void delayxs(uchar xt)
{
uchar t;
for(t=0;t<xt;t++)
delay1s();
}
void main()
{
TMOD=0x01;
while(1)
{
uchar i,j,a,b;
a=0xfe;
b=0xdf;
for(j=0;j<3;j++)
{
for(i=0;i<6;i++)
{
P0=a;
P1=b;
a<<=1;
b>>=1;
delayxs(1);
if(a==0xdf)
P0=0xfe;
if(b==0xfe)
P1=0xdf;
}
}
}
}
#include <reg52.h>
#define uchar unsigned char
sbit P0_0=P0^0;
sbit P0_1=P0^1;
sbit P0_2=P0^2;
sbit P0_3=P0^3;
sbit P0_4=P0^4;
sbit P0_5=P0^5;
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
sbit P1_4=P1^4;
sbit P1_5=P1^5;
void delay1s()
{
uchar i;
for(i=0;i<20;i++)
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
while(!TF0);
TF0=0;
}
}
void delayxs(uchar xt)
{
uchar t;
for(t=0;t<xt;t++)
delay1s();
}
void main()
{
TMOD=0x01;
while(1)
{
uchar i,j,a,b;
a=0xfe;
b=0xdf;
for(j=0;j<3;j++)
{
for(i=0;i<6;i++)
{
P0=a;
P1=b;
a<<=1;
b>>=1;
delayxs(1);
if(a==0xdf)
P0=0xfe;
if(b==0xfe)
P1=0xdf;
}
}
}
}
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
#include <reg52.h>
#define uchar unsigned char
sbit P0_0=P0^0;
sbit P0_1=P0^1;
sbit P0_2=P0^2;
sbit P0_3=P0^3;
sbit P0_4=P0^4;
sbit P0_5=P0^5;
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
sbit P1_4=P1^4;
sbit P1_5=P1^5;
void delay1s()
{
uchar i;
for(i=0;i<20;i++)
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
while(!TF0);
TF0=0;
}
}
void delayxs(uchar xt)
{
uchar t;
for(t=0;t<xt;t++)
delay1s();
}
void main()
{
TMOD=0x01;
while(1)
{
uchar i,j,a,b;
a=0xfe;
b=0xdf;
for(j=0;j<3;j++)
{
for(i=0;i<6;i++)
{
P0=a;
P1=b;
a<<=1;
b>>=1;
delayxs(1);
if(a==0xdf)
P0=0xfe;
if(b==0xfe)
P1=0xdf;
}
}
}
}