找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

帖子
查看: 2450|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

keil 5能不能軟件仿真這個交通燈程序,求指點

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:415837 發(fā)表于 2018-10-31 12:20 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include <reg52.h>
#define uchar unsigned char
#define unit unsigned int
        sbit light_R1=P2^0;
        sbit light_G1=P2^1;
        sbit light_Y1=P2^2;
        sbit light_R2=P2^3;
        sbit light_G2=P2^4;
        sbit light_Y2=P2^5;
        sbit D1=P1^0;
        sbit D2=P1^1;
        uchar code tab[10]={~0x3f,~0x06,~0x5b,~0x4f,~0x66,~0x6d,~0x7d,~0x7f,~0x6f};
        uchar T,shi,ge,s,k,kk;
        void main(void)
        {uchar time1=60;
                T=0;k=0;
                kk=0;
                TMOD=0x01;
                TH0=(65536-50000)/256;
                TL0=(65536-50000)%256;
                EA=1;
                ET0=1;
                TR0=1;
                IT0=1;
                EX0=1;
                IT1=1;
                EX1=1;
                shi=3;
                ge=0;
                while(1)
                {
                        if(k==1)
                        {D1=0;
                         D2=0;
                         light_G1=1;
                         light_G2=1;
                         light_R1=1;
                         light_R2=1;
                         light_Y1=0;
                         light_Y2=0;
                                while(k)
                                {
                                        if(kk==1)
                                        {
                                                time1=60;
                                                light_Y1=1;
                                                light_Y2=1;
                                                kk=0;
                                                k=0;
                                        }
                                }
                        }
                        if(time1==60)
                        {
                                light_G1=0;
                                light_R2=0;
                                light_Y2=1;
                                light_R1=1;
                        }
                        D1=1;
                        D2=0;
                        P0=tab[shi];
                        s=50;
                        while(s--);
                        P0=0xff;
                        D1=0;
                        D2=1;
                        P0=tab[ge];
                        s=50;
                        while(s--);
                        P0=0xff;D2=0;
                        if(T==20)
                        {
                                T=0;
                                time1--;
                                if(time1>30)
                                {
                                        shi=(time1-30)/10;
                                        ge=(time1-30)%10;
                                }
                                else
                                {
                                        shi=time1/10;
                                        ge=time1%10;
                                }
                                if((time1-30)==3)
                                {
                                        light_G1=1;
                                        light_Y1=0;
                                        light_R2=0;
                                }
                                else if(time1==30)
                                {
                                        light_Y1=1;
                                        light_R1=0;
                                        light_R2=1;
                                        light_G2=0;
                                }
                                else if(time1==3)
                                {
                                        light_G2=1;
                                        light_Y2=0;
                                        light_R1=0;
                                }
                                else if(time1==0)
                                {
                                        time1=60;
                                        shi=3;
                                        ge=0;
                                }
                        }
                }
        }
        void timer0() interrupt 1
        {
                TH0=(65536-50000)/256;
                TL0=(65536-50000)%256;
                T++;
        }
        void interrupt_0() interrupt 0
        {
        k=1;
        }
        void interrupt_1() interrupt 2
        {
                kk=1;
         }

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:89515 發(fā)表于 2018-10-31 15:35 | 只看該作者
keil是程序編譯軟件,不是仿真軟件
回復(fù)

使用道具 舉報

板凳
ID:157238 發(fā)表于 2018-10-31 17:04 | 只看該作者
你可以下載個proteus仿真一下。https://pan.baidu.com/s/1qhC2XEH_ddJG-7YPJokqgA  
這是個proteus7.8的安裝文件。
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表