找回密码
 立即注册

QQ登录

只需一步,快速开始

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

中断控制的交通灯c代码

[复制链接]
跳转到指定楼层
楼主
ID:151605 发表于 2016-12-2 10:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <reg51.h>
#define INT8U unsigned char
#define INT16U 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;
INT8U Time_Count=0,Flash_Count=0,Operation_Type=1;

void T0_INT() interrupt 1
{
  TH0=(65536-50000)>>8;
  TL0=(65536-50000)&0xff;
  switch(Operation_Type)
  {
   case 1:red_a=1;yellow_a=1;green_a=0;
          red_b=0;yellow_b=1;green_b=1;
                  if(++Time_Count!=100) return;
                  Time_Count=0;
                  Operation_Type=2;
                  break;

        case 2:if(++Time_Count!=8) return;
                   Time_Count=0;
                   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;
                  if(++Time_Count!=100) return;
                  Time_Count=0;
                  Operation_Type=4;
                  break;

   case 4:if(++Time_Count!=8) return;
                   Time_Count=0;
                   yellow_b=!yellow_b;green_b=1;
                   if(++Flash_Count!=10) return;                          
                   Flash_Count=0;
                   Operation_Type=1;
                  
  }
}
void main()
{
  TMOD=0x01;
  IE=0x82;
  red_a=1;red_b=1;
  yellow_a=1;yellow_b=1;
  green_a=1;green_b=1;
  while(1);
}

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

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

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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