This design is a decimal calculator system design based on the AT89C51 single-chip microcomputer. It can complete the keyboard input of the calculator, perform simple arithmetic operations of addition, subtraction, multiplication and division of 4-bit unsigned numbers, and display the results accordingly on the LED. In terms of hardware, from the functional considerations, the AT89C51 single-chip microcomputer with rich internal storage resources is first selected, and the input adopts a 4×4 matrix keyboard. The display adopts a 4-bit 7-segment common anode LED dynamic display. In terms of software, the system design is carried out from the analysis of calculator functions, flow chart design, to program writing. Here I recommend you to read the ten-day learning single-chip microcomputer.
0 Preface
This system uses AT89C51 single-chip microcomputer as the controller to realize the four-digit "+", "-", "*", "/" operation. The operation result is displayed through the digital tube and has a clearing function. AT89C51 has the following features: 40 pins, 4k BytesFlash on-chip program memory, 128 bytes of random access data memory (RAM), 32 external bidirectional input/output (I/O) ports, 5 interrupt priority levels, 2-level interrupt nesting interrupts, 2 16-bit programmable timer counters, 2 full-duplex serial communication ports, watchdog (WDT) circuit, and on-chip clock oscillator.
1 Overall design plan
1.1 System composition and working principle
This system is based on the 51 single-chip microcomputer as the main control core, and is combined with a matrix keyboard, crystal oscillator, and LED display tube module. Its working process is: first, the storage unit is initialized, the initial value and keyboard scan are displayed, the key position is determined, and the key value is obtained. The single-chip microcomputer stores the data and processes and converts it accordingly, and then sends it to the digital tube for dynamic display. The calculation result is sent to the digital tube for dynamic display. This design can only perform calculations with a result of no more than four digits, and its functions are as follows:
(1) The numeric keys "0" to "9" are displayed using digital tubes.
(2) Addition operation: Both the addend and the augend cannot exceed 9999, and the final result of the addition cannot exceed 9999.
(3) Subtraction operation: The normal logic of subtraction operation is to subtract a larger number from a smaller number. This calculator is also the same and can only perform normal logic operations. For example, if you want to subtract a larger number from a smaller number, add the resulting negative number to 535 to get the corresponding result. In other words, if you want to subtract a larger number from a smaller number, subtract 535 from the result to get the correct result for a negative number.
(4) Multiplication operation: As with the above method, the calculation result cannot exceed 9999. If overflow occurs, only the last three digits of the result will be displayed.
(5) Division operation: The divisor and dividend cannot exceed 9999, and only the integer part of the calculation result is displayed.
(6) Equal key: The calculation result will be displayed only when the equal key is pressed; otherwise, the previous number will be displayed.
(7) Reset function: When the program is unstable or an error occurs, use the reset key to return to the initial state. You can also use the reset key to reset.
2 System Hardware Design
2.1 Overall design of system hardware
This system consists of a keyboard matrix and an LED display tube. The keyboard inputs key values, and the LED display tube displays the current key presses and results. The overall hardware design diagram 1 is as follows:
2.2 Matrix scan displays the current key module
Use the P0 port P0.0 - P0.7 of the AT89S51 microcontroller to connect to the a - h segments of a seven-segment digital tube, and the common end of the digital tube is connected to the power supply. The matrix scan displays the current key module as shown in Figure 2.
2.3 Keyboard Layout Module
Working principle of matrix keyboard: The keyboard layout of calculator is shown in Figure 3: It is generally composed of 16 keys. In the single-chip microcomputer, one P port can be used to realize the functions of 16 keys. This form is also the most commonly used in single-chip microcomputer systems.
3 System Software Design
3.1 System software overall design
The software flow of this system is shown in Figure 4.
3.2 Display program modules
The display program calculates the thousands, hundreds, tens and units of the value to be displayed, outputs the value through the P0 segment selector, and realizes dynamic display through the bit selectors P3^3, P3^4, P3^5 and P3^6.
LED digital tube, realize the display of four-digit decimal number by seven-segment digital tube. The value of key and calculation result is displayed by segment selection. Since this hardware design adopts common anode connection, the corresponding segment code table is as follows 3.3 Keyboard scanning module
This keyboard scanning program uses the row-column flip method to scan the keyboard, that is, first set the row to 0, read the column value, and store it in variable 1, then set the column to 0, read the row value, and store it in variable 2. Adding variable 1 and variable 2 is the key value corresponding to the key. The following table shows the key values corresponding to the corresponding keys.
This calculator is a calculator system based on the 51 series single-chip microcomputer. It is designed to perform simple arithmetic operations. Under the existing hardware conditions, it can only perform operations with results not exceeding four digits. It can realize the calculation functions of addition, subtraction, multiplication and division, the function of clearing numbers, and the reset function of the system.
Previous article:51 MCU-button part (1)
Next article:Six common problems with 51 single-chip microcomputers
Recommended ReadingLatest update time:2024-11-16 13:54
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
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
- [Review of Arteli Development Board AT32F421] 2. Use of peripheral ERTC
- [Review of SGP40] + Unboxing & Basic Use
- How to choose between different chips in TI's Sub-1GHz product line?
- CircuitPython Electronic Chain Bracelet
- "C Programming Magic Book: Based on C11 Standard"
- [Project Source Code] 3 methods to display state machine names in Modelsim simulation based on FPGA
- Temperature sensor + I2C + serial port + PC host (pyserial) example
- MSP430G2553 internal ADC principle and routine description
- Types of PCB substrates
- What is the difference between an AD schematic and a schematic library?