想通过数组实现倒计时功能,63s 到60s,再到3s倒计时,63到60可以实现,但是60到3不行,跳转一次可以,第二次就不行,结构一样,红绿灯什么的都很精确,怎么解决



 #include <reg51.h>
#include <intrins.h>
unsigned char tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
code unsigned char dxtab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};              //0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
 unsigned char nb[]={6,3,6,0,0,3 };
 unsigned char dx[]={6,0,0,4,6,3 };                                          //636003 ???????
unsigned int time;
unsigned char counts,countss,i,j;
sbit LED_RED=P2^0;
unsigned char LED_RED_S;
sbit LED_YELLOW=P2^1;
unsigned char  LED_YELLOW_S;
sbit LED_GREEN=P2^2;
unsigned char  LED_GREEN_S;
sbit LED_GREEN_ew=P2^5;
unsigned char  LED_GREEN_ew_S;
sbit LED_YELLOW_ew=P2^6;
unsigned char  LED_YELLOW_ew_S;
sbit LED_RED_ew=P2^7;
unsigned char  LED_RED_ew_S;
sbit weixuan1=P2^3;
sbit weixuan2=P2^4; 
sbit weixuan11=P3^0;
sbit weixuan22=P3^1;
sbit test=P1^1;                     //???63s?????3?????60s  //??-??-?????126s ????????126s?????????????63s??????????????123???????????????
//void LED_set0()
//{ LED_RED=0;
//  LED_YELLOW=0;
//  LED_GREEN=0;
//  LED_RED_ew=0;
//  LED_YELLOW_ew=0;
//  LED_GREEN_ew=0;
//      LED_RED=1;
//  LED_YELLOW=0;
//  LED_GREEN=0;
//  LED_RED_ew=1;
//  LED_YELLOW_ew=0;
//  LED_GREEN_ew=0;
//
//}

//void baocun_nanbei()
//{
//  LED_RED_S=LED_RED;
//  LED_YELLOW_S=LED_YELLOW;
//  LED_GREEN_S=LED_GREEN;
//
//
//}
//void baocun_dongxi()
//{
//  LED_RED_ew_S=LED_RED_ew;
//  LED_YELLOW_ew_S=LED_YELLOW_ew;
//  LED_GREEN_ew_S=LED_GREEN_ew;
//}
//void huifu_nanbei()
//{
//  LED_RED=LED_RED_S;
//  LED_YELLOW=LED_YELLOW_S;
//  LED_GREEN=LED_GREEN_S;
//
//}
//void huifu_dongxi()
//{
//  LED_RED_ew=LED_RED_ew_S;
//  LED_YELLOW_ew=LED_YELLOW_ew_S;
//  LED_GREEN_ew=LED_GREEN_ew_S;
//}

void delay(unsigned char n)
{
    unsigned char z;
    for(z=0;z<n;z++)
    _nop_();

}                           //????????????
void reset()
{
LED_YELLOW=0;
        LED_RED_ew=0;
        TR0=0;
        time=0; 
        nb[0]=6;
        nb[1]=3;
        nb[2]=6;
        nb[3]=0;
        nb[4]=0;
        nb[5]=3;
        dx[0]=6;
        dx[1]=0;
        dx[2]=0;
        dx[3]=3;
        dx[4]=6;
        dx[5]=3;
        i=0;
        j=0;
        TR0=1;  
}
void xianshi_dongxi()
{
              weixuan11=1;
              weixuan22=0;           
              P1=dxtab[dx[j]];
              delay(3000);
              weixuan11=0;

              weixuan22=1;          
              P1=dxtab[dx[j+1]];
              delay(2500);
              weixuan11=0;
              weixuan22=0;

}           
void xianshi_nanbei()
{
              weixuan1=1;
              weixuan2=0;            
              P0=tab[nb[i]];
              delay(3000);
              weixuan1=0;
              weixuan2=1;           
              P0=tab[nb[i+1]];
              delay(2500);
              weixuan1=0;
              weixuan2=0;

}           
void changenb()                                        //?????????
{
            if(counts==20)
                    {   
                        if(nb[i+1]!=0)
                        {
                        counts=0;
                        nb[i+1]--;

                        }

                        else  if (nb[i+1]==0)
                        {
                        counts=0;
                        nb[i+1]=9;
                        nb[i]--;

                        }
                    }
}
void changedx()                                        //?????????
{
            if(countss==20)
                    {   
                        if(dx[j+1]!=0)
                        {
                        dx[j+1]--;
                        countss=0;
                        }

                        else  if (dx[j+1]==0)
                        {
                        dx[j+1]=9;
                        dx[j]--;
                        countss=0;
                        }
                    }
}
void main ()
{
    TMOD=0x11;    
    TH0=(65536-50000)/256; 
    TL0=(65536-50000)%256;
    TR0=1;                 //?????t0 50ms
    EA=1;                   //EA?????
    ET0=1;                  //ET0 ?????T0
    EX0=1;
    IT0=1;                 // ????????
    LED_RED=0;
    LED_YELLOW=0;
    LED_GREEN=0;
    LED_RED_ew=0;
    LED_YELLOW_ew=0;
    LED_GREEN_ew=0;             //?????LED
    while (1)                                                                       
{

        changenb();
        xianshi_nanbei();
        changedx();
        xianshi_dongxi();



//////                                                                V2?汾
        if(time<=1260)
    {   
        LED_RED=1;                         //63s???????  
        if(time<=1200)
        LED_GREEN_ew=1;                    //60s???????
                                                                                                //???????????
        else if(time>1200&&time<=1260)          //60-63s??????                                     
        {   

            LED_GREEN_ew=0;
            LED_YELLOW_ew=1;
        }
        }
        else if(time>1260 && time<=2460)                //63-123s ?????  ??????
    {   

        LED_RED=0;
        LED_GREEN=1;
        LED_YELLOW_ew=0;   
        LED_RED_ew=1;

     }        
        else if(time>2460&&time<=2520)
        {   

        LED_GREEN=0;
        LED_YELLOW=1;   
        }
         if(time>2520)
        {
        reset();                         //????????
    }   }       
}

void timer0_int (void)interrupt 1    //1 ???t0
{
    TH0=(65536-50000)/256;
    TL0=(65536-50000)%256;
    time ++;
    counts++;
    countss++;

    if (time==1200) 
        j=+2;
    else if (time==1260) 
    {
        i=+2;
        j=+2;
    }
    else if( time==2460)
        i=+2;
}
//void INT0_E (void) interrupt 0
//{ if(k==1)
//  {
//  TR0=0;
//  INT0=0;
////    baocun_nanbei();
////    baocun_dongxi();
////    LED_set0();
//  LED_RED=1;
//  LED_YELLOW=0;
//  LED_GREEN=0;
//  LED_RED_ew=1;
//  LED_YELLOW_ew=0;
//  LED_GREEN_ew=0;
//  EX0=0;
////    j++;
//  
//  while (1)
//  { 
//   if (INT0==1)
//   {
//      LED_RED=0;
//      LED_YELLOW=0;
//      LED_GREEN=0;
//      LED_RED_ew=0;
//      LED_YELLOW_ew=0;
//      LED_GREEN_ew=0;
//      TR0=1;
//      EX0=1;
//      break;
//          }
//  }
//
//  }
////    else  if(j==2)
////   
////    {   
//////      huifu_dongxi();
//////      huifu_nanbei();
////    LED_RED=0;
////    LED_YELLOW=0;
////    LED_GREEN=0;
////    LED_RED_ew=0;
////    LED_YELLOW_ew=0;
////    LED_GREEN_ew=0;
////        TR0=1;
////        j=1;
////    }
//
//}


https://blog.csdn.net/weixin_34120274/article/details/94263522