#include "reg52.h"
typedef unsigned int u16;
typedef unsigned char u8;
***it LSA=P2^2;
***it LSB=P2^3;
***it LSC=P2^4;
***it k2=P3^0;
***it k3=P3^2;
***it k4=P3^3;
u8 code duanxuan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
u8 s1,s2,s3,sum;
u8 MBXS[4];
void delay(u16 i)
{
while(i--);
}
void Timer0Init()
{
TMOD|=0X01;
TH0=0Xd8;
TL0=0Xf0;
ET0=1;
EA=1;
TR0=1;
}
void DigDisplay()
{
u8 i;
for(i=0;i<4;i++)
{
switch(i)
{
case(0)SA=0;LSB=0;LSC=0; break;
case(1)SA=1;LSB=0;LSC=0; break;
case(2)SA=0;LSB=1;LSC=0; break;
case(3)SA=1;LSB=1;LSC=0; break;
}
P0=MBXS
;
delay(100);
P0=0x00;
}
}
void datapros()
{
MBXS[0]=duanxuan[s1/10];
MBXS[1]=duanxuan[s2%10];
MBXS[2]=duanxuan[s2/10];
MBXS[3]=duanxuan[s3%10];
}
void main()
{
Timer0Init();
while(1)
{
datapros();
DigDisplay();
}
}
void Timer0() interrupt 1
{
TH0=0Xd8;
TL0=0Xf0;
s1++;
if(s1>=100)
{
s1=0;
s2++;
if(s2>=100)
{
s2=0;
s3++;
if(s3>=10)
{
s3=0;
}
}
}
}
帮忙看看,谢谢
#include "reg52.h"
typedef unsigned int u16;
typedef unsigned char u8;
***it LSA=P2^2;
***it LSB=P2^3;
***it LSC=P2^4;
***it k2=P3^0;
***it k3=P3^2;
***it k4=P3^3;
u8 code duanxuan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
u8 s1,s2,s3,sum;
u8 MBXS[4];
void delay(u16 i)
{
while(i--);
}
void Timer0Init()
{
TMOD|=0X01;
TH0=0Xd8;
TL0=0Xf0;
ET0=1;
EA=1;
TR0=1;
}
void DigDisplay()
{
u8 i;
for(i=0;i<4;i++)
{
switch(i)
{
case(0)SA=0;LSB=0;LSC=0; break;
case(1)SA=1;LSB=0;LSC=0; break;
case(2)SA=0;LSB=1;LSC=0; break;
case(3)SA=1;LSB=1;LSC=0; break;
}
P0=MBXS;
delay(100);
P0=0x00;
}
}
void datapros()
{
MBXS[0]=duanxuan[s1/10];
MBXS[1]=duanxuan[s2%10];
MBXS[2]=duanxuan[s2/10];
MBXS[3]=duanxuan[s3%10];
}
void main()
{
Timer0Init();
while(1)
{
datapros();
DigDisplay();
}
}
void Timer0() interrupt 1
{
TH0=0Xd8;
TL0=0Xf0;
s1++;
if(s1>=100)
{
s1=0;
s2++;
if(s2>=100)
{
s2=0;
s3++;
if(s3>=10)
{
s3=0;
}
}
}
}
帮忙看看,谢谢
举报