欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 950|回復: 1
收起左側

新手求助,AT89C51單片機Proteus仿真交通燈

[復制鏈接]
ID:1138816 發表于 2024-12-11 20:59 | 顯示全部樓層 |閱讀模式
為啥數碼管不能正確顯示啊(代碼借鑒了論壇里的)
9F2F1D058C458BE42DA9236ED9BCCDEE.png

#include <REGX51.H>

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;

unsigned char seg[]={0xC0,0xF9,0xA4,0xB0,0x99,
                           0x92,0x82,0xF8,0x80,0x90};
unsigned char wei[]={0xFE,0xFD};
unsigned int count0=0,timeleft=5,Time_Count=0,
                   Flash_Count=0,Operation_Type=1;

void  inittimer()
{
        TMOD=0x01;
        TH0=(65536-50000)/256;
        TL0=(65536-50000)%256;
        ET0=1;
        EA=1;
        TR0=1;
               
}        

void delay(unsigned int time)
{
        unsigned int i,j;
        
        for(i=0;i<time;i++)
        {
                for(j=0;j<120;j++);
        }
}        

void display(unsigned int time, unsigned char port)
{
    unsigned char tens=time/10;
    unsigned char units=time%10;

    P3 = wei[0];
    if (port==1)
                {
        P1=seg[tens];
    }
                else
                {
        P2=seg[tens];
    }
    delay(1);

    P3 = wei[1];
    if (port==1)
                {
        P1 = seg[units];
    }
                else
                {
        P2 = seg[units];
    }
    delay(1);
}

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

void T0_INT() interrupt 1
{
        TL0=(65536-50000)%256;
        TH0=(65536-50000)/256;
        
        count0++;
  if(count0>=20)
  {
     if (timeleft>0)
     {
        timeleft--;
     }  
     count0=0;
  }
        
        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;
                                display(timeleft,2);
                                Time_Count=0;
                                Operation_Type=2;
                                break;

                case 2:        
        if(++Time_Count!=10)
                                return;   
        Time_Count=0;
                                YELLOW_A=~YELLOW_A;GREEN_A=1;
                                if(++Flash_Count!=10)
                                return;
                                display(timeleft,2);
                                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;
                                display(timeleft,1);
                                Time_Count=0;
                                Operation_Type=4;
                                break;

                case 4:
                                if(++Time_Count!=10)
                                return;     
        Time_Count=0;
        YELLOW_B=~YELLOW_B;GREEN_B=1;
        if(++Flash_Count!=10)
                                return;
                                display(timeleft,1);
        Flash_Count=0;
        Operation_Type=1;
                                break;
        }
}

回復

使用道具 舉報

ID:161164 發表于 2024-12-12 15:34 | 顯示全部樓層
不時顯示了嗎?
有問題請描述問題,預計表現,實際表現,提供代碼,報錯信息
回復

使用道具 舉報

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

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表