Editing Read before write

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
 
==== Read before Write ====
 
==== Read before Write ====
  
The issue with 'read before write' is that, unlike a PIC18, it is impossible for a program running on the PIC16 to read the state of its output port latch.
+
The issue with 'read before write' is that, unlike a PIC18, it is impossible for a program running on the PIC16 to read the state of its output pins.
  
 
The classic issue occurs when individual port bits are set, or toggled, causing outputs on the pins to behave unexpectedly.
 
The classic issue occurs when individual port bits are set, or toggled, causing outputs on the pins to behave unexpectedly.
Line 25: Line 25:
  
 
#define set_port(port, no)\
 
#define set_port(port, no)\
set_bit(sport[&port-PORTA], no);\
+
set_bit(sport[&porta-PORTA], no);\
port=sport[&port-PORTA];
+
port=sport[&porta-PORTA];
  
 
#define clear_port(port, no)\
 
#define clear_port(port, no)\
clear_bit(sport[&port-PORTA], no);\
+
clear_bit(sport[&porta-PORTA], no);\
port=sport[&port-PORTA];
+
port=sport[&porta-PORTA];
  
 
#define test_port(port, no)\
 
#define test_port(port, no)\
test_bit(sport[&port-PORTA], no)
+
test_bit(sport[&porta-PORTA], no)
  
 
#define toggle_port(port, no)\
 
#define toggle_port(port, no)\
toggle_bit(sport[&port-PORTA], no);\
+
toggle_bit(sport[&porta-PORTA], no);\
port=sport[&port-PORTA];
+
port=sport[&porta-PORTA];
 
</pre>
 
</pre>
  
Line 43: Line 43:
  
 
* [http://massmind.org/techref/readmodwrite.htm The Read-Modify-Write problem]
 
* [http://massmind.org/techref/readmodwrite.htm The Read-Modify-Write problem]
* [http://circuitguru.com/79/pic-microcontroller-read-modify-write-bugs/ Circuit guru: "PIC microcontroller read-modify-write bugs"]
 
* [http://www.cornerstonerobotics.org/curriculum/lessons_year2/erii_rmw_problem.pdf Cornerstone Robotics: "Read-Modify-Write (RMW) Problem with Mid-Range PIC Microcontrollers ... and Avoiding the Read-Modify-Write (RMW) Problem with LATx Registers in PIC18Fxxxx"]
 
* [http://electronics.stackexchange.com/questions/7684/what-causes-turning-on-an-single-output-pin-on-a-microchip-pic16f690-to-spontane Stackexchange: "What causes turning ON an single output pin on a Microchip PIC16F690 to spontaneously turn OFF another pin on the same port?"]
 
  
  
 
[[Category:BoostC]][[Category:PIC]]
 
[[Category:BoostC]][[Category:PIC]]

Please note that all contributions to OpenCircuits may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see OpenCircuits:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)