Circuit:
Using AT89S52 single chip microcomputer.
P3.0 to P3.3 are connected to four external buttons.
P3.4 to P3.7 are the bit selection ports for controlling the four digital tubes, and P1 is the segment selection port for the digital tubes.
Require:
The initial number is 0.
Each time you press the first button, the first number is added by 1;
each time you press the second button, the second number is added by 2;
each time you press the third button, the third number is added by 3;
each time you press the fourth button, the fourth number is added by 4.
;==================================================
Best answer:
As required, use PROTEUS to draw the circuit and simulate it. The screenshot of the effect is as follows:
The control program is written in assembly language. The following programs have been debugged successfully:
ORG 0000H
JMP START
START:
MOV 30H, #0
MOV 31H, #0
MOV 32H, #0
MOV 33H, #0
;----------------------------
M_LOOP:
CALL DISP
MOV P3, #0FH
MOV A, P3 ;Read key information.
CPL A
ANL A, #0FH
JZ M_LOOP ;Loop display if no key is pressed.
;--------------------
CALL DISP ;Delay and debounce.
MOV P3, #0FH
MOV A, P3
CPL A
ANL A, #0FH
JZ M_LOOP ;Confirm again.
MOV B, #1
JB ACC.0, J1 ;Branch.
JB ACC.1, J2
JB ACC.2, J3
JB ACC.3, J4
JMP M_LOOP
;------------------Calculate and add 1234
J4: INC B
J3: INC B
J2: INC B
J1: MOV A, #2FH
ADD A, B
MOV R0, A
MOV A, @R0
ADD A, B
MOV B, #8
DIV AB
MOV @R0, B
;------------------Wait for the key to be released.
J_J:
CALL DISP
MOV P3, #0FH
MOV A, P3
ORL A, #0F0H
CPL A
JNZ J_J
JMP M_LOOP
;------------------The following is the display program
DISP:
MOV R0, #30H
MOV R2, #10H
D_LOOP:
MOV A, @R0
INC R0
ADD A, #(D_TAB - $ - 3)
MOVC A, @A + PC
MOV P3, #0FH
MOV P1, A
MOV P3, R2
CALL DELAY
MOV A, R2
RL A
MOV R2, A
CJNE R2, #1, D_LOOP
RET
;----------------------------
D_TAB:
DB 0C0H, 0F9H, 0A4H, 0B0H, 99H, 92H, 82H, 0F8H
DB 80H, 90H, 88H, 83H, 0C6H, 0A1H, 86H, 8EH, 0FFH ;FF is a blank code.
;---------------------------------------
DELAY:
MOV R6, #20
D1: MOV R7, #250
DJNZ R7, $
DJNZ R6, D1
RET
;---------------------------------------
END
;
=
...
;------------------The following is the display program
DISP:
MOV R0, #30H
; MOV R2, #10H
MOV R2, #0EFH
D_LOOP:
MOV A, @R0
INC R0
ADD A, #(D_TAB - $ - 3)
MOVC A, @A + PC
; MOV P3, #0FH
MOV P3, #255
MOV P1, A
MOV P3, R2
CALL DELAY
MOV A, R2
RL A
MOV R2, A
; CJNE R2, #1, D_LOOP
CJNE R2, #254, D_LOOP
RET
;----------------------------
I sent the modified program via email, and a reply came in a few minutes:
That's awesome! I've been working on it for days... but it didn't work... Thanks! It worked in one go! Thank you very much...
The following is a photo of the program working on the actual circuit board:
Previous article:51 MCU assembly language programming: using timer to control the output of rectangular wave
Next article:Digital tube dynamic display assembly 60 hexadecimal
- Popular Resources
- Popular amplifiers
- Setup_SmartRFProgr_1.12.7.rar
- A good application to see some components like better button and vertical menu. Works with GP3 to con
- Copy gen_jmsn.dll to your Winamp Plugins Directory.JMSN Auto Nickname Changer plugins support only
- CAN1.c and CAN2.c are a simple example of configuring a CAN network to transmit and receive data o
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
- How is JTAG used for chip testing?
- Talk about downloading the DSP28335 register manual
- 4W PLC Power Supply Reference Design with Wide Input Voltage Range
- [Gizwits Gokit3 Review] Device Access-Step 1: Create a New Solution Project
- Circuit Diagram
- Apple faces ultimatum! EU finalizes: Type-C interface will be fully adopted in 2024
- Running test code for mmWave chips on QSPI flash
- RF and Microwave Passive Component Design Considerations and Limitations
- 【TI recommended course】#Lecture on basic knowledge of electronic circuits#
- Power PCB Layout Issues