找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1048|回复: 0
打印 上一主题 下一主题
收起左侧

普通的交通灯

[复制链接]
跳转到指定楼层
楼主
ID:949622 发表于 2021-7-5 23:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <reg52.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 t;
    while(x--)
    {
        for(t=120;t>0;t--);
    }
}

void Traffic_lignt()
{
    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(200);
            YELLOW_A=~YELLOW_A;
            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(200);
            YELLOW_B=~YELLOW_B;
            if(++Flash_Count !=10)
                return;
            Flash_Count=0;
            Operation_Type = 1;
            break;  
    }
}

void main()
{
    while(1)
    {
        Traffic_lignt();   
    }
}



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表