Read-Modify-Write issues on Ports

General discussion on mikroC.
Post Reply
Author
Message
dgoadby
Posts: 18
Joined: 01 Aug 2005 07:03

Read-Modify-Write issues on Ports

#1 Post by dgoadby » 01 Aug 2005 07:13

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?
David Goadby

User avatar
zristic
mikroElektronika team
Posts: 6608
Joined: 03 Aug 2004 12:59
Contact:

Re: Read-Modify-Write issues on Ports

#2 Post by zristic » 01 Aug 2005 08:03

Which PIC do you use?
Instead of using a copy of port variable, try with using LATC register.

pizon
mikroElektronika team
Posts: 823
Joined: 11 Oct 2004 08:53

Re: Read-Modify-Write issues on Ports

#3 Post by pizon » 01 Aug 2005 08:34

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?
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.
pizon

dgoadby
Posts: 18
Joined: 01 Aug 2005 07:03

#4 Post by dgoadby » 01 Aug 2005 16:37

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.... :?
David Goadby

Post Reply

Return to “mikroC General”