Sorry for the typo - and the inability to edit a post.
Code:ShadowC VAR BYTE ShadowC = PortC ShadowC = $f PortC = ShadowC
Sorry for the typo - and the inability to edit a post.
Code:ShadowC VAR BYTE ShadowC = PortC ShadowC = $f PortC = ShadowC
Why pay for overpriced toys when you can have
professional grade tools for FREE!!!
Hi,
Not really because then the top four bits will be 0 which they might not have been when PortC was read. And IF the top four bits doesn't matter then I see no reason for not simply writing to PortC directly, ie PortC = $F which would make THIS particular example even faster....Even faster would be this way - but obviously the OP did not try it the way Charles described.
However, I suspect that setting the low four bits to 1 are just an example. Using bitwise AND/OR could also work but I'm not sure it's faster than simply flipping the four bits in ShadowC and then writing it to the port.
/Henrik.
All of this is basic stuff - using a bit mask and writing directly to PORTC is the fastest way. Bottom line is that the OP did not do it the way Charles described and that is why it did not work for him. I just re-wrote it in a way that I felt would make sense to the OP.
Last edited by rmteo; - 9th December 2011 at 17:16.
Why pay for overpriced toys when you can have
professional grade tools for FREE!!!
One of the best threads dealing with RMW and solutions to solve the problem is here:
http://www.picbasic.co.uk/forum/showthread.php?t=15843
Charles also explains that using this method should not affect your USART pins if they are on that particular port.
Just out of curiosity, is this method affecting your PWM if it is active on the same port and how?
Are there any other special or ordinary functions that could be affected?
I’m especially interested to know about inputs on the port that might be used for interrupts and the external source changes while this action is in progress.
Regards,
Nick
This thread was about an antiquated 16F877. I try to use only later model processors (2009 at the oldest). If a PORT pin is declared as a PWM port, none of the following will have any affect on that pin:
HIGH PWMpin
LOW PWMpin
HIGH LAT[PWMpin]
LOW LAT[PWMpin]
PWMpin = 0
PWMpin = 1
In other words, if you wanted to turn the output off, HPWM 1, 0, Freq
To turn it fully on, HPWM 1, 255, Freq.
With that said, the above methods of altering pins on a port will not affect PWM output (at least on the processors I use).
Last edited by mpgmike; - 5th August 2017 at 16:03.
Sorry, my bad. I posted to the wrong thread which in fact is the target of my link.
I was trying to post to this new thread:
http://www.picbasic.co.uk/forum/showthread.php?t=22951
Just so we do not create too much confusion, can my reply be moved to the right thread?
Regards,
Nick
Bookmarks