Misunderstandings and Skills in Using MCU Instructions

Publisher:RadiantJourneyLatest update time:2013-02-20 Source: dzscKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
    Misunderstandings and Skills in Using Elan MCU Instructions

  The basic instruction syntax of EMC is actually just 57/58. How to change it depends on your practice and luck.

  1. Misunderstanding of subtraction instruction

  Part 1: About ACC

  EMC has three subtraction instructions, as follows:

  SUB A,R (R-A→A)

  SUB R,A (R-A→R)

  UNDER A,K (KA→A)

  It should be noted that no matter whether A is in the front or the back, A is the subtrahend, not the minuend.

  也就是說如果我們想計算A-2的值,如果寫成:

  UNDER A,@2

  其實是執行2-A

  解決方法如下:

  ADD A,@256-2 or

  ADD A,@254

  Part 2: About CY

  Generally speaking, addition/subtraction will affect the carry flag CY.

  In some other single-chip instruction systems, when a borrow occurs in subtraction, CY=1, and when a borrow does not occur, CY=0.

  If you think that the subtraction of EMC is the same, haha, you need to take medicine!

  It turns out that in the EMC instruction system, when a borrow occurs in subtraction, CY=0, and when a borrow does not occur, CY=1.

  If you don't pay attention to this, it is easy to leave bugs in some calculations or judgment programs.

  2. Misunderstandings of table lookup (scatter transfer) instructions

  1. About the "ADD R2,A" instruction

  In the EMC153/156 instruction system, there is no TBL instruction (this must be remembered), so when you need to look up a table, you have to use "ADD R2, A" (or MOV R2, A) instead.

  But when using "ADD R2,A", please note that this instruction can only change the lower 8 bits (i.e. 256 bytes) of the PC pointer, and all other high bits are cleared!

  So when using "ADD R2,A", you must ensure that the entire table is within the first 256 bytes of each page of ROM. (153/156 has only one page)

  The use of large tables is limited, and in order to "squeeze" the tables into the ROM space from 00H to FFH, the structure of the program is destroyed.

  Part 2: About the "TBL" instruction

  Just now I mentioned that there are many unpleasant things when using the "ADD R2,A" instruction.

  To this end, EMC added a new instruction to the instruction system of 447/458 and subsequent chips, namely the TBL instruction.

  TBL is a table lookup instruction. It is said that it can be placed anywhere in the program.

  But wait -

  The following points should also be noted when using the TBL instruction:

  First, the table cannot span pages (each 1024 bytes is a page (PAGE))

  Secondly, the table cannot cross "segments"

  What is a "segment"?----"Segment" is a concept defined by craftsmen: each page is divided into 4 segments, each segment has 256 bytes (for example: 00H~FFH is a segment, 100H~1FFH is another segment)

  That is to say, for each table lookup program, the table length must be less than or equal to 255 bytes, except that the TBL itself occupies one byte. And the entire table lookup program must be in the same "segment".

  This question is such a big trap!

  Sometimes, even though your program has been debugged, you may accidentally adjust the order of program modules or add/reduce a few instructions, and the program may not work properly.[page]

  Hey, check your LST file, it's probably TBL that's causing the problem!

  In addition, TBL still does not solve the problem of looking up large tables (it has to be cut into small tables of less than 255 bytes like cutting tofu)

  3. About the "MOV R,R" instruction

  This is a very strange instruction. First of all, please do not misunderstand this instruction and think that it is to send the data of one register to another register. When I first came into contact with EMC 8bit IC, I was once "hit"! After being guided by an expert, I was freed - Buddha has mercy on me, and I am free from Buddha!

  Look carefully: the two Rs in "MOV R,R" refer to the same register, and its action is to transfer the contents of the register to itself.

  If you think this is a meaningless action, you are wrong.

  According to the experience of craftsmen, this instruction has at least two uses:

  Use one: judge zero

  The purpose of this instruction is that it can affect the Zero Flag to determine whether the content of the register is zero.

  If we want to determine whether the value of a register is zero, we usually use

  MOV    A,R

  JBS    STTS,Z        ; R3,Zero Flag

  These two instructions, but this will affect the original content of ACC. If you do not want to use ACC, you may write

  INC    R

  DEC    R

  JBS    STTS,Z

  This will use three instructions. If the MOV R,R instruction is used, not only can the same function be achieved, but the number of instructions can also be reduced, which can be said to kill two birds with one stone.

  MOV    R,R

  JBS    STTS,Z

  Use 2: Store the external level state of the I/O port into the latch

  At this point, we need to first introduce the IO port characteristics of EMC.

  EMC IO ports are generally tri-state and can be set to high impedance (input); or output state

  When the IO port is set to input state, it can only be "read" but not "written". The CPU directly "reads" the external voltage level through the IO port. If a "write" action occurs at this time, the data will not be output but stored in a latch. When the IO port becomes an output state, the data in the latch will be sent to the IO port.

  ——Note: Here, although the source register and the destination register have the same address, they are actually different things. (It is equivalent to two families living under the same house number)

  If there is such an instruction: MOV R6, R6

  Analysis: First read the external level status of port R6, and then send it to the latch of R6.

  For example: When port R6 is used for level flip wake-up function, its external level must be saved in the latch first.

  MOV    R6,R6

  Then turn on the R6 port level flip wake-up function. When the R6 port status and latch change, the corresponding interrupt can be triggered.

  (The corresponding port of R6 must be set to input state)

  Once again, I would like to remind you that the "MOV R,R" instruction cannot be used to transfer numbers between two registers. If you want to transfer numbers between two registers, you must go through the intermediary company - ACC.

  If you want to reduce the labor of writing programs, insert the following macro into your program:

  MOV     MACRO    REG1,REG2

  MOV    A,REG2

  MOV    REG1,A

  ENDM

  In this way, when you write "MOV REG1, REG2", the system will automatically convert it into two instructions for you:

  MOV    A,REG2

  MOV    REG1,A

Keywords:MCU Reference address:Misunderstandings and Skills in Using MCU Instructions

Previous article:Analyze how to improve the analog-to-digital conversion accuracy of single-chip microcomputers
Next article:Quick Start Technology of Single Chip Microcomputer

Recommended ReadingLatest update time:2024-11-16 17:37

STMicroelectronics STM32U0 creates the ultimate low-power MCU
ST (STMicroelectronics) recently launched the new STM32U0 microcontroller, this Cortex-M0+ core-based product can achieve a static power consumption of only 160nA in standby mode with a real-time clock (RTC), and as low as 16nA in shutdown mode, showing excellent energy-saving performance. In the CoreMark and SESIP
[Microcontroller]
STMicroelectronics STM32U0 creates the ultimate low-power MCU
Metal detector based on 51 single chip microcomputer
1. Hardware Solution The metal detector designed in this paper is made based on the principle of electromagnetic induction. When a metal is placed in a changing magnetic field, eddy currents will be generated inside the metal according to the principle of electromagnetic induction. The magnetic field generated by the
[Microcontroller]
Metal detector based on 51 single chip microcomputer
51 microcontroller programming environment construction method
Preface This tutorial will introduce you to the installation of KEIL C51 software. Through the study of this tutorial, we can install a KEIL C51 software on the computer, paving the way for the development of subsequent learning programs. 1. KEIL C51 installation 1. Software acquisition To successfully install KEIL
[Microcontroller]
51 microcontroller programming environment construction method
Robotic arm intelligent grabbing system based on 89C51 microcontroller
Abstract: In the process of agricultural development, fruit picking is an extremely labor-intensive task. In order to reduce labor costs in the agricultural production process, applying artificial intelligence to the agricultural field will be an effective means. An intelligent grasping system is designed based on the
[Microcontroller]
Robotic arm intelligent grabbing system based on 89C51 microcontroller
Highly sensitive, low power infrared proximity sensing solution
Silicon Laboratories (Silicon Labs), an innovative manufacturer of high-performance analog and mixed-signal ICs, has launched the Si1102 and Si1120, which are among the most sensitive infrared proximity sensors in the industry, especially in terms of long-range detection and low power consumption
[Security Electronics]
Highly sensitive, low power infrared proximity sensing solution
Comparison of GB22450.1 and YD1032 standards in mobile phone EMC testing
    Although 3G products are gradually occupying the market, major manufacturers and various fields are also waiting for the arrival of the 3G era, but this does not mean that 2G will be completely replaced soon. It is expected that 2G wireless terminals will still dominate the market for a long time.     As China's e
[Test Measurement]
Comparison of GB22450.1 and YD1032 standards in mobile phone EMC testing
Design of LED display system based on single chip microcomputer
Recently, the author found in a logistics call system project based on field bus on a large production line in a factory that due to the large amount of information flow to be displayed, the existing LED display screen control system based on AT89C51 chip is limited by the processing speed, system architecture, addr
[Power Management]
Design of LED display system based on single chip microcomputer
Differences between EMC receiver and spectrum analyzer in EMC testing
When selecting EMC test equipment, we often encounter the following questions: What is the difference between an EMI receiver and a spectrum analyzer? Why should we use a receiver for EMI testing? This article analyzes the test principle of a receiver based on CISPR16-1 (GB/T6113) and GJB152, and provides a reference
[Test Measurement]
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号