Four buttons control four numbers in increments

Publisher:雅逸之风Latest update time:2018-05-11 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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:Four buttons control four numbers to increase - Non-famous blogger - Electronic Information Corner

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:Four buttons control four numbers to increase - Non-famous blogger - Electronic Information Corner


Reference address:Four buttons control four numbers in increments

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

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号