Read-Modify-Write, it's briefly explained in the PBP manual somewhere...and it's also explained in those links above a bit...
Read-Modify-Write, it's briefly explained in the PBP manual somewhere...and it's also explained in those links above a bit...
This one is pretty good explaining what it is.
Outside the forum:http://www.piclist.com/techref/readmodwrite.htm
Ohm it's not just a good idea... it's the LAW !
Setting or clearing port bits directly reads the whole port, alters the bit in question,However I do not understand why PORTA does not work and LATA works in this "example". Could somebody try to explain that shortly
the writes the whole 8-bit value back to the port.
Example (for 18F parts);
HIGH PORTB.0
HIGH PORTB.1
HIGH PORTB.2, etc
And PBP will generate assembler code something like;
bsf PORTB,0 ; reads the whole port, sets RB0, writes the 8-bit value back to the port
bcf TRISB,0 ; make RB0 an output (now RB0 begins to go high)
bsf PORTB,1 ; reads whole port again (note that RB0 may not be high yet because this happens fast)
bcf TRISB,1
bsf PORTB,2
bcf TRISB,2, etc.
What happens is when RB0 goes high, then it's made an output, it may take a while
before the actual voltage output on RB0 goes high - due to external capacitance.
If the voltage output on RB0 is below the PIC logic 1 input threhold, when the port was
read on the 2nd bsf instruction, it gets read back in as zero, and a logic 0 gets output
back on RB0. It read the port, modified only RB1, and wrote the new value back to the
port. I.E. That's R-M-W.
When you use the LAT registers it doesn't cause the whole port to be read back, modified,
then written again.
The faster the core is running, and the more external capicitance there is, the more you will
have problems with read-modify-write.
Microchip added the LAT registers on 18F series primarily to eliminate this problem.
You are setting ADCON1 = 7. This sets PortA to analog.
I would be setting ADCON1 = %00001111 in order to make PortA all digital.
This has changed froom the PIC16F877 series.
HTH
Brian
Thank you Skimask, Bruce, Pic_user and all other for your support.
The more one comes familiar with PIC, there are more and more that is not advertised by Microchip in the first place, mais c'est la vie....
Before this problem, I was not aware of such a thing as r-m-w. Now I think I understand what the phenomena is. In a matter of fact, I was kind of lucky when I run into this TOGGLE problem.
Thank you once again for your kind help....
Regards
Key
Bookmarks