51 MCU: Key-controlled DC motor

Publisher:平静的33号Latest update time:2018-05-09 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Title: Use AT89C51 microcontroller assembly language to write a program to control the forward and reverse rotation of the motor


The button of P3.0 is used to control the forward rotation.

The button of P3.1 is to control the inversion

The button of P3.2 is to stop


Write it in the shortest possible assembly language, and explain it sentence by sentence if possible. I won't use interrupts.


The circuit is as follows:

51 MCU: Key-controlled DC motor - Non-famous blogger - Electronic Information Corner


For such a simple problem, there is no need to use interrupts.


The program written by Dao is as follows:


;DC motor control

    ORG 0000H

P30:JB P3.0, P31; Detection button

    CALL DELAY ; Delay

    JB P3.0, P31 ; Anti-shake

    JNB P3.0, $ ; Waiting for release

    MOV P2, #01H ;Forward

;------------------------

P31:JB P3.1, P32; take turns to test

    CALL DELAY

    JB P3.1, P32

    JNB P3.1, $

    MOV P2, #02H ; reverse

;------------------------

P32:JB P3.2, P30

    CALL DELAY

    JB P3.2, P30

    JNB P3.2, $

    MOV P2, #03H ;Stop

    SJMP P30

;------------------------

DELAY: ; Delay about 10ms (fosc = 6MHz)

    MOV R6, #10

    DJNZ R7, $

    DJNZ R6, $ - 2

    RET

;------------------------

END

;------------------------


Comment from the questioner: I thank the great god, grateful


postscript:

This program is written as: short and powerful, fully functional, and works extremely fast, not inferior to the method of using interrupts.


Reference address:51 MCU: Key-controlled DC motor

Previous article:51 Assembly language programming: 8 buttons control 8 LEDs
Next article:51 MCU Assembly Programming: Recording Keystrokes

Recommended ReadingLatest update time:2024-11-17 06:45

The electronic clock function is realized by 51 single chip microcomputer and displayed by LCD1602
Implement the clock function through 51 single-chip microcomputer and display it through LCD1602. Click to download the rar project file The experimental screenshots are as follows: Hardware involved in the experiment: 51 single-chip microcomputer, LCD1602 module, one EEPROM AT24C02 model, 3 buttons, one bu
[Microcontroller]
51 MCU Learning Log-Instruction System
3.1 Instruction System Overview 3.1.1 Instructions and instruction system The instruction set of each machine is inherent and cannot be changed. 3.1.2 Programs and Programming Instructions arranged according to predetermined requirements are called programs 3.1.3 Assembly language Progr
[Microcontroller]
51 MCU each pin function
RST reset input is used to complete the reset initialization operation of the microcontroller ALE/(30 pin): Address latch control signal (ALE) is the output pulse that latches the lower 8 bits of the address when accessing the external program memory. PSEN: External program memory select signal is activated twice in e
[Microcontroller]
C8051F320 I/O Usage Summary
First, we need to distinguish between digital signals and analog signals!!!! And also whether they are input or output. Secondly, everyone should know that no matter how the crossbar switch is set, the state of the port I/O pin can always be read into the corresponding port latch. That is, no matter whether the pin
[Microcontroller]
51 MCU Getting Started Tutorial (3) - Digital Tube Display
1. Introduction to LED digital tube LED digital tubes (LED Segment Displays) are devices composed of multiple light-emitting diodes packaged together. Common LED digital tubes are in the shape of "8", with a total of 8 segments. Each segment corresponds to a light-emitting diode. There are two types of digital tubes
[Microcontroller]
51 MCU Getting Started Tutorial (3) - Digital Tube Display
Be sure to learn about the offset compensation function of Keithley's DMM7510 multimeter
Offset compensation is a measurement technique that reduces or eliminates thermal electromotive forces (EMFs) in low-level resistance measurements. The voltage offsets due to the presence of thermal electromotive forces (VEMFs) can adversely affect resistance measurement accuracy, and to overcome these offset voltages
[Test Measurement]
Be sure to learn about the offset compensation function of Keithley's DMM7510 multimeter
51 MCU - Timer Counter Interrupt
First write the IE register interrupt enable register, then write the interrupt handling function After an interrupt is triggered in timing mode, the values ​​of TH and TL will be reset to 0 by default, and the initial values ​​need to be reset in the interrupt service function. example void timer0() interrupt
[Microcontroller]
51 MCU - Timer Counter Interrupt
Direct software architecture for 8-bit MCU systems (C51 series)
1. Preparation of startup documents $ NOMOD51 ; Ax51 macro assembler control command: disable predefined 8051 ; Customize the storage area that needs to be initialized after power-on ; The starting address of the indirect addressing area IDATA is fixed to 0 IDATALEN EQU 8OH; specifies the length
[Microcontroller]
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号