Electronic – PIC32 having multiple PORTB’s “high” at the same time

cmicrochipmplabmplabxpic

I am trying to set a couple of PORTBbits to "high" (1) at the same time
for that I am using the following code:
I am using thePIC32MX695F512H

#define MOV1A_IO TRISBbits.TRISB0
#define MOV1A PORTBbits.RB0
#define MOV1B_IO TRISBbits.TRISB1
#define MOV1B PORTBbits.RB1

#define MOV2A_IO TRISBbits.TRISB2
#define MOV2A PORTBbits.RB2
#define MOV2B_IO TRISBbits.TRISB3
#define MOV2B PORTBbits.RB3

#define MOV3A_IO TRISBbits.TRISB10
#define MOV3A PORTBbits.RB10
#define MOV3B_IO TRISBbits.TRISB11
#define MOV3B PORTBbits.RB11

int main(void)
{
    MOV1A_IO = 0x00; //output
    MOV1B_IO = 0x00; //output
    MOV2A_IO = 0x00; //output
    MOV2B_IO = 0x00; //output

    //while(1){
    MOV2B = 0xFF;
    MOV2A = 0xFF;
    MOV1B = 0xFF;
    MOV1A = 0xFF;
    //}
    return 0;
}

But what I get is this:

image

I would expect all 3 to be "high". Anyone knows what is wrong with the code

Best Answer

Use LATx: to write to an output pin

Use PORTx: to read an input pin

For all PICs with LATx registers, all INPUT must be from PORTx and all OUTPUT should be to LATx, which totally avoids the problem of flipping bits when you write to a single bit of the port.