Home > other >  C51 timer implementation water lamp
C51 timer implementation water lamp

Time:10-03

C51 timer implementation water lamp from left to right, from right to left but run through this list of true value will appear garbled, I am a novice, can ask bosses to help see if the problem is 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 []={
XFD 0 xfe, 0, 0 XFB, 0 xf7, 0 xef, 0 XDF, 0 XBF, 0 x7f,
XDF 0 XBF, 0, 0 xef, 0 xf7, 0 XFB, 0 XFD
};

Void main ()
{
Unsigned char CNT.
Unsigned char SEC;
ENLED=0;
ADDR3=1;
ADDR2=1;
ADDR1=1;
ADDR0=0;
TMOD=0 x01;
TH0=0 xb8;
TL0=0 x00;
TR0=1;
While (1)
{
If (TF0==1)
{
TF0=0;
TH0=0 xb8;
TL0=0 x00;
Cnt++;
If (cnt>=50)
{
CNT=0;
P0=LedChar (SEC),
Sec++;
If (sec>
=15){
The SEC=0;
}
}
}
}
}

CodePudding user response:

Array LedChar [] defines only 14 elements, namely LedChar [0] ~ LedChar [13], when judging conditions is sec>=15, there are two value was not obtained from the array LedChar, so will be garbled words, this is the C language array defines the basic knowledge, suggested that the building Lord, learning how to learn C language more

CodePudding user response:

Upstairs, positive solutions to
 if (sec>=sizeof (LedChar)) 

CodePudding user response:

The
reference 1/f, a tree may reply:
array LedChar [] defines only 14 elements, namely LedChar [0] ~ LedChar [13], when judging conditions is sec>=15, there are two value was not obtained from the array LedChar, so will be garbled words, this is the C language array defines the basic knowledge, suggested that the building Lord, learning how to learn C language more

Sorry, correct once, in the judgment condition is sec>=15, there should be a value not obtained from the array LedChar,

CodePudding user response:

Change & gt;=14, just a matter of
  • Related