找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2263|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

請哪位老師幫我指點一下程序,

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:77608 發(fā)表于 2015-8-16 10:39 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
我用595數(shù)碼管做了顯示程序,總是不正常,哪位老師能幫我指點一上程序好下:
#include<reg52.h>
unsigned int date;   
unsigned char n0,n1,n2,n3,n4,n5,n7,s,sec;
unsigned char step1; unsigned  int num,t0,start;
unsigned char step2,step3,step0,nn,step4,step5;
unsigned char code table[]={0xc0,0xcf,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned char code table[]={0xc0,0xcf,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90sbit x1=P0^1;
sbit x2=P0^2;
sbit x3=P0^3;
sbit x4=P0^4;
sbit x5=P0^5;
sbit x6=P0^6;
sbit x7=P0^7;
sbit x0=P0^0;
sbit y0=P1^3;
sbit out1=P1^1;
sbit out2=P1^2;
sbit LOAD=P2^7;
sbit SCLK=P2^6;         //時鐘
sbit SDK=P2^5;           //數(shù)據(jù)
void display();
void hc595(unsigned char word);
void main ()
{     t0=123;
      date=5;
          display();
     TMOD=0x01;                          
     TH0=0x3c;  
     TL0=0xb0;
     EA=1;
     TR0=1;
     ET0=1;
         step0=1;
         
         while(1)
         {P0=0xff;
         if(x0==0)
         {for(nn=0;nn>1000;nn++);
          if(x0==0)
          n0=1;
          }
          else n0=0;
         if(x1==0)
         {for(nn=0;nn>1000;nn++);
          if(x1==0)
          n1=1;
          else n1=0;}
          
         if(x2==0)
         {for(nn=0;nn>1000;nn++);
          if(x2==0)
           n2=1;
          else n2=0;
           }
           if(x3==0)
         {for(nn=0;nn>1000;nn++);
          if(x3==0)
                n3=1;   
        }
                else
                n3=0;
        if(x4==0)
         {for(nn=0;nn>1000;nn++);
          if(x4==0)
             n4=1;}
                else n4=0;
        if(x7==0)
         {for(nn=0;nn>1000;nn++);
          if(x7==0)
          n7=1;
          else n7=0;}
          if (step0==1)
{ display();
                }
          if(((step0&n0)|step1)&!n7)//起動時
          {step1=1;step0=0;y0=0;sec=0;}
          else step1=0;
          if (((step1&n1)|step2)&!step5) //下到位
               {step2=1;step1=0;   //橫進
                     out1=0;
                         y0=1;}
                if(((step2&&n2)|step3)&&!step4)         //橫進到位       
          {step3=1;
                    if(date==0)
                            y0=1;
                            else
                                y0=0;
                     if(date<num)
                        date++;
                                else
                                {y0=1;
                                 out1=1;
                                 step5=1;
                                 }
                         if(step5&!n5==1)
                          {out2=1;
                           if(n5==1)
                            {out2=0;
                                 step0=1;
                                 }
                           }
          }

    if((step3|step4)&n0&step1)
     { step4=1;
     if(n5==1)
      out1=0;
           }
      }
         }
void timer() interrupt 1
  {TH0=0x3c;
  TL0=0xb0;
  s++;
  if(s>1)
   {s=0;
   if(step1==1)
    {sec++;
      display();
    if(sec>t0)
          {out2=0;
          sec=0; }
            }
        if((n3==1)&&(t0<999) )
                 { t0++;
              }
        if((t0>1)&(n4==1))
         {t0--;
             }
      display();
          }
         }


       
  //*串行輸出一個字節(jié)子函數(shù)
void hc595(unsigned char out_data)
  {unsigned char i,temp;
        for(i=0;i<8;i++)
          {   SCLK=0;        // //先拉低,為后面的上升沿做準備
             temp=out_data&0x80;//按位與
             if(temp==0x80)     //如果數(shù)據(jù)等于080
        SDK=1;           //SDK高電平
        else SDK=0;       //否則低電平
             out_data=out_data<<1;//數(shù)據(jù)左移一位
             SCLK=1;//CLK高電平
        }
}

//**顯示子函數(shù)**//
void display()
{ LOAD=1;
  LOAD=0;
hc595(table[date]);
hc595(table[t0/100]);
hc595(table[(t0%10)/10]);
hc595(table[t0%100]);
LOAD=1;          
;
LOAD=0;
}

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩

相關(guān)帖子

回復(fù)

使用道具 舉報

沙發(fā)
ID:88438 發(fā)表于 2015-8-16 18:42 | 只看該作者
你這個程序做的有點小問題
回復(fù)

使用道具 舉報

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

本版積分規(guī)則

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

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

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