12F675 program query

Thread Starter

MaxHeadRoom

Joined Jul 18, 2013
21,607
Just started playing around with a 12f675 and just to make sure of a program I plugged in a LED flasher program of the web using GP0 pin 7 output.
But the method used I had not seen before but what puzzles me is how is pin GP0 turned on with this method, there is no direct operation on GP0 as in 'bsf GP0, o etc.
This is essentially the command with just a constant loop back to a 1 sec delay.

Code:
; Toggle the LED every second.
movlw b'00000001'
xorwf GPIO, 1

; Repeat this forever.
; goto loop to delay.
Max.
.
 
Last edited:

WBahn

Joined Mar 31, 2012
26,277
So what happens to GP0 when you XOR the contents of the W register, which has been set to 1, with the GPIO register and store the result back in the GPIO register?

Hint: How are GP0 and GPIO related?
 

Dodgydave

Joined Jun 22, 2012
9,642
Gpio is the Register for the gp0-5 bits, so you need to make the gpo bit Zero in file Gpio this will make it an Output,

then you can use "Bsf gpo" or "Bcf gpo"
to toggle the output pin.
 

Thread Starter

MaxHeadRoom

Joined Jul 18, 2013
21,607
Yes I came to realize, It was the GPIO,1 that confused me for a sec, I'm so used to seeing a F.
But I also read on the Microchip forum that this is the preferred method, as some run in to an issue with Read-Write-Modify, this pic does not have the LAT register like the ones I am used to.
Max.
 

JohnInTX

Joined Jun 26, 2012
4,337
Yes I came to realize, It was the GPIO,1 that confused me for a sec, I'm so used to seeing a F.
But I also read on the Microchip forum that this is the preferred method, as some run in to an issue with Read-Write-Modify, this pic does not have the LAT register like the ones I am used to.
Max.
I don't know what you read on uCHIP's forum but I would always use ,F and ,W and never use the default file register destination. If you get into the habit of always specifying the destination, the assembler will alert you when you forget and the assembler picks the default for you making debugging a little easier. Using ,W and ,F also makes your code more readable and less prone to error.

Specifying ,1 instead of ,F has nothing to do with the r-m-w problem. I would strongly recommend shadowing the GPIO when you don't have a LATx register.

Good luck with your coding.
 

Thread Starter

MaxHeadRoom

Joined Jul 18, 2013
21,607
Thanks, The original example was from a program I grabbed off the internet not the micro forum.
The R-W-M issues was the one I saw on the Forum.
The main thing is it is working!
Max.
 

GopherT

Joined Nov 23, 2012
8,012
I understand the issues of the chips without the LATx register but What do you mean by "shadowing"? Specifically, What specific program lines (or effects) make a "shadow"?

I would strongly recommend shadowing the GPIO when you don't have a LATx register.
 

JohnInTX

Joined Jun 26, 2012
4,337
Shadowing means to maintain a copy of the output port in RAM, do any bit-diddling on the RAM image then write the RAM to the PORT as a byte i.e. movwf.
The problem with bsf/bcf to a PORT is that the port's copy of its current value is on the pins. Any operation that reads the port with the port as the destination i.e. andwf PORTx,F, bsf, bcf, incf etc. takes the initial value to modify by reading the pins. If for whatever reason a pin is read with an incorrect value (noise spike at a bad time, capacitive load that hasn't charged up yet, bad luck - there are a lot of reasons) that incorrect value will be used in by the instruction then written back to the port, causing that pin value to change from what the program wrote. The real bugger is that a r-m-w on one pin can affect the written values of other pins if they have the misfortune to be subject to anything that might cause the value to be different than written.

Lots of people don't believe that r-m-w is a potential problem in a properly designed system.
I disagree.
 

GopherT

Joined Nov 23, 2012
8,012
Shadowing means to maintain a copy of the output port in RAM, do any bit-diddling on the RAM image then write the RAM to the PORT as a byte i.e. movwf.
The problem with bsf/bcf to a PORT is that the port's copy of its current value is on the pins. Any operation that reads the port with the port as the destination i.e. andwf PORTx,F, bsf, bcf, incf etc. takes the initial value to modify by reading the pins. If for whatever reason a pin is read with an incorrect value (noise spike at a bad time, capacitive load that hasn't charged up yet, bad luck - there are a lot of reasons) that incorrect value will be used in by the instruction then written back to the port, causing that pin value to change from what the program wrote. The real bugger is that a r-m-w on one pin can affect the written values of other pins if they have the misfortune to be subject to anything that might cause the value to be different than written.

Lots of people don't believe that r-m-w is a potential problem in a properly designed system.
I disagree.
I've had the problem and it happened to be on a project using the exact chip in this thread's title. We addressed it in a similar way you mentioned - I just wasn't sure if your word, "shadowed" implied a different method.

Thanks.
 

JohnInTX

Joined Jun 26, 2012
4,337
Me, too. The 12F675 seems particularly prone to r-m-w even with solid I/O circuits attached. One of many reasons why I won't use midrange any more.
 

Thread Starter

MaxHeadRoom

Joined Jul 18, 2013
21,607
Up to now I had been using the 12f1822 but had some '675's I thought I would use up, but maybe a bad idea, I think I will revert back.!
Max.
 

JohnInTX

Joined Jun 26, 2012
4,337
Up to now I had been using the 12f1822 but had some '675's I thought I would use up, but maybe a bad idea, I think I will revert back.!
Max.
You can use up the 675's if they do the job. Shadow the GPIO and it will work fine. As you progress with your project, you might be starting to suspect that it is a good idea to make your IO operations either subroutines or macros so that you can diddle with the particulars as you move from chip to chip. .. and it is so good on ya! :cool:
 

Thread Starter

MaxHeadRoom

Joined Jul 18, 2013
21,607
The irksome thing is it is so laborious using the Pickit3 needed for the 12f1822, the '675's work slick with the PK2.
MPLAB 8.92.
Max.
 
Top