时钟带调节


#include<reg51.h>

#define uchar unsigned char

#define dula P0        //??????????
#define wela P2        //??????????,?????P2.4-P2.7

sbit k4 = P3^6;//????k4
sbit k3 = P3^5;
sbit k5 = P3^7;//????k5
sbit beep = P2^3;//???

bit stop = 1;
unsigned char j,k,num0,num1,num2,num3,sec,min,count=0;
unsigned char time_count;
unsigned char code weitable[]={0x8f,0x4f,0x2f,0x1f};
//????????
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
                        0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//????????(????)
unsigned char code table1[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,
                        0x87,0xff,0xef};
void delay(unsigned char i)
{
  for(j=i;j>0;j--)
    for(k=125;k>0;k--);
}


void display(unsigned char h,unsigned char s)
{                          //????4???,???????????
   unsigned int j;
     P0=table[s%10];  //????????P1?
     P2=0x8F;     //???1000 0000??P2?
     for(j=0;j<100;j++); //????????
     P2=0x0F;     //???????,???????
    
P0=table[s/10];  //????????P1?
     P2=0x4F;     //???0100 0000??P2?
     for(j=0;j<100;j++); //????????
     P2=0x0F;     //???????,???????
    
     P0=table[h%10];  //????????P1?
     P2=0x2F;     //???0100 0000??P2?
     for(j=0;j<100;j++); //????????
     P2=0x0F;     //???????,???????
    
     P0=table[h/10];  //????????P1?
     P2=0x1F;     //???0100 0000??P2?
     for(j=0;j<100;j++); //????????
     P2=0x0F;     //???????,???????
     
     
}

void start_timer()
{
       ET0=1;             //????0??
    EA=1;             //????
    TR0=1;             //?????
}

void stop_timer()
{
       ET0=0;             //????0??
    EA=0;             //????
    TR0=0;             //?????
}

void tiaojie()
{  
  if(k3==0)        //?????????
                  
   {
    display(min,sec);   
if(k3==0) //????,???INC_h:??????23, 
 {  //????0;?????1
 if(min==23) min=0;
 else min++;  
    while(!k3)display(min,sec);} //???????(??????,????)
   }

     }

void main()
{
    TMOD=0x01;         //????,00000001,?????????0,?????1(M1=0,M0=1)?
    TH0=(65536-50000)/256;// ?????11.0592,???????46080,?????50000?????????
    TL0=(65536-50000)%256;//46080???,?50000*11.0592/12
    while(1)
    {
        if(k4 == 0)//????????????
        {
            delay(10);//??10ms ??
            if(k4 == 0)//???????????
            {
                while(k4 == 0);//????????
                {
                    if(stop)
                        start_timer();             //?????
                    else    
                        stop_timer();             //?????
                    stop = ~stop;
                    beep = 1;
                    P1 = 0xff;
                }
            }
        }
        else if(k5 == 0)//????????????
        {
            delay(10);//??10ms ??
            if(k5 == 0)//???????????
            {
                while(k5 == 0);//????????
                {    
                    stop_timer();             //?????
                    stop = 1;
                    beep = 1;
                    P1 = 0xff;
                    count = 0;
                    time_count = 0;
                    sec = 0;              //????
                    min = 0;
                }
            }
        }

        if(stop)
        {
            count++;
            if(count == 100)
            {
                P1 = ~P1;
                count = 0;
            }
        }
        else if(time_count==20)//??20?0.05????
        {
            count = 0;
            time_count=0;
            sec++;
            if(sec==60)
            {
                sec=0;       //???60s,???
                min++;
            }
            if(min==60)
            {
                min=0;       //???60min,???
            }
            beep = 1;
            delay(10);
            beep = 1;
        }

        display(min,sec);      
      tiaojie();
    }
}

void timer0() interrupt 1
{
    TH0=(65536-50000)/256;
    TL0=(65536-50000)%256;
    time_count++;
}

  • 8
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值