标题:
交通灯程序
[打印本页]
作者:
charsh
时间:
2015-5-30 15:08
标题:
交通灯程序
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit RED_A=P0^0;
sbit YELLOW_A=P0^1;
sbit GREEN_A=P0^2;
sbit RED_B=P0^3;
sbit YELLOW_B=P0^4;
sbit GREEN_B=P0^5;
uchar Flash_Count=0,Operation_Type=1;
void DelayMs(uint x)
{
uchar i;
while(x--)for(i=0;i<120;i++);
}
void Traffic_Light()
{
switch(Operation_Type)
{
case 1:RED_A=1;YELLOW_A=1;GREEN_A=0;
RED_B=0;YELLOW_B=1;GREEN_B=1;
DelayMs(2000);
Operation_Type=2;
break;
case 2:DelayMs(300);
YELLOW_A=~YELLOW_A;GREEN_A=1;
if(++Flash_Count!=10)return;
Flash_Count=0;
Operation_Type=3;
break;
case 3:RED_A=0;YELLOW_A=1;GREEN_A=1;
RED_B=1;YELLOW_B=1;GREEN_B=0;
DelayMs(2000);
Operation_Type=4;
break;
case 4:DelayMs(300);
YELLOW_B=~YELLOW_B;GREEN_B=1;
if(++Flash_Count!=10)return;
Flash_Count=0;
Operation_Type=1;
}
}
void main()
{
while(1)Traffic_Light();
}
下载地址(根据大家的反馈 注释和仿真已经补上):
http://www.51hei.com/bbs/dpj-77262-1.html
作者:
西边无法
时间:
2015-10-7 09:13
没有文字说明,没有程序注解,不完美呦。建议楼主添加上呦。
作者:
woin7
时间:
2016-4-7 10:02
要是有个电路图就好了
作者:
molubumo
时间:
2016-4-8 10:33
用了6管脚太麻烦了,可以用3管脚的
作者:
默默默默
时间:
2016-4-9 15:55
由仿真图或者注释就好了。
作者:
17863201837
时间:
2016-12-28 22:00
缺点其他的东西
作者:
rock5442107
时间:
2016-12-28 22:59
由仿真图或者注释就好了。
作者:
qm123456
时间:
2017-3-17 22:58
很赞,有仿真吗
作者:
qm123456
时间:
2017-3-17 22:58
有仿真吗
作者:
1102396223
时间:
2017-6-15 21:51
感谢楼主,刚好找这样程序
作者:
nliang
时间:
2017-6-16 20:50
先看看
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1