Jump to content
Sign in to follow this  
Visti

Bit Copy

Recommended Posts

V. 6.31 Target PIC16F877A (must apply to others aswell).

 

bit1=bit2; gives following

 

 

...

bcf bit1

btfsc bit2

bsf bit1

...

...

 

meaning that an output (in my case) is toggled when it should stay 1 (took me a couple of hours to figure that one out).

 

Workaround: if(bit2) bit1=1;else bit1=0;

Share this post


Link to post
Share on other sites
V. 6.31 Target PIC16F877A (must apply to others aswell).

 

bit1=bit2; gives following

 

 

...

bcf bit1

btfsc bit2

bsf bit1

...

...

 

meaning that an output (in my case) is toggled when it should stay 1 (took me a couple of hours to figure that one out).

 

Workaround: if(bit2) bit1=1;else bit1=0;

 

 

Manipulating output port bits is a bit hairy on PICs due to the read modify write problem (its documented in every PIC spec sheet.)

You would be better mirroring the port bits, manipulating the mirror then writing the mirror out to the port.

Share this post


Link to post
Share on other sites
V. 6.31 Target PIC16F877A (must apply to others aswell).

 

bit1=bit2; gives following

 

 

...

bcf bit1

btfsc bit2

bsf bit1

...

...

 

meaning that an output (in my case) is toggled when it should stay 1 (took me a couple of hours to figure that one out).

 

Workaround: if(bit2) bit1=1;else bit1=0;

 

Declare the bit as volatile. This will prevent unnecessary toggle but will generate slightly longer code.

 

Regards,

Pavel

 

PS: We also recommend to upgrade to the latest release 6.32

Share this post


Link to post
Share on other sites
Declare the bit as volatile. This will prevent unnecessary toggle but will generate slightly longer code.

if(bit1) bit2=1;else bit2=0; is shorter.

Mirroring a port is overkill if e.g. only 1 bit is output.

The bit2=bit1; could give problems in interrupts as well.

PS: We also recommend to upgrade to the latest release 6.32

I accidently hit the 1 instead of 2. It is 6.32.

Share this post


Link to post
Share on other sites

Declare the bit as volatile. This will prevent unnecessary toggle but will generate slightly longer code.

if(bit1) bit2=1;else bit2=0; is shorter.

 

Not really. "if(bit1) bit2=1;else bit2=0;" compiles into 5 instructions while "bit2 = bit1;" into 4 instructions when bit2 is declared as volatile.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Declare the bit as volatile. This will prevent unnecessary toggle but will generate slightly longer code.

if(bit1) bit2=1;else bit2=0; is shorter.

 

Not really. "if(bit1) bit2=1;else bit2=0;" compiles into 5 instructions while "bit2 = bit1;" into 4 instructions when bit2 is declared as volatile.

 

Regards,

Pavel

This is what I got

 

CLRF CompTempVar164

BTFSC gbl_bit1,0

INCF CompTempVar164, F

BTFSC CompTempVar164,0

BSF gbl_bit2,6

BTFSS CompTempVar164,0

BCF gbl_bit2,6

 

The transfer itself is 4 but the setup is another 3.

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...