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

QQ登錄

只需一步,快速開始

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

這個(gè)程序,如果想定時(shí)時(shí)間為小時(shí),怎樣時(shí)間到,LED燈滅,調(diào)整時(shí)間按一次加鍵,加5...

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:158886 發(fā)表于 2019-6-22 15:11 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit led=P2^0;
sbit wea=P2^2;
sbit web=P2^3;
sbit wec=P2^4;
sbit fm=P1^5;
sbit sw1=P3^1;
sbit sw2=P3^0;
sbit sw3=P3^2;
sbit sw4=P3^3;
uchar code duma[]={0x3f,0x06,0x5b,0x4f,
                                   0x66,0x6d,0x7d,0x07,
                                   0x7f,0x6f,0x77,0x7c,
                                   0x39,0x5e,0x79,0x71
                                   };
                               
                                 
uchar time ,counter,time_counter;                               
                               
                               
                               
uchar i ;

void delay(uint z);
void delay(uint z)
{
  while (z--);

}
void display(uchar i)
{        uchar shi,ge,qie;
shi=i%100/10;
ge=i%10;
qie=i/100;
P0=0XFF;
wea=0;
web=0;
wec=0;
  P0=duma[ge];
  delay(41);
   P0=0XFF;
wea=1;
web=0;
wec=0;
  P0=duma[shi];
  delay(41);
   P0=0XFF;
wea=0;
web=1;
wec=0;
  P0=duma[qie];
  delay(41);
}

void keypros()
{
        if(sw1==0)
        {
           delay(10);
           if(sw1==0)
           {
                   time_counter++;
               
                  while(!sw1);
           }
        }       
         if(sw2==0)
         {
          delay(10);
          if(sw2==0&&time_counter!=0)
          {
                  time_counter--;
       
                   while(!sw2);
          }
         }
         if(sw3==0)
         {
           delay(10);
           if(sw3==0)
           {
                     TR1=0;
                  led=1;
                  time_counter=0;
                while(!sw3);
               
           }
         
         
         
         }
          if(sw4==0)
          {
           delay(10);
          
           if(sw4==0)
           {
                   TR1=~TR1;
                led=~led;
                while(!sw4);
           }
          
          }
}

void init()
{
  TMOD=0x10;
  TH1=0x4b;
  TL1=0x00;
  TR1=0;



}


void main()
{       

             
                         init();
                        
    while(1)
        {       
        keypros();         
   if(TF1==1)
   { TF1=0;
            TH1=0x4b;
     TL1=0x00;
            counter++;


   }
         if(counter==10)
        {
         counter=0;
         time_counter++;
        }
        if(time_counter==240)

         time_counter=0;
          
         display(time_counter);
          
          
   }
}

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

使用道具 舉報(bào)

沙發(fā)
ID:158886 發(fā)表于 2019-6-22 15:14 | 只看該作者
補(bǔ)充,時(shí)間到燈滅,加鍵,按一次加5分鐘,減鍵一次,減5分鐘,定時(shí)間為小時(shí),顯示為分鐘數(shù)
回復(fù)

使用道具 舉報(bào)

板凳
ID:332444 發(fā)表于 2019-6-22 20:14 | 只看該作者
加5修改: if(sw1==0)time_counter+=5;判斷時(shí)間的時(shí)參數(shù)到指定值那么執(zhí)行LED即可
回復(fù)

使用道具 舉報(bào)

地板
ID:332444 發(fā)表于 2019-6-22 20:18 | 只看該作者
假設(shè)這個(gè)為定時(shí)值判斷 if(time_counter==240){ time_counter=0; led=~led;}那么修改判斷式中的參數(shù)就是你要的小時(shí)值
回復(fù)

使用道具 舉報(bào)

5#
ID:332444 發(fā)表于 2019-6-23 10:33 | 只看該作者
把仿真與程序所有打包發(fā)出來以便修改
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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