I am using a pic on a simple little robot with the usual bump, revese, turn, obsticle avoidance. it will do more than that later but I havent even writen a PIC program yet so I am starting small. anyway there is on thing I don't understand in the tutorial i read. it is the XORFcommand. I understand xor gates but how does it work here; http://www.pictutorial.net/?page_id=152
it says
MOVLW 02h XORWF PORTA,1
should toggle the 1 bit in port a.
how does it toggle? where is the result and what is w being compared to?
oh and one more question. does w register clear to 0 or 255 when you use movwf?
once I get this figured out I should be ready to start. I am working on the electronics and program at the same time.
I strongly recommend you go to Microchip.com and grab the datasheet for the 16F84A if you don’t have it already; it has the full instruction set inside it, along with pretty much everything else about the micro.
The XORWF commands takes two arguments as you know, the first one being the target f register that will be XOR’d with the W register. The second argument is a single bit that determines where the result will be stored after the calculation: a 0 stores the result in W, a 1 stores the result in the target f register. In the case of your example code, XORWF is taking the contents of PORTA and W, XORing them together, and then taking the result and putting it back into PORTA, which overwrites the original data. As mentioned in the tutorial 02h is just 0010 in binary, so using this value in an XOR command toggles bit 1 in the target register (PORTA’s bit #1 in this case), but leaves the other bits as they were.
MOVWF actually copies W as opposed to ‘moving’ it in a conventional sense. When you use MOVWF, the target f register becomes the same value as W, but W also stays that value unless you use CLRW or something similar to reset or overwrite it.