I have some code which sets/resets individual bits on PortB. I created some definitions like: #define lamp_on (PORTC.F1 = 1) etc
I am using the EasyPIC2 board with LED's enabled. When testing bits that were on started to be reset; never the reverse. After a while I wondered if there was a hardware problem. However, the problem appears to be with the read-modify-write operation; the port read is unreliable.
I fixed the problem using a portc_copy variable. I set/reset the bits in the copy and then store the copy into PORTC. This works ok.
Is this a known problem?
Read-Modify-Write issues on Ports
Re: Read-Modify-Write issues on Ports
Which PIC do you use?
Instead of using a copy of port variable, try with using LATC register.
Instead of using a copy of port variable, try with using LATC register.
Re: Read-Modify-Write issues on Ports
No, not so far. Try experimenting a little with the #define directive. The source file that exits the preprocessor and enters the compiler has the extension .cp.dgoadby wrote:I fixed the problem using a portc_copy variable. I set/reset the bits in the copy and then store the copy into PORTC. This works ok.
Is this a known problem?
pizon
I am using PIC16F688.
I have investigated a little further now. I copied the PORTC contents to PORTA before updating and the PORTC read does return a different value to the actual value.
+++++++++++++ DOH! I've got it. As ever, the answer is in the small print. The problem was the comparators; unless they are specifically disabled then the digital read will return 0.
My excuse is that my previous PIC didn't have comparators so I just didn't consider them....
I have investigated a little further now. I copied the PORTC contents to PORTA before updating and the PORTC read does return a different value to the actual value.
+++++++++++++ DOH! I've got it. As ever, the answer is in the small print. The problem was the comparators; unless they are specifically disabled then the digital read will return 0.
My excuse is that my previous PIC didn't have comparators so I just didn't consider them....
David Goadby