Home > other >  [for] a laparoscope, usually connected to a switch function and the if function can 51 single-chip m
[for] a laparoscope, usually connected to a switch function and the if function can 51 single-chip m

Time:09-26

在51单片机动态数码管学习过程中,我想做一个扫描显示05201314但是最终结果却没达到预期,求大佬指导下

CodePudding user response:

The source code
#include
Typedef unsigned int under-16;
Typedef unsigned char u8;
Void delay (under-16 I)
{
While (I -);
}
Sbit A=P2 ^ 2;
Sbit lB=P2 ^ 3;
Sbit C=P2 ^ 4;
U8 code led []={x5b x3f 0, 0 x06, 0, 0 x4f, 0 x66, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f, 0 x77, 0 x7c, 0 x39, 0 x5e, 0 x79, 0 x71};

Void digdisplay () {
u8 i;
for(i=0; i<8; I++) {
The switch (I)
{
Case (0) :
A=0; LB=0; C=0; break;
Case (1) :
A=1; LB=0; C=0; break;
Case (2) :
A=0; LB=1; C=0; break;
Case (3) :
A=1; LB=1; C=0; break;
Case (4) :
A=0; LB=0; C=1; break;
Case (5) :
A=1; LB=0; C=1; break;
Case (6) :
A=0; LB=1; C=1; break;
Case (7) :
A=1; LB=1; C=1; break;
}

If (I=0) {P0=led [5];
delay(100);
P0=0 x00;
}
Else if (I=1) {P0=led [2];
delay(100);
P0=0 x00;
}
Else if (I=2) {P0=led [4];
delay(100);
P0=0 x00;
}
Else if (I=3) {P0=led [2];
delay(100);
P0=0 x00;
}
Else if (I=4) {P0=led [1];
delay(100);
P0=0 x00;
}
Else if (I=5) {P0=led [3];
delay(100);
P0=0 x00;
}
Else if (I=6) {P0=led [6];
delay(100);
P0=0 x00;
}
Else if (I=7) {P0=led [1];
delay(100);
P0=0 x00;
}
}
}


Void main ()
{

While (1)
{
Digdisplay ();
}
}

CodePudding user response:

Try to have deleted the else

CodePudding user response:

Can, your program in the switch and if statements are independent, but why don't you will in order to realize the function of both together?

CodePudding user response:

You have a problem if it was not the=====is judgment,=is the assignment

CodePudding user response:

You should have reminded of the compiler

CodePudding user response:

#include Typedef unsigned int under-16; Typedef unsigned char u8; Void delay (under-16 I) {while (I -); } sbit A=P2 ^ 2; Sbit lB=P2 ^ 3; Sbit C=P2 ^ 4; U8 code led []={x5b x3f 0, 0 x06, 0, 0 x4f, 0 x66, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f, 0 x77, 0 x7c, 0 x39, 0 x5e, 0 x79, 0 x71}; Void digdisplay () {u8 I; For (I=8; I> 0; {I -) {switch (I) in case (1) : A=1; LB=0; C=0; break; Case (2) : A=0; LB=1; C=0; break; Case (3) : A=1; LB=1; C=0; break; Case (4) : A=0; LB=0; C=1; break; Case (5) : A=1; LB=0; C=1; break; Case (6) : A=0; LB=1; C=1; break; Case (7) : A=1; LB=1; C=1; break; } the if (I==1) {P0=led [4]; Delay (100000); P0=0 x00; } the if (I==2) {P0=led [1]; Delay (100000); P0=0 x00; {} the if (I==3) P0=led [3]; Delay (100000); P0=0 x00; {} the if (I==4) P0=led [1]; Delay (100000); P0=0 x00; {} the if (I==5) P0=led [0]; Delay (100000); P0=0 x00; {} the if (I==6) P0=led [2]; Delay (100000); P0=0 x00; {} the if (I==7) P0=led [5]; Delay (100000); {}}} void main () while (1) {digdisplay (); }}
  • Related