51模拟交通灯实验
#include51.h>
/*************延时子程序*******************************/
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);
}
仿真电路
![](http://m.amcfsurvey.com/editerupload/fetch/20161101/315522_1_0.jpg)
评论