开始:按下后从停止处开始
停止:按下后显示变为00
能附带Professional模拟图最好 没有也没关系
是AP89C51的单片机
有一个现成的相关程序,你参考参考
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit key1=P3^4;
sbit key2=P3^5;
sbit key3=P3^6;
sbit key4=P3^7;
uchar code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0xb0,0x8e};
uchar numt0,num;
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display(uchar numdis)
{
uchar shi,ge;
shi=numdis/10;
ge=numdis%10;
P0=table[shi];
P2=0x0b;
delayms(5);
P0=table[ge];
P2=0x07;
delayms(5);
}
void init()
{
TMOD=0x01;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
EA=1;
ET0=1;
}
void keyscan()
{
if(key1==0)
{
delayms(10);
if(key1==0)
{
num++;
if(num==60)
num=0;
while(!key1); //等待按键释放
}
}
if(key2==0)
{
delayms(10);
if(key2==0)
{
if(num==0)
num=60;
num--;
while(!key2) ;
}
}
if(key3==0)
{
delayms(10);
if(key3==0)
{
num=0;
while(!key3);
}
}
if(key4==0)
{
delayms(10);
if(key4==0)
{
while(!key4)
TR0=~TR0;
}
}
}
void main()
{
init();
while(1)
{
keyscan();
display(num);
}
}
void T0_time()interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
numt0++;
if(numt0==20)
{
numt0=0;
num++;
if(num==60)
num=0;
}
}