51模擬交通燈實(shí)驗(yàn)
#include51.h>
/*************延時(shí)子程序*******************************/
void delay(unsigned int x)//最小1毫秒
{
unsigned char j;
while(x--)
{
for(j=0;j<125;j++)
{;}
}
}
void main(void)
{
unsigned char i;
do
{
P0_0=1;
P0_1=1;
P0_2=0;
P0_3=0;
P0_4=1;
P0_5=1;
delay(1000);
for(i=0;i<5;i++)
{
P0_0=1;
P0_1=0;
P0_2=1;
P0_3=0;
P0_4=1;
P0_5=1;
delay(100);
P0_0=1;
P0_1=1;
P0_2=1;
P0_3=0;
P0_4=1;
P0_5=1;;
delay(100);
}
P0_0=0;
P0_1=1;
P0_2=1;
P0_3=1;
P0_4=1;
P0_5=0;
delay(1000);
for(i=0;i<5;i++)
{
P0_0=0;
P0_1=1;
P0_2=1;
P0_3=1;
P0_4=0;
P0_5=1;
delay(100);
P0_0=0;
P0_1=1;
P0_2=1;
P0_3=1;
P0_4=1;
P0_5=1;
delay(100);
}
}
while(1);
}
仿真電路
評(píng)論