#include <reg52.h>
#define Dataport P1
sbit Latch_seg = P2^2;
sbit Latch_bit = P2^3;
unsigned char DuanMa[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char WeiMa[] ={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char TempData[8];
unsigned char num ;
void Display(unsigned char FirstBit,unsigned char Num);
void delay(unsigned int t) ;
void display(unsigned char Firstbit,unsigned char num)//firstbit表示从第几个段开始,num表示位数
{
unsigned char i;
for (i=0;i<num;i++)
{
Dataport = 0;//清空数据,防止交替重影
Latch_seg = 1;
Latch_seg = 0;
Dataport = WeiMa[i+Firstbit];
Latch_bit = 1;
Latch_bit= 0;
Dataport = TempData[i];
Latch_seg = 1;
Latch_seg = 0;
delay(100);
}
}
void exit0_isr(void) interrupt 0
{
EX0 = 0;
num++;
if(num == 100)
num = 0;
EX0 = 1;
}
void exit1_isr(void) interrupt 2
{
EX1 = 0;
num--;
if(num == 255)
num = 99;
EX1 = 1;
}
void delay(unsigned int t)
{
while(t--);
}
void main(void)
{
EA = 1;
EX0 = 1;//外部中断
IT0 = 1;//边沿触发
EX1 = 1;
IT1 = 1;
while(1)
{
TempData[0] = DuanMa[num/10];
TempData[1] = DuanMa[num%10];
Display(6,2);
}
}
#define Dataport P1
sbit Latch_seg = P2^2;
sbit Latch_bit = P2^3;
unsigned char DuanMa[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char WeiMa[] ={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char TempData[8];
unsigned char num ;
void Display(unsigned char FirstBit,unsigned char Num);
void delay(unsigned int t) ;
void display(unsigned char Firstbit,unsigned char num)//firstbit表示从第几个段开始,num表示位数
{
unsigned char i;
for (i=0;i<num;i++)
{
Dataport = 0;//清空数据,防止交替重影
Latch_seg = 1;
Latch_seg = 0;
Dataport = WeiMa[i+Firstbit];
Latch_bit = 1;
Latch_bit= 0;
Dataport = TempData[i];
Latch_seg = 1;
Latch_seg = 0;
delay(100);
}
}
void exit0_isr(void) interrupt 0
{
EX0 = 0;
num++;
if(num == 100)
num = 0;
EX0 = 1;
}
void exit1_isr(void) interrupt 2
{
EX1 = 0;
num--;
if(num == 255)
num = 99;
EX1 = 1;
}
void delay(unsigned int t)
{
while(t--);
}
void main(void)
{
EA = 1;
EX0 = 1;//外部中断
IT0 = 1;//边沿触发
EX1 = 1;
IT1 = 1;
while(1)
{
TempData[0] = DuanMa[num/10];
TempData[1] = DuanMa[num%10];
Display(6,2);
}
}