What is read-modify-write, the problems it causes and how to solve them:
只要PICmicro的命令,所处理的FILE (暂存器,内存,和I/O的统称),其最终的值,和命令处理前的值有关,那么,这种命令便是所谓的读-修改-写命令。因为这类命令的操作,可以再细分为三个小步骤,即是读(READ),修改(MODIFY),接著才是写(WRITE)。
Such as: ADDWF, DECF, IORWF, XORWF, BSF, BCF, etc.
在使用这类命令的时候,如果所处理的FILE是I/O, 就必须要特别小心。因为,假设任务电压为5V;而您在PORTB的8支脚,没有串接电阻,分别接了8颗二极管(也许是LED)到地。如果,您在先前下了"BSF PORTB,0"这条命令,使得PORTB第0脚上的LED亮了。当您再运行了”BSF PORTB,1"这条命令后,虽然PORTB第1脚上的LED亮了,但是,PORTB第0脚上的LED却会熄掉。原因是因为,运行”BSF PORTB,1”时,会先将整个PORTB的值往回读,而它读到的PORTB第0脚,却是相当於低电位(被二极管拉为0.7V)。当它再把整个PORTB的值写出去的时候,PORTB第0脚就被写成低电位,自然灯就熄了。
The solution is to add resistors in series or not to directly perform read-modify-write commands on the I/O.
There is another situation that needs attention: when you connect the two commands "BSF PORTB,0" and "BSF PORTB,1" together without idle running, even if you do not have the bad circuit design mentioned in the previous paragraph, sometimes you will find that the high potential of PORTB,0 will disappear. The reason for this phenomenon is: because you may have long wires connected to the outside of these two pins, there are considerable capacitance and inductance that will prevent the change of potential; and, the PIC command operation is "written out" in the last 1/4 cycle and "read in" in the first 1/4 cycle, PORTB,0 has not had time to rise to a high potential and is read back by the next command.
The solution is: usually just insert a NOP command between two commands.
Previous article:Tips for using LCD with PIC16F946
Next article:PIC microcontroller loop program example
- Popular Resources
- Popular amplifiers
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
- CC2541 cannot receive data sent by Bluetooth main module
- EEWORLD University Hall - FPGA Simple Design Principles and Applications
- Several analysis methods that you must know about transistor circuits!
- [GD32L233C] + 5. Use RTThread's Finsh component
- Please design a pressure sensor conversion circuit
- Do you know these three special PCB routing techniques?
- FAQ_Using any GPIO to simulate a serial port
- MM32F103 Development Board Evaluation: Driving OLED Display
- TMS320C6711 serial communication initialization program
- How should I choose PCB surface treatment? How should I choose between HASL and OSP?