# Bit Set Command not working as I thought

Status
Not open for further replies.

#### andydawson

##### New Member
I have been trying to do some bit manipulations on a P12F675 and it doesn't appear to be working as I expected. BSF seems to set the right bit but clears all the rest. For example:
The following only leaves bit 5 on,
code assembler
$1405 BSF GPIO, 0$1485 BSF GPIO, 1
$1505 BSF GPIO, 2$1605 BSF GPIO, 4
$1685 BSF GPIO, 5 The following only leaves bit 4 on, code assembler$1405 BSF GPIO, 0
$1485 BSF GPIO, 1$1505 BSF GPIO, 2
\$1605 BSF GPIO, 4

WHEREAS if I write a word of all ones to GPIO the right lights come on so I have the TRISIO and other registers set up ok
etc etc.
What an I doing wrong. Any Ideas?

(I am working with EASy PIC 5 and as the basic compiled code wasn't working I started looking at the actual assembler- I have tried two PICs)

#### ericgibbs

##### Well-Known Member
hi,
Look at page 25 of the 12C67x datasheet, ref GPIO reading.

#### Attachments

• 24.4 KB Views: 74
Last edited:

#### eng1

##### New Member
I have been trying to do some bit manipulations on a P12F675 and it doesn't appear to be working as I expected. BSF seems to set the right bit but clears all the rest.
After the first BSF instruction, the port might not have time to respond to this command. The second BSF read the port and sees '0' on GPIO0, then it sets GPIO1.... This repaeats until the last BSF set one bit to '1' and the other ones are '0'.

Try inserting a couple of NOPs between each BSF instruction.

A better tecnique is to move the the port bits the W register and set the pin values with IORWF or ANDWF instructions.

Last edited:

#### andydawson

##### New Member
Thanks for all the input , it seems to that using a seperate register to do the bit seting overcomes the problem.
thanks again
Andy