Home > other >  (novice for help! 51 single chip microcomputer
(novice for help! 51 single chip microcomputer

Time:09-28

The following this code program execution to break after is how to continue? How to ensure that each statement is executed in the switch 1 ms, answer, thank you!


#include

Sbit ADDR0 P1=^ 0;
P1 sbit ADDR1=^ 1;
Sbit ADDR2=p ^ 2;
Sbit ADDR3 P1=^ 3;
Sbit ENLED=P1 ^ 4;

Unsigned char code LedChar []={
Xa4 xc0 0, 0 xf9, 0, 0, xb0 x99 0, 0 x92, 0 x82, 0 xf8,
X90 0 x80, 0, 0 x88, 0 x83, 0 xc6, xa1 0, 0 x86, 0 x8e
};

Unsigned char LedBuff []={
0 XFF, 0 XFF, 0 XFF, 0 XFF, 0 XFF, 0 XFF
};

Void main ()
{
Unsigned int CNT=0;
Unsigned long SEC=0;
Unsigned char I=0;

ENLED=0;
ADDR3=1;
TMOD=0 x01;
XFC TH0=0;
X67 TL0=0;
TR0=1;

While (1)
{
If (TF0==1)
{
TF0=0;
XFC TH0=0;
X67 TL0=0;
cnt++;
If (cnt>
=1000){
CNT=0;
Sec++;
LedBuff [0]=LedChar [10] the SEC %;
LedBuff [1]=LedChar SEC/10% 10;
LedBuff [2]=LedChar SEC/100% 10;
LedBuff [3]=LedChar SEC/1000% 10;
LedBuff [4]=LedChar SEC/10000% 10;
LedBuff [5]=LedChar SEC/100000% 10;
}

The switch (I)
{
Case 0: ADDR2=0; ADDR1=0; ADDR0=0; i++; P0=LedBuff [0]; ENLED=0; break;
Case 1: ADDR2=0; ADDR1=0; ADDR0=1; i++; P0=LedBuff [1]; ENLED=0; break;
Case 2: ADDR2=0; ADDR1=1; ADDR0=0; i++; P0=LedBuff [2]; ENLED=0; break;
Case 3: ADDR2=0; ADDR1=1; ADDR0=1; i++; P0=LedBuff [3]. ENLED=0; break;
Case 4: ADDR2=1; ADDR1=0; ADDR0=0; i++; P0=LedBuff [4]; ENLED=0; break;
Case 5: ADDR2=1; ADDR1=0; ADDR0=1; i=0; P0=LedBuff [5]; ENLED=0; break;
Default: break;
}
}
}
}

CodePudding user response:

Continue to cycle to swith, and then the if (TF0==1); If you set the timer is 1 ms, each time the loop time is 1 ms, natural your original state is to keep the 1 ms

CodePudding user response:

Understand, thank you

CodePudding user response:

Break out of the switch statement, you can now this code to make the switch statement execution in 1 ms, after the 1 ms, TF0 overflow is equal to 1, to get into a case to the next

CodePudding user response:

Jump out of the swith circulation, let each one case is 1 ms word need to delay time delay function

CodePudding user response:

reference 4 floor electric_man response:
swith circulation, let each one case is 1 ms word need to delay function delay

The timer, you don't have to delay function.
  • Related