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

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

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

這個(gè)單片機(jī)程序是按鍵設(shè)置有問題嗎?

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:2724 發(fā)表于 2008-7-26 18:02 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式


 void outkey()                       //P1.4
{
 uchar Second;
   if(out==0)        
   {
  delay(10);
  if(out==0)
  {
   
   while(out==0);
   
  }
  count=0;
  //count_up=0;
  //count_down=0;
  hide_sec=0,hide_min=0,hide_hour=0,hide_day=0,hide_week=0,hide_month=0,hide_year=0;
  Second=Read1302(DS1302_SECOND);
     write1302(0x8e,0x00);    //寫入允許
  write1302(0x80,Second&0x7f);
  write1302(0x8E,0x80);          //禁止寫入
  done=0;          
   }
}

//**************************************************************************
//升序按鍵******************************************************************
//**************************************************************************
void Upkey()         //P1.2
{   
   // static char count_up=0;
    Up=1;
             if(Up==0)
          {
     delay(10);
     if(Up==0)
     {
      
      //count_up=count_up+1;  / tkey按一次,count就加1
      count++;
      P21=~P21;
      done=1;    //進(jìn)入調(diào)整模式
      while(Up==0);
     
     }
     
        switch(count_up)
        {
      case 1:
          P01=~P01;  
                                  temp=Read1302(DS1302_SECOND);  //讀取秒數(shù)
          temp=((temp&0x70)>>4)*10 + (temp&0x0F);
          temp=temp+1;   //秒數(shù)加1
                                  up_flag=1;     //數(shù)據(jù)調(diào)整后更新標(biāo)志
          if((temp)>59)    //超過59秒,清零
                                  {
           temp=0;
          }     
            temp=temp/10*16+temp%10;
          break;
              case 2:
                                  P02=~P02;
          temp=Read1302(DS1302_MINUTE);  //讀取分?jǐn)?shù)
          temp=((temp&0x70)>>4)*10 + (temp&0x0F);
          temp=temp+1;  //分?jǐn)?shù)加1
                                  up_flag=1;
          if(temp>59)          //超過59分,清零
          {
           temp=0;
          }
          temp=temp/10*16+temp%10;
          break;
         case 3:

         case 4:

             
           default:break;
             }
      
     //  while(Up==0);
      }
}


//**********************************************************************
//降序按鍵**************************************************************
//**********************************************************************
void Downkey()        //P1.0
{    
  //static char count_down=0;
  Down=1;
     if(Down==0)
  {
   delay(10);
   if(Down==0)
   {
    //count_down=count_down+1;  / tkey按一次,count就加1
    count++;
   
    done=1;    //進(jìn)入調(diào)整模式
    while(Down==0);
    //P01=~P01;
   }
   switch(count)
   {
    case 1:
                  temp=Read1302(DS1302_SECOND);  //讀取秒數(shù)
      temp=((temp&0x70)>>4)*10 + (temp&0x0F);
      temp=temp-1;          //秒數(shù)減1
                  down_flag=1;       //數(shù)據(jù)調(diào)整后更新標(biāo)志
      if(temp==-1)     //小于0秒,返回59秒
      temp=59;
      temp=temp/10*16+temp%10;
      break;

    case 2:
                        temp=Read1302(DS1302_MINUTE);  //讀取分?jǐn)?shù)
      temp=((temp&0x70)>>4)*10 + (temp&0x0F);
      temp=temp-1;  //分?jǐn)?shù)減1
                        down_flag=1;
      if(temp==-1)
      temp=59;      //小于0秒,返回59秒
      temp=temp/10*16+temp%10;
      break;

 

    case 3:

    case 4:
    
    case 5:

   
         default:break;
   }

 

     
     //  while(Down==0);
  }
}

void show_time()   //數(shù)碼管顯示程序
{
//  DS1302_GetTime(&CurrentTime);  //獲取時(shí)鐘芯片的時(shí)間數(shù)據(jù)
//  Print(CurrentTime.TimeString); //顯示時(shí)間
//  GotoXY(0,0);
 // Print(CurrentTime.DateString); //顯示日期
 // GotoXY(15,0);
 // Print(week_value);             //顯示星期
 // GotoXY(11,0);
 // Print("Week"); //在液晶上顯示 字母 week
  delay(400);                 //掃描延時(shí)
}

 

//****************************************************
//**************模式選擇按鍵**************************
//****************************************************
void Setkey()
{
  Set=1;
  if(Set==0)     //P1.1
     {
           delay(10);
     if(Set==0)
           { //static char count=0;
    count=count+1;  / tkey按一次,count就加1
    P13=~P13;
    P20=~P20;
    done=1;    //進(jìn)入調(diào)整模式
    while(Set==0);
   }
   }
 

//*****************************************************
//**************按鍵功能執(zhí)行***************************
//*****************************************************
void keydone()
{        uchar Second;
  /* if(flag==0)    //關(guān)閉時(shí)鐘,停止計(jì)時(shí)
         { Write1302(0x8e,0x00); //寫入允許
           temp=Read1302(0x80);
           Write1302(0x80,temp|0x80);
        Write1302(0x8e,0x80); //禁止寫入
           flag=1;
         }*/
         Setkey();                //掃描模式切換按鍵
   switch(count)
   {
  
   case 1:do             //count=1,調(diào)整秒
            {
                  
                   outkey();      //掃描跳出按鈕
       Upkey();                //掃描加按鈕
       Downkey();              //掃描減按鈕
       if(up_flag==1||down_flag==1)  //數(shù)據(jù)更新,重新寫入新的數(shù)據(jù)
       {
         write1302(0x8e,0x00); //寫入允許
         write1302(0x80,temp); //寫入新的秒數(shù)
         write1302(0x8e,0x80); //禁止寫入
         up_flag=0;
         down_flag=0;
      }
                     if(Down!=0&&Up!=0)
                     {
      hide_sec++;
            if(hide_sec>3)
            hide_sec=0;
                     }
      else hide_sec=0;
      show_time();         //顯示數(shù)據(jù)
      }while(count==2);break; 
    case 2:do             //count=2,調(diào)整分
            { P22=~P22;
        hide_sec=0;
        outkey();
        Upkey();
        Downkey();
       if(temp>0x60)
         temp=0;
       if(up_flag==1||down_flag==1)
       {
         write1302(0x8e,0x00); //寫入允許
         write1302(0x82,temp); //寫入新的分?jǐn)?shù)
          write1302(0x8e,0x80); //禁止寫入
          up_flag=0;
          down_flag=0;
      }
                     if(Down!=0&&Up!=0)
                     {
        hide_min++;
            if(hide_min>3)
            hide_min=0;
                     }
      else hide_min=0;
      show_time();
      }while(count==3);break;
  
    case 8: count=0;hide_year=0;  //count8, 跳出調(diào)整模式,返回默認(rèn)顯示狀態(tài)
               Second=Read1302(DS1302_SECOND);
                  write1302(0x8e,0x00); //寫入允許
               write1302(0x80,Second&0x7f);
               write1302(0x8E,0x80);          //禁止寫入
      done=0;
    break; //count=7,開啟中斷,標(biāo)志位置0并退出
    default:break;

   }

}
 void main(void)
{
 flag=1;            //時(shí)鐘停止標(biāo)志
 P2=0x00;    //消隱
// P1=0xff;
 up_flag=0;   //數(shù)據(jù)是否更新標(biāo)志
 down_flag=0;  //數(shù)據(jù)是否更新標(biāo)志
 Initial_inti_time();  //中斷初始化
 Initial_DS1302();   //時(shí)鐘芯片DS_1302初始化
 while(1)
 {  
       // while(done==0)           
 // while(done==1)
          keydone();     //進(jìn)入調(diào)整模式
      { 
            show_time();    //數(shù)碼管顯示數(shù)據(jù)
            flag=0;                 
        Setkey();  //掃描各功能鍵
   }
 }
}

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

使用道具 舉報(bào)

無效樓層,該帖已經(jīng)被刪除

本版積分規(guī)則

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

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

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