#include <stc15f2k60s2.h>
#include <intrins.h>
#define LED P2
sbit L1=P4^4;
sbit L2=P4^2;
sbit L3=P4^1;
sbit L4=P3^7;
sbit L5=P3^6;
sbit L6=P3^5;
sbit L7=P3^4;
sbit L8=P3^3;
sbit K1=P5^5;
sbit S1=P4^5;
void Delay10us() //@11.0592MHz
{
unsigned char i;
_nop_();
i = 25;
while (--i);
}
unsigned char code table[]={ 0xC0,
0xF9,
0xA4,
0xB0,
0x99,
0x92,
0x82,
0xF8,
0x80,
0x90};
unsigned char num,sec=10;
void Timer1Init() ////¶¨Ê±Æ÷³õʼ
{
TMOD = 0x01; //ÉèÖö¨Ê±Æ÷ģʽ
TH0 = (65535-10000)/256; //¶¨Ê±Æ÷³õʼֵ
TL0 =(65535-10000)%256; //¶¨Ê±Æ÷³õʼֵ
EA = 1; //´ò¿ª×ÜÖжÏ
ET0 = 1; //´ò¿ª¶¨Ê±Æ÷0
TR0 = 0; //Æô¶¯¶¨Ê±Æ÷0
}
void timer() interrupt 1
{
TH0=(65535-10000)/256;
TL0=(65535-10000)%256;
num++;
if(num==100)
{
sec--;
num=0;
}
}
void key()
{
if(K1==0)
{Delay10us();
TR0=~TR0;
while(!K1);
}
}
void xs()
{
L1=1;L2=L3=L4=L5=L6=L7=L8=0;
LED=table[sec/10];
Delay10us();
LED=0xff;
L2=1;L1=L3=L4=L5=L6=L7=L8=0;
LED=table[sec%10];
Delay10us();
LED=0xff;
}
void sy()
{
if(sec==0)
{
TR0=0;
S1=0;
Delay10us();
S1=1;
Delay10us();
}
}
void main()
{
P4M1=0x00;
P4M0=0xff;
P3M1=0x00;
P3M0=0xff;
Timer1Init();
while(1)
{
key();
xs();
sy();
}
}
|