PIC Microcontrollers: Read-Modify-Write Problems and Solutions

Publisher:EnchantedDreamLatest update time:2011-05-07 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Reference address:PIC Microcontrollers: Read-Modify-Write Problems and Solutions

Previous article:Tips for using LCD with PIC16F946
Next article:PIC microcontroller loop program example

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号