# PIC32 having multiple PORTB's “high” at the same time

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:

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

• return 0; ? Where do you expect t to return? Put while(1); in the end. – Eugene Sh. Mar 4 '19 at 20:55
• PORTs are generally used for reading. LAT are used for writing. What happens if you write to the port using LAT - LATBbits.LATB0 = 1 etc... – efox29 Mar 4 '19 at 20:56
• Thank you that works! – Jose Luis Montalvo Ferreiro Mar 4 '19 at 20:59

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.