找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2199|回復: 3
收起左側

按鍵檢測

[復制鏈接]
ID:105402 發(fā)表于 2016-2-13 22:42 | 顯示全部樓層 |閱讀模式
#include"reg52.h"
#include"intrins.h"
#define uchar unsigned char
sbit S3=P2^4;
sbit S4=P2^5;
sbit S5=P2^6;
sbit S6=P2^7;
uchar a,b,e=0x01,time;
int num;
uchar code TAB[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar c[3]={0xff,0xff,0xff};
void delayms()
{
for(a=10;a>0;a--)
     for(b=124;b>0;b--);
}
void delayms2()
{
for(a=5;a>0;a--)
     for(b=124;b>0;b--);
}
void anjian()
{
if(S3==0)
    {
     delayms();
     if(S3==0)
        {
         num++;
         num=(num>=1000)?0:num;
         while(!S3);
        }
    }
if(S4==0)
    {
     delayms();
     if(S4==0)
        {
         num=(num==0)?1000:num;
         num--;
         while(!S4);
        }
    }
if(S5==0)
    {
     delayms();
     if(S5==0)
        {
         num=0;
         while(!S5);
        }
    }
if(S6==0)
    {
     delayms();
     if(S6==0)
        {
         TR0=~TR0;
        }
     while(!S6);
    }
c[0]=TAB[num/100];
c[1]=TAB[(num%100)/10];
c[2]=TAB[(num%100)%10];
}
void xianshi()
{
         P0=0xff;
         if(e==8) e=0x01;
         P2=~e;
         P0=c[e/2];
         e=_crol_(e,1);
         delayms2();
}
main()
{
IE=0x8a;
TMOD=0x21;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0 = 0;
TH1=6;
TL1=6;
TR1=1;   
while(1) ;
}
void T0_() interrupt 1
{
TR0=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(++time==20)
    {
     time=0;
     num++;
     num=(num>=1000)?0:num;
    }
c[0]=TAB[num/100];
c[1]=TAB[(num%100)/10];
c[2]=TAB[(num%100)%10];
TR0=1;
}
void T1_() interrupt 3
{
TR1=0;
anjian();
xianshi();
TR1=1;
}




回復

使用道具 舉報

ID:1 發(fā)表于 2016-2-13 22:53 來自觸屏版 | 顯示全部樓層
程序很好適合初學者,有電路圖嗎
回復

使用道具 舉報

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

本版積分規(guī)則

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

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

快速回復 返回頂部 返回列表