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
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
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- How to achieve automated testing of LCR?
- Which company can make PCB boards with a width of about 2MM?
- How to speed up the program running speed of Huada HC32F460 HC32F4A0?
- FPDLINK Spark Interference Optimization
- Why do electrolytic capacitors explode? Find out in one article!
- [Iprober 520 current probe] Calibration and use in PCB mode
- A brief history of hard disk interface evolution
- Hot plug and unplug
- EEWORLD University ---- STM32CubeMX and STM32Cube HAL basics
- [TI mmWave Radar Evaluation]_3_AWR1843BOOST Corridor Ranging Test Environment