是你的程序问题,与for无关
给你改好了,试试看
#include<reg52.h>
sbit LA=P2^2;
sbit LB=P2^3;
sbit LC=P2^4;
unsigned char code smguan[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
unsigned char Ledbuf[6]={0x00,0x00,0x00,0x00,0x00,0x00};
unsigned int counter=0;
unsigned char buf[6];
unsigned int stopwatch=12345,ST;
void T1_Timer();
void main(void)
{
unsigned char i=0;
T1_Timer();
while(1)
{
ST=stopwatch;
if(counter>=1000)
{
counter=0;
stopwatch--;
for(i=0;i<6;i++)
{
buf[i]=ST%10;
ST /=10;
}
}
}
}
void T1_Timer()
{
TMOD=0X01;
TH0=0Xfc;
TL0=0X18;
TR0=1;
EA=1;
ET0=1;
}
void Keyscan()
{
static unsigned char j=0;
P0=0X00;
switch(j)
{
case 0: LA=0;LB=0;LC=0;break;
case 1: LA=1;LB=0;LC=0;break;
case 2: LA=0;LB=1;LC=0;break;
case 3: LA=1;LB=1;LC=0;break;
case 4: LA=0;LB=0;LC=1;break;
case 5: LA=1;LB=0;LC=1;break;
case 6: LA=0;LB=1;LC=1;break;
case 7: LA=1;LB=1;LC=1;break;
default:break;
}
P0=smguan[buf[j]];
j++;
if(j==8)j=0;
}
void interrupt_Timter1() interrupt 1
{
TH0=0Xfc;
TL0=0X18;
counter++;
Keyscan();
}
|