#include<reg52.h>
#define Data_Outport P0
sbit Lotch_Duan=P2^2;
sbit Lotch_Wei=P2^3;
sbit KEY_ADD=P3^3;
sbit KEY_DEC=P3^4;
void delay1(unsigned int t);
void delay2(unsigned int t);
void disply(unsigned char FirstBit,unsigned char Num);
unsigned char code Wei_Ma[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char code Duan_Ma[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char Huan_Chun[8];
void Shi_Jian(void);
void main()
{ unsigned char num=0;
Shi_Jian();
while(1)
{
if(KEY_ADD==0)
{
delay2(10);
if(KEY_ADD==0)
{
while(!KEY_ADD);
if(num<99)
{
num++;
}
}
}
if(KEY_DEC==0)
{
delay2(10);
if(KEY_DEC==0)
{
while(!KEY_DEC);
if(num>0)
{
num--;
}
}
}
Huan_Chun[0]=Duan_Ma[num/10];
Huan_Chun[1]=Duan_Ma[num%10];
}
}
void delay1(unsigned int t)
{
while(--t);
}
void delay2(unsigned int t)
{
while(t--)
{
//大致延时1mS
delay1(245);
delay1(245);
}
}
void disply(unsigned char FirstBit,unsigned char Num)
{
static unsigned char i=0;
Data_Outport=0;
Lotch_Duan=1;
Lotch_Duan=0;
Data_Outport=Huan_Chun[i];
Lotch_Duan=1;
Lotch_Duan=0;
Data_Outport=Wei_Ma[i+FirstBit];
Lotch_Wei=1;
Lotch_Wei=0;
i++;
if(i==Num)
{
i=0;
}
}
void Shi_Jian(void)
{
TMOD |=0x01;
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;
EA=1;
ET0=1;
TR0=1;
}
void Ding_Shi(void)interrupt 1
{
TH0=(65536-2000)/256;
TL0=(65536-2000)%256;
disply(0,8);
}
|