#include<reg51.h>
#define GPIO_DIG P0
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
unsigned char code DIG_CODE[10]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char DisplayData[1];
void DigDisplay();
unsigned int Time1,K;
void TimerConfiguration()
{
TMOD=0X02;
TH0=0X9C;
TL0=0X9C;
ET0=1;
EA=1;
TR0=1;
}
void main(void)
{
unsigned char i;
for(i=0;i<10;i++)
{
DisplayData[i]=DIG_CODE[i];
}
TimerConfiguration();
while(1)
{
DigDisplay();
}
}
void DigDisplay()
{
unsigned char i;
unsigned int j;
for(i=0;i<8;i++)
{
switch(i)
{
case(0):
LSA=0;LSB=0;LSC=0; break;
case(1):
LSA=1;LSB=0;LSC=0; break;
case(2):
LSA=0;LSB=1;LSC=0; break;
case(3):
LSA=1;LSB=1;LSC=0; break;
case(4):
LSA=0;LSB=0;LSC=1; break;
case(5):
LSA=1;LSB=0;LSC=1; break;
case(6):
LSA=0;LSB=1;LSC=1; break;
case(7):
LSA=1;LSB=1;LSC=1; break;
}
GPIO_DIG=DIG_CODE[K];
j=10;
while(j--);
GPIO_DIG=0x00;
}
}
void Timer() interrupt 1
{
Time1++;
if(Time1>5000){
Time1=0;
++K;
if(K>9) K=0;
}
}
#define GPIO_DIG P0
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
unsigned char code DIG_CODE[10]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char DisplayData[1];
void DigDisplay();
unsigned int Time1,K;
void TimerConfiguration()
{
TMOD=0X02;
TH0=0X9C;
TL0=0X9C;
ET0=1;
EA=1;
TR0=1;
}
void main(void)
{
unsigned char i;
for(i=0;i<10;i++)
{
DisplayData[i]=DIG_CODE[i];
}
TimerConfiguration();
while(1)
{
DigDisplay();
}
}
void DigDisplay()
{
unsigned char i;
unsigned int j;
for(i=0;i<8;i++)
{
switch(i)
{
case(0):
LSA=0;LSB=0;LSC=0; break;
case(1):
LSA=1;LSB=0;LSC=0; break;
case(2):
LSA=0;LSB=1;LSC=0; break;
case(3):
LSA=1;LSB=1;LSC=0; break;
case(4):
LSA=0;LSB=0;LSC=1; break;
case(5):
LSA=1;LSB=0;LSC=1; break;
case(6):
LSA=0;LSB=1;LSC=1; break;
case(7):
LSA=1;LSB=1;LSC=1; break;
}
GPIO_DIG=DIG_CODE[K];
j=10;
while(j--);
GPIO_DIG=0x00;
}
}
void Timer() interrupt 1
{
Time1++;
if(Time1>5000){
Time1=0;
++K;
if(K>9) K=0;
}
}