找回密码
 立即注册

QQ登录

只需一步,快速开始

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

基于51单片机的交通灯程序+Proteus仿真

[复制链接]
跳转到指定楼层
楼主



#include<reg51.h>
unsigned char code a[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit w1=P3^6;
sbit w2=P3^7;
void delay(unsigned int xms);
void light(unsigned int t);
int main()
{          
       
        while(1){
           P1=0x1e;                 
           light(8);         
           P1=0x1f;               
           delay(500);
           P1=0x1e;               
           delay(500);
           P1=0x1f;               
           delay(500);
           P1=0x1e;               
           delay(500);
           P1=0x1f;               
           delay(500);
           P1=0x1e;               
           delay(500);

          
           P1=0x1d;                 
           delay(3000);         
          

          
           P1=0x33;                 
           light(8);
           P1=0x3b;                 
           delay(500);
           P1=0x33;                 
           delay(500);
           P1=0x3b;                 
           delay(500);
           P1=0x33;                 
           delay(500);
           P1=0x3b;                 
           delay(500);
           P1=0x33;               
           delay(500);
          
           P1=0x2b;                 
           delay(3000);
          
        }
        return 0;
}
void delay(unsigned int xms)
{        unsigned int k;
        unsigned char i,j;
        for(k=xms;k>0;k--)
                for(i=0;i<10;i++)
                        for(j=0;j<33;j++);
}
void light(unsigned int t)
{       
        unsigned int j;
        unsigned int x;
        unsigned int y;
        while(t!=-1)
        {
        x=t/10;
        y=t%10;
        for(j=50000;j>0;j--)
         {
          P2=a[x];
          w1=0;w2=1;
          w1=1;w2=1;

          P2=a[y];
          w1=1;w2=0;
          w1=1;w2=1;
         
          }
          t--;
    }
       
}

2019-12-02_101559.png (26.34 KB, 下载次数: 39)

2019-12-02_101559.png

交通灯.zip

19.8 KB, 下载次数: 46, 下载积分: 黑币 -5

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

使用道具 举报

沙发
ID:654032 发表于 2019-12-2 10:22 | 只看该作者
C语言编程哦
回复

使用道具 举报

板凳
ID:659291 发表于 2019-12-9 09:38 | 只看该作者
谢谢分享
回复

使用道具 举报

地板
ID:659549 发表于 2019-12-9 13:48 来自手机 | 只看该作者
谢谢分享
回复

使用道具 举报

5#
ID:659680 发表于 2019-12-21 12:04 | 只看该作者
大佬,怎么让黄灯闪三下的时候,数码管也会显示三秒倒计时嘞
回复

使用道具 举报

6#
ID:822000 发表于 2020-9-22 17:41 | 只看该作者
CFZhi 发表于 2019-12-21 12:04
大佬,怎么让黄灯闪三下的时候,数码管也会显示三秒倒计时嘞

黄灯闪三下,刚好三秒
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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