Continue to Site

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.

  • 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.

Transferring bit condition in 2 instructions ?

Status
Not open for further replies.

tubos

New Member
Code:
LATB.B4=Gdat.b7;            //

translates to:

Code:
	BTFSC       _Gdat+0, 7 
	GOTO        L__interrupt54
	BCF         LATB+0, 4 
	GOTO        L__interrupt55
L__interrupt54:
	BSF         LATB+0, 4 
L__interrupt55:

Is it possible to do it in only 1 or 2 instructions?
I'm using an 18F14K22
 
Last edited:
Code:
     asm bsf LATB,4
     asm BTFSS _Gdat,7
     asm BCF LATB,4

studying the datasheet this is the best i can think off
 
There must be a wider context implication. A straight bitwise equal in Basic looks like three instructions:

Code:
green_led = green_duty.7

asm output:
	bcf	LATC,0,ACCESS
	btfsc	GREEN_DUTY,7,BANKED
	bsf	LATC,0,ACCESS
 
Your code has the disadvantage of the PIC output turning off and then back on again if it is on to start with and bit 7 of GREEN_DUTY is on.

That glitch is avoided with this:-

Code:
	btfss	GREEN_DUTY,7,BANKED
	bcf	LATC,0,ACCESS
	btfsc	GREEN_DUTY,7,BANKED
	bsf	LATC,0,ACCESS

I am fairly sure that there is usually no quicker way of transferring a bit state in less than 3 instructions, if you don't know the initial state.

On PWM applications, you may already know that the output is off when you come round to turn it on.

Also, you may be able to clear an entire register, then set individual bits. Each individual bit has two instructions to set it, but the overall number of instructions is less than if you cleared individual bits one at a time.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top