• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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
Most Helpful Member
hi,
Look at page 25 of the 12C67x datasheet, ref GPIO reading.:)
 

Attachments

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.
Read-Modify-Write issue, isn't it?
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
 

Pommie

Well-Known Member
Most Helpful Member
I suspect you haven't turned off the analogue inputs. Any pins setup as analogue (the default setting) read back as zero and so a bsf will write zero back to the other pins. Try writing zero into ANSEL (bank 1) and your problems will disappear.

Mike.
 
Last edited:
Status
Not open for further replies.

EE World Online Articles

Loading
Top