//Button plus or minus one
#include
#include
int duan[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; //Hexadecimal of the common cathode digital tube 0 to 9
sbit K1 = P1^0;
sbit K2 = P1^7;
char num = 0;
//Delay function with parameters
void delay(unsigned int i){
while(i--);
}
//Main function
void main(void)
{
while(1){
if(K1 == 0){
delay(5000); //key press delay
if(K1 == 0){
num++;
}
}
if(K2 == 0){
delay(5000);
if(K2 == 0){
num --;
}
}
//cycle
if(num > 99){
num = 0;
}
if(num < 0){
num = 99;
}
//Knowledge point: The unit digit of any two-digit number divided by 10 is the tens digit
P3=0x08; //unit display
P0 = ~duan[num%10]; //Only multiples of ten modulo 10 equal 0, so other non-multiples of ten equal themselves plus their units digit
delay(5000);
P3=0x04; //ten digit display
P0= ~duan[num/10%10]; //Any number in the MCU divided by 10 equals its tens digit
delay(6000);
}
}
Previous article:External interrupt 0/1
Next article:Digital tube application digital_pile
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Keep up with the latest news in 2018: fast charging and wireless charging, Bluetooth and smart home and GaN
- Application of LOTO oscilloscope with VI curve tester in circuit board maintenance
- About PCB board to make a set of playing cards
- [Silicon Labs BG22-EK4108A Bluetooth Development Evaluation] 1. Unboxing + Data Collection + Development Environment Construction + Lighting
- Please help provide the entire PCB board production process and the SMD component mounting process animation. Thank you
- Summary of DSP's real clock system--Explained with TI's DSP TMS320F2812 as an example
- E840-DTU device unresponsive problem
- Is it better to first increase the voltage to 5V and then decrease it to 3.3V when using a 3.7V lithium battery? Or is it better to first decrease it to 3.3V and then increase it to 5V?
- Download the Pomona Connectors catalogue and win a Xiaomi Mosquito Repellent!
- Are smaller components better?