Alex Ruhl
Alex Ruhl

Reputation: 457

Assembly movf & movwf

i will realize my circuit with my PIC16F84A from Microchip... so i have to put a signal from PORTA,3 to PORTB,0 but movwf is just working with PORTB... i have following code

movf        PORTA,3   ; copy PORTA,3 into registry
movwf       PORTB,0   ; copy PORTA,3 from the registry into PORTB,0

so... when i give a high on PORTA,3 it should be give a signal on PORTB,0....

how can i realize that?

Upvotes: 1

Views: 5057

Answers (2)

raj raj
raj raj

Reputation: 1922

Moving signal PORTA(3) to PORTB(0):

btfss PORTA,3
bcf PORTB,0
btfsc PORTA,3
bsf PORTB,0

Edit:

// if PORT(3) is zero, PORTB(0,1,2) is reset to zero
movlw f8
btfss PORTA,3
andwf PORTB,1

// if PORT(3) is set, PORTB(0,1,2) is set to high
movlw 03
btfsc PORTA,3
iorwf PORTB,1

Upvotes: 1

Michael
Michael

Reputation: 58507

This should move the value of PORTA to PORTB:

movf PORTA, W
movwf PORTB

It's a bit unclear from your question whether you want to move the value as-is, or if you want to set bit 0 of PORTB to bit 3 of PORTA. In the latter case you can do something like this (written in C since I don't know the exact PIC16 syntax off the top of my head):

temp = PORTA;
temp >>= 3; 
temp &= 1;      // temp now contains PORTA.0 in bit 0
temp2 = PORTB;
temp2 &= ~1;    // clear bit 0, keep all others as-is
temp |= temp2;
PORTB = temp;

Upvotes: 1

Related Questions