絕對同時不可能,相對同時(相差幾us秒)可以。
#include <reg51.h>
void Delay_ms(unsigned int t)
{
unsigned int i,j;
for(i=t;i>0;i--)
for(j=120;j>0;j--);
}
void main(void)
{
unsigned long temp=0xfffffffe;
while(1)
{
P0=temp;
P1=temp>>8;
P2=temp>>16;
P3=temp>>24;
Delay_ms(1000);
temp=temp<<1|1;
if(temp==0xffffffff)
temp=0xfffffffe;
}
}
|