Home > other >  MCU button control digital tube display, and code
MCU button control digital tube display, and code

Time:09-27

Button control digital tube display
Requirements:
1. Map simulation, contains four buttons and a four digital tube, (20 points)
2. Press the button 1 numerical add 1, digital tube display (20 points)
3. Key numerical minus 1, 2 press the digital tube display (20 points)
4. Qing 0 keys 3 press the digital tube display, (20 points)
5. Digital tube automatic start/pause button 4 press the add 1, (20 points)

CodePudding user response:

C currency reward?

CodePudding user response:

This code should be easy to find right

CodePudding user response:

In the process of proteus mode digital tube display abnormal, after more than 9 May be related to computer refresh rate, so the program is feasible also need actual inspection, no time to get these two days, have time, I'm verify the novice if there is wrong place please teach

#include
# define uchar unsigned char
# define uint unsigned int
Uchar led []={x5b x3f 0, 0 x06, 0, 0 x4f, 0 x66, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f};//digital tube display 0-9
Uchar flag, temp;//tag
Uint index;
Void delay (uint t) {//delay function
Uint n;
While (t -) {
For (n=0; N<6245; N++);
}
}
Void show (uint m) {//digital tube display function, according to different digits
If (index<10) {//when m<10, show only a
P3=0 xf7;
The P2=led [m];
} else if (m>=10 & amp; & m<100) {//when m>=19 and mP3=0 xf7;
The P2=led [m] % 10;
P3=0 XFB;
The P2=[10] m/led;
} else if (m & gt;=100 & amp; & M & lt; 1000) {//when m>=100 and mP3=0 xf7;
The P2=led [m] % 10;
P3=0 XFB;
The P2=led [m] % 100/10;
P3=0 XFD;
The P2=led [m/100];
} else if (m & gt; 1000 & amp; & m<10000) {//when m>=1000 and mP3=0 xf7;
The P2=led [m] % 10;
P3=0 XFB;
The P2=led [m] % 100/10;
P3=0 XFD;
The P2=led [m] % 1000/100;
P3=0 xfe;
The P2=led [m/1000];
}
}
Void main () {
P3=0 xf7;
The P2=led [0];
While (1) {
If (P1!=0 XFF) {//when any four key press, the following judgment
If (P1==0 xfe & amp; & Flag==0) {//the first button press, the index value + 1
flag=1;
Index++;
If (index & lt; 0 | | index & gt; 9999) {index=0; }//the index's upper limit and lower limit
}
If (P1==0 XFD & amp; & Flag==0) {//the second button press, the index value - 1
flag=1;
The index -;
If (index & lt; 0 | | index & gt; 9999) {index=0; }
}
If (P1==0 XFB & amp; & Flag==0) {//the third button press, the index value=0
The index=0;
}
If (P1==0 xf7 & amp; & Flag==0 & amp; & Temp==0) {//fourth button press for the first time, the temp tag changes, at the same time the index on the + 1
flag=1;
Temp=1;
While (1) {//index cycle on the + 1
Delay (5);
Index++;
If (index & lt; 0 | | index & gt; 9999) {index=0; }
Show (index);//show
If (P1!=0 XFF) {//in the process of the index since the increase if there is a button is pressed the end on the
break;
}
}
}
If (P1==0 xf7 & amp; & Flag==0 & amp; & Temp==1) {//with the upper, but the index since the increase into the decrement
flag=1;
Temp=0;
While (1) {
Delay (5);
The index -;
If (index & lt; 0 | | index & gt; 9999) {index=0; }
Show (index);
If (P1!=0 XFF) {
break;
}
}
}
} else {
Flag=0;
}
Show (index);//show
}
}
  • Related