The calculators we talked about before were all based on C language. Next, let’s talk about a simple calculator based on assembly language.
hardware design
The display is still a digital tube, and the MCU is C51, which supports integer calculation.
Simulation diagram:
programming
YJ EQU 50H ;Result storage
YJ1 EQU 51H ;Intermediate result storage
GONG EQU 52H ; Function key storage
ORG 0000H
START: MOV R3,#0 ; Initialization display is empty
MOV GONG,#0
MOV 32H,#00H
MOV 33H,#00H
MOV 34H,#00H
MLOOP: CALL DISP ;Call display subroutine
WAIT: CALL TESTKEY ; Check if a key is pressed
JZ WAIT ; Check if the accumulator is 0
CALL GETKEY ; read key
INC R3 ;Number of buttons
CJNE A,#0,NEXT1 ; Determine whether it is a numeric key
LJMP E1 ; Switch to numeric key processing
NEXT1: CJNE A,#1,NEXT2
LJMP E1
NEXT2: CJNE A,#2,NEXT3
LJMP E1
NEXT3: CJNE A,#3,NEXT4
LJMP E1
NEXT4: CJNE A,#4,NEXT5
LJMP E1
NEXT5: CJNE A,#5,NEXT6
LJMP E1
NEXT6: CJNE A,#6,NEXT7
LJMP E1
NEXT7: CJNE A,#7,NEXT8
LJMP E1
NEXT8: CJNE A,#8,NEXT9
LJMP E1
NEXT9: CJNE A,#9,NEXT10
LJMP E1
NEXT10: CJNE A,#10,NEXT11; Determine whether it is a function key
LJMP E2 ; Switch to function key processing
NEXT11: CJNE A,#11,NEXT12
LJMP E2
NEXT12: CJNE A,#12, NEXT13
LJMP E2
NEXT13: CJNE A,#13,NEXT14
LJMP E2
NEXT14: CJNE A,#14,NEXT15
LJMP E2
NEXT15: LJMP E3; Determine whether to clear the key
E1: CJNE R3,#1,N1; Determine which key is pressed
LJMP E11 ; for the first number
N1: CJNE R3,#2,N2
LJMP E12; for the second number
N2: CJNE R3,#3,N3
LJMP E13 ; for the third digit
N3: LJMP E3; The fourth digit overflows
E11: MOV R4,A; Input value is temporarily stored in R4
MOV 34H,A ; input value is sent to display buffer
MOV 33H,#00H
MOV 32H,#00H
LJMP MLOOP ; Wait for input again
E12: MOV R7,A; single digit is temporarily stored in R7
MOV B,#10
MOV A,R4
MUL AB ; Tens digit
ADD A,R7
MOV R4,A ; input value stored in R4
MOV 32H,#00H ; Input value is sent to display buffer
MOV 33H,34H
MOV 34H,R7
LJMP MLOOP ; Wait for input again
E13: MOV R7,A
MOV B,#10
MOV A,R4
MUL AB
JB OV,E3; Input overflow, if OV is equal to 1, go to E3
ADD A,R7
JB CY,E3 ; Input overflow
MOV R4,A
MOV 32H,33H ; input value to display buffer
MOV 33H,34H
MOV 34H,R7
LJMP MLOOP
E3: MOV R3,#0 ; reset the number of key presses
MOV R4,#0 ; input value cleared
MOV YJ,#0 ; Clear the calculation result
MOV GONG,#0 ; Set the function key to zero
MOV 32H,#00H ; Display clear
MOV 33H,#00H
MOV 34H,#00H
LJMP MLOOP
E2: MOV 34H,#00H
MOV 33H,#00H
MOV 32H,#00H
MOV R0,GONG ;Exchange with the last function key
MOV GONG,A
MOV A,R0
CJNE A,#10,N21 ;Judgement function key
LJMP JIA ;"+"
N21: CJNE A,#11,N22
LJMP JIAN ;"-"
N22: CJNE A,#12,N23
LJMP CHENG ;"*"
N23: CJNE A,#13,N24
LJMP CHU ;"/"
N24: CJNE A,#0,N25
LJMP FIRST ; Press the function key for the first time
N25: LJMP DEN ;"="
N4: LJMP E3
FIRST: MOV YJ,R4; input value to result
MOV R3,#0 ; reset the number of key presses
LJMP DISP1 ; Result processing
JIA: MOV A,YJ ; send the last result to the accumulator
ADD A,R4; last result plus input value
JB CY,N4 ;Overflow
MOV YJ,A ; store this result
MOV R3,#0 ; reset the number of key presses
LJMP DISP1
JIAN: MOV A,YJ
SUBB A, R4 ; Last result minus input value
JB CY,N4 ; Negative overflow
MOV YJ,A
MOV R3,#0
LJMP DISP1
CHENG: MOV A,YJ
MOV B,A
MOV A,R4
MUL AB ; last result multiplied by input value
JB OV,N4 ;Overflow
MOV YJ,A
LJMP DISP1
CHU: MOV A,R4
MOV B,A
MOV A,YJ
DIV AB ; divide the last result by the input value
MOV YJ,A
MOV R3,#0
LJMP DISP1
DEN: MOV R3,#0
LJMP DISP1
DISP1: MOV B,#10
MOV A,YJ ; send the result to the accumulator
DIV AB ; Divide the result by 10
MOV YJ1,A ; Temporarily store "商"
MOV A,B ; take the unit digit
MOV 34H,A ; Send the single digit to the display buffer
MOV A,YJ1
JZ DISP11 ; Is the result a single digit?
MOV B,#10
MOV A,YJ1
DIV AB
MOV YJ1,A
MOV A,B
MOV 33H,A ; Send the ten digits to the display buffer
MOV A,YJ1
JZ DISP11 ; Is the result a two-digit number?
MOV 32H,A ; send the hundreds digit to the display buffer
DISP11: LJMP MLOOP
The file is for reference only:
Link: https://pan.baidu.com/s/1ZAxAbTe_oD_cuTvvKWxU5A
Extraction code: x102
Previous article:Simple lottery machine based on 51 single chip microcomputer
Next article:A multifunctional calculator based on 51 single-chip microcomputer, supporting binary and octet decimal negative number calculation
- 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
- Application of electromagnetic functional composite materials in radar antenna covers
- Noise Countermeasures Using Capacitors
- I have a few questions about the WM8978 audio amplifier board.
- Guess what development board this is?
- ST programmable sensor + FSM on Unico
- Digital Circuits and Digital Systems: Experiments and Course Design Training Course
- AT91SAM7S256 serial port data loss
- Using DSP motor speed measurement and detailed explanation
- Low-power Qorvo chips enhance connectivity and reliability for new Luna smart home system
- Highlights of Bluetooth Mesh Technology