初学者对动态显示都是这样做,方法不对。应该用中断。LED器件的帧频要达到60Hz以上,你用1/2扫,所以应达到120Hz以上的频率。我给提个方法,自己去改完。
#include<reg52.h>
#include<intrins.h>
void time0over();
sbit M2=P1^2;/*十位*/
sbit M3=P1^3;/*个位*/
char table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
int k=60,m=0;
unsigned char which=0,counter=0;
bit B1s=0;
void main()
{
TMOD=0x01;
TH0=0x ;
TL0=0x ;/*5ms*/
TR0=1;
ET0=1; EA=1;
while(1)
{
if(B1s)
{
B1s=0;
k--;
if(k==-1)k=60;
}
}
}
void T0_service interrupt 1
{
TH0=0x ;
TL0=0x ;/*5ms*/
counter++;
if (counter==200)
{
counter=0; B1s=1;
}
switch(which)
{
case 0:
P0=table[k/10]; /*十位*/
M3=1;M2=0; /*个位关*/
M3=0;M2=0; /*个位开*/
break;
case 1:
P0=table[k%10]; /*个位*/
M2=1;M3=0; /*十位关*/
M2=0;M3=0; /*十位开*/
break;
}
which++;
if (which==2) which=0;
}
|