#include
#include
#define uint8 unsigned char
#define uint16 unsigned int
#define PosPort P1 //位选
#define SegPort P0 //段选
***it key1=P2^0;
void Delayms (uint16 ms);
void Display();
uint8 code Segment[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uint16 qian,bai,shi,ge;
uint16 num=0;
uint8 flag,i;
void key(void);
void Init(void);
void main()
{
Init();
while(1)
{
key();
if(!flag)
num++;
if(num==10000)
num=0;
qian=num/1000;
bai=num%1000/100;
shi=num%100/10;
ge=num%10;
for(i=5;i>0;i--)
{
Display();
}
}
}
/******************************************
延时函数
********************************************/
void Delayms(uint16 ms)
{
uint16 i,j;
for(i=ms;i>0;i--)
for(j=100;j>0;j--);
}
void Init(void)
{
EA=1; //开启总中断
EX1=1; //打开外部中断
IT1=1; //外部中断1触发方式选择位
PX1=1;
}
/************************************************
显示函数
************************************************/
void Display()
{
uint8 temp;
temp=0x7f;
PosPort=temp;
SegPort=Segment[qian];
Delayms(1);
temp=_cror_(temp,1);
PosPort=temp;
SegPort=Segment[bai];
Delayms(1);
temp=_cror_(temp,1);
PosPort=temp;
SegPort=Segment[shi];
Delayms(1);
temp=_cror_(temp,1);
PosPort=temp;
SegPort=Segment[ge];
Delayms(1);
}
void timer1_isr(void) interrupt 2
{
Delayms(5);
flag=~flag;
}
void key(void)
{
if(key1==0)
Delayms(10);
if(key1==0)
while(!key1)
{
num=0;
}
}
|