In the previous article, we talked about using 74LS138 to control the bit selection of digital tubes. How to select it? Let's take a look at the manual of this decoder.
74LS138
/Y0--/Y7 is data output
A0--A2 is data input
/E1, /E2, E3 are enable controls, /E1 and /E2 are low level effective, E3 is high level effective
VDD is connected to the power supply; GND is connected to the ground
The most important thing is the truth table, to explain how it works
/E1 and /E2 are low level valid, E3 is high level valid, as long as one of them does not meet the conditions, /Y0--/Y7 will all output high level, our common cathode digital tube will not light up
All are satisfied from the fourth row onwards, and now you can look at A0--A2, the order is A2-
A1-A0, from top to bottom, are 000, 001, 010, 011, 100, 101, 110, 111. This shows that they are binary 0, 1, 2, 3, 4, 5, 6, 7. Look at the right half of Y0, 000 is Y0, 001 is Y1, 010 is Y2... Once you correspond, you will know how it is controlled?
Code:
Digital tube dynamics
There is a switch statement switch(i) which judges i. When i is 0, the statements after case 0 are executed. Add a break after each statement, otherwise the following statements will be executed continuously.
A for loop realizes the requirement that different digital tubes display different numbers. When i is 0, the first digital tube lights up and the number is 0. When i is 1, the second digital tube lights up and displays the number 1.
P0 = 0x00 is to make the P0 port more stable and return to its original position
I suddenly had an idea halfway through writing, which made it more difficult. I had to display it once and then do it again in reverse.
Improve
In fact, a nested for loop is added, which is judged as follows...
That 9 took a lot of time. I kept writing 8, so the display was 0, 1, 2, 3, 4, 5, 6, 0, 7, 6, 5, 4, 3, 2, 1, 0
I thought a and i were synchronized. I was careless and my foundation was not solid. a is in the order of 1, 2, 3, 4, 5, 6, 7... So when i is 7, a is 8, so here I write <9
The case 4 is protruding out of hand because of carelessness, but this is C language so the indentation is not a problem. If it is Python that relies on indentation for positioning, there will be a problem, but it seems that Python is rarely used to write microcontrollers. . . .
*
Previous article:The MCU Learning Journey for Beginners (Twenty-one) --- Understanding MCU Serial Communication (I)
Next article:The Path of Learning for a Newbie in Microcontrollers (Part 1)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Live Q&A Summary: ADI MEMS Sensors Open a New Era of Conditional State Monitoring
- Security Technology System of Wireless WLAN
- It is found that the OPAMP of STM32G474 cannot be internally connected to ADC4
- In-depth understanding of C language function parameters as pointers
- EEWORLD University Hall ---- The first stop of the ADI Road theme tour of Shijian: Industrial Automation
- AD20 Installation Issues
- Are there any commonly used solutions recommended for converting 0-10V to PWM?
- Looking for C8051F58x/F59x IDE?
- 9. [Learning LPC1768 library functions] Clkout experiment
- DSP28335 eCAP module capture pulse problem