|
#include <reg51.h>
#define LED P0
sbit P17=P1^7;
sbit LSA=P2^0;
sbit LSB=P2^1;
sbit LSC=P2^2;
unsigned char code discode[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char disp[]={0x3f,0x3f};
unsigned int n=0,second=0,i=0;
void delay(unsigned int i) //Ñóê±oˉêy
{
unsigned int j;
for(i;i>0;i--)
for(j=110;j>0;j--);
}
void display() //ÏÔê¾oˉêy
{
LED=0;
switch(i) //λѡ
{
case(0):
{
LSA=0;LSB=0;LSC=0;break;
}
case(1):
{
LSA=1;LSB=0;LSC=0;break;
}
}
LED=disp[i]; //¶ÎÑ¡
i++;
if(i>1)
{
i=0;
}
}
void main()
{
TMOD=0x61; //3õê¼»ˉ
IE=0x8B;
IT0=1;
TH1=0xE7;
TL1=0xE7;
TR1=1;
while(1)
display(); //ÎTÏTÑ-»·ÏÔê¾oˉêy
}
void int0() interrupt 0 //ía2¿ÖD¶Ï0
{
n++;
switch (n)
{
case 1: //n=1,¿aÆô¶¨ê±Æ÷0£¬¼Æê±20ms
{
TH0=0xB1;
TL0=0xE0;
TR0=1;
break;
}
case 2: //n=2,1رն¨ê±Æ÷0
{
TR0=0;
break;
}
case 3: //n=3,Çåáã
{
n=0;
LED=0x3f;
break;
}
}
}
void intt0() interrupt 1 //¶¨ê±Æ÷0ÖD¶Ï
{
if(P17==1) //2úéúÖüÆúÎa40msμÄÂö3å
{
P17=0;
}
else
{
P17=1;
}
TH0=0xB1;
TL0=0xE0;
TR0=1;
}
void intt1() interrupt 3 //¶¨ê±Æ÷1ÖD¶Ï
{ second++;
if(second==11)
{
second=0;
}
disp[0]=discode[second%10]; //½«ÏÔê¾′úÂëËíèëÏÔê¾êy×é
disp[1]=discode[second/10];
TH1=0xE7;
TL1=0xE7;
TR1=1;
}
这个是按一次开始计时,再按一次停止,再按一次清零的。但是第三次按并不能清零,显示的数字不变。
|
|