8051 MCU Tutorial Lesson 12: Logical Operation Instructions

Publisher:心满愿望Latest update time:2021-05-08 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Logical operations on accumulator A:


CLRA; clear the value in A to 0, single-cycle single-byte instruction, with the same effect as MOVA, #00H.


CPLA; reverse the value in A bit by bit


RLA; logically shift the value in A to the left


RLCA; logically shift left by adding the carry bit to the value in A


RRA; logically shift the value in A to the right


RRCA; logically shift right by adding the carry bit to the value in A


SWAPA; swap the high and low 4 bits of the value in A.


For example, if (A) = 73H, CPLA is executed as follows:


73H is converted to binary as 01110011.


The bit-by-bit inversion is 10001100, which is 8CH.


RLA sends the 7th bit of the value in (A) to the 0th bit, the 1st bit to the 0th bit, and so on.


For example: The value in A is 68H, and RLA is executed. 68H is converted to binary 01101000, and the shift is performed according to the above figure. 01101000 is converted to 11010000, which is D0H.


RLCA shifts the value in (A) with the carry bit (C).


For example: if the value in A is 68H and the value in C is 1, then RLCA is executed.


After 101101000, the result is 011010001, that is, the value of the carry bit of C becomes 0, and (A) becomes D1H.


I won’t talk much about RRA and RRCA. Please refer to the two examples above and practice on your own.


SWAPA swaps the high and low 4 bits of the value in A.


For example: (A) = 39H, then after executing SWAPA, the value in A is 93H. Why is it swapped like this? Because this is a hexadecimal number, and each hexadecimal digit represents 4 binary bits. Note that if it is like this: (A) = 39, without H behind it, after executing SWAPA, (A) = 93 is not. It needs to be converted into binary and then calculated: 39 is converted into binary 10111, which is 0001. The upper 4 bits of 0111 are 0001, and the lower 4 bits are 0111. After swapping, it is 01110001, which is 71H, or 113.


Exercise, given (A) = 39H, execute the following instructions and write down the results of each step


CPLA


RLA


CLRC


RRCA


SETBC


RLCA


SWAPA


Through the previous learning, we have mastered quite a few instructions. You may be a little bored with these boring instructions. Let's relax and do an experiment.


Experiment 5:


ORG0000H


LJMPSTART


ORG30H


START:


MOVSP,#5FH


MOVA,#80H


LOOP:


MOVP1,A


RLA


LCALLDELAY


LJMPLOOP


delay:


movr7,#255


d1:movr6,#255


d2:nop


nop


nop


nop


djnzr6,d2


djnzr7,d1


ret


END


Let us first write the program into the chip, install it into the experimental board, and see the phenomenon.


What we see is a phenomenon of dark spots flowing. Let us analyze it.


We will analyze the previous ORG0000H, LJMPSTART, ORG30H later. Starting from START, MOVSP, #5FH, this is to initialize the stack. It doesn't matter whether this sentence is in this program, but we are slowly starting to get in touch with formal programming, so I will slowly cultivate the habit for everyone.


MOVA, #80H, sends the number 80H to A. What is it for? I don't know. Read on.


MOVP1, A. Send the value in A to the P1 port. At this time, the value in A is 80H, so the value sent out is 80H, so the value of the P1 port is 80H, which is 10000000B. Through the previous analysis, we should know that at this time, the LED connected to P1.7 is not bright, while the other LEDs are bright, so a "dark spot" is formed. Continue to look at RLA, RLA is to shift the value in A to the left. Calculate, what is the result after the shift? Yes, it is 01H, which is 00000001B. In this way, the LED connected to P1.0 should not be bright, while the others are bright. From the phenomenon, the "dark spot" flows to the back. Then call the delay program, which we are very familiar with, to make this "dark spot" "dark" for a while. Then transfer to LOOP (LJMPLOOP). Please calculate which light should be off below. . . . . Yes, it should be connected to P1.1. The light is not on. This cycle forms the phenomenon of "dark spot flow".


question:


How to achieve highlight flow?


How to change the direction of flow?


Answer:


1. Change the initial value in A to 7FH.


2. Change RLA to RRA.


Reference address:8051 MCU Tutorial Lesson 12: Logical Operation Instructions

Previous article:8051 MCU Tutorial Lesson 11: Arithmetic Operation Instructions
Next article:Create a new Keil C51 project (3)

Recommended ReadingLatest update time:2024-11-16 15:55

Precise signal simulation circuit design based on C8051F410 microcontroller
When testing a certain type of transmitting device. Three sets of accurate DC voltage signals referenced to 11.50 volts are required. In order to cooperate with the test process, these three sets of signals need to take 18 different DC voltage values ​​​​at different periods of time, with amplitudes distributed in the
[Microcontroller]
Precise signal simulation circuit design based on C8051F410 microcontroller
What does the 8051 microcontroller consist of? How many pins does the 8051 microcontroller have?
Introduction to 8051 microcontroller The 8051 microcontroller is an 8-bit microcontroller widely used in embedded systems. It was launched by Intel in 1980. It was one of the most advanced 8-bit microcontrollers in the industry at that time and a classic in the field of microcontrollers. The 8051 microcontroller has
[Microcontroller]
Audio peak collection terminal design based on C8051F020 microcontroller and RTL8019AS
Broadcast signals go through program production and broadcasting, signal transmission, emission and other links, and are finally listened to at the audience's end. The system working status of each link will have an impact on the final broadcast quality. In order to comprehensively monitor the signal quality of multip
[Microcontroller]
Audio peak collection terminal design based on C8051F020 microcontroller and RTL8019AS
Delphi-smpcomm code example (3)
In order to realize the communication between PC and 8051 microcontroller, the handshake signal between them must be adjusted first. Assuming that the communication protocol between them is that one frame of data from PC to 8051 is 6 bytes, and one frame of data from 8051 to PC is also 6 bytes. When PC sends (F0, 01
[Microcontroller]
C language programming of 8051 microcontroller
      8051 C programming is similar to traditional C programming. Of course, some data types are different. As we know, 8051 supports powerful bit addressing capabilities, so 8051 C programming adds some new data types to avoid wasting the capabilities of 8051. The following are the newly added data types.        bi
[Microcontroller]
C language programming of 8051 microcontroller
Introduction to Single Chip Microcomputer C8051F020 and Its Application in Instruments and Meters
1 Introduction At present, with the continuous improvement of science and technology and industrial and agricultural production levels, higher and higher requirements are placed on corresponding instruments and meters. Therefore, instruments and meters need to expand a large number of peripheral funct
[Microcontroller]
Design of Virtual Instrument Test System Based on C8051F120 Single Chip Microcomputer
1 Introduction Virtual instruments are computer-based instruments. The close integration of computers and instruments, and the construction of virtual instruments to replace complex and bulky analog instruments is the current trend of instrument development. Compared with traditional instruments, virtual instruments h
[Test Measurement]
Design of Virtual Instrument Test System Based on C8051F120 Single Chip Microcomputer
LCD touch screen technology and application designed with C8051F023
There are many types of human-computer dialogue interfaces, such as display, LED, LCD and LCD with touch screen. Among them, LCD with touch screen is a new technology that has just developed in recent years. It uses computer technology to process sound, image, video, text, animation and other information, and establish
[Microcontroller]
LCD touch screen technology and application designed with C8051F023
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号