Compiled marquee of 51 microcontroller

Publisher:EuphoricMelodyLatest update time:2023-01-11 Source: zhihuKeywords:Assembly Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Without further ado, let’s start with the program

ORG 0000H

MAIN:MOV P1,#0O

LCALL DELAY

MOV A,#0FEH

SETB C

TO: MOV P1,A

LCALL DELAY

LCALL DELAY

RLC A

JC TO

MOV P1,A

LCALL DELAY

LCALL DELAY

TO1: RRC A

MOV P1,A

LCALL DELAY

LCALL DELAY

JC TO1

AJMP TO

DELAY:MOV R2,#0FEH

TC1:MOV R3,#0FEH

TC2:DJNZ R3,TC2

DJNZ R2,TC1

RET

END

The purpose of this program is to make 8 LEDs light up in a cycle, and one of them is not lit at all. My LED is connected to the P1 port and lights up when the level is low. The general phenomenon is that they all light up once, then light up in sequence from left to right, and then all go out, then light up once from right to left, and then go out, and then the cycle continues like this.


Now let's analyze the code step by step. I won't repeat the knowledge points I talked about before. I will write it briefly and if you don't understand, look ahead.

ORG 0000H; I won’t talk about this anymore

MAIN:MOV P1,#00; Let all lights turn on

LCALL DELAY; delay

MOV A,#0FEH; 11111110 is assigned to accumulator A. Accumulator A is equivalent to a temporary variable and temporary register in C language.

SETB C; Set the carry flag C to 1, which is equivalent to adding one bit to the eight bits. This can make the lights all off. Wait until you understand everything below to see the function of this statement. , which is better understood this way.


TO: MOV P1,A; This statement is labeled TO. After execution, the leftmost light will light up.

LCALL DELAY

LCALL DELAY

RLC A; This is a new statement, which performs circular left shift and carry on A. RLC, my understanding is recircle left carry. When translated into Chinese, it means circular left shift and carry, which means adding accumulator A and carry flag C together. Cycle left

It is equivalent to 9 numbers moving back and forth in a cycle, and there is a 0 in it. Wherever this 0 is moved, whichever light will light up. When it moves to the carry flag, every light will not light up, because the carry flag is not Control the lights on and off.


JC TO; JC means to judge whether to transfer based on whether the carry flag C is 1. Jump carry. If C is equal to 1, jump to TO and continue to perform the left shift. Otherwise, the following program will be executed. Since 8 1 and a 0 move in these nine positions, so only when 0 moves to the carry flag C, it will execute the following program, so when it does not cycle to the state of all off, it will continue to perform the left shift

MOV P1,A; assign the state that the carry flag C is 0 to the P1 port, and let all the lights go out.

LCALL DELAY

LCALL DELAY

TO1: RRC A; RRC, recircle right carry, cycle right shift with carry and RLC cycle in the opposite direction. There is no difference in essence. From this time on, the first light on the right will light up, and it will light up to the far left

MOV P1,A

LCALL DELAY

LCALL DELAY

JC TO1; rotate right

AJMP TO; move to the far right and jump back to the front to start looping left

DELAY:MOV R2,#0FEH; The following is the delay function

TC1:MOV R3,#0FEH

TC2:DJNZ R3,TC2

DJNZ R2,TC1

RET

END

You can try RL and RC, which do not have a carry flag, so there will not be a state where everything is turned off. If there is something wrong or not in place, please give me your advice. It is best for you to buy a 51 or 52 microcontroller and play with it to learn, otherwise it will be very ineffective. Try for yourself what will happen if those statements are missing. Then change the program according to your goals.


Keywords:Assembly Reference address:Compiled marquee of 51 microcontroller

Previous article:51 microcontroller realizes temperature acquisition and display (2)
Next article:Use assembly to write the beginning of 51 microcontroller to light up the LED

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号