Electronic – Put one value in PORTA, and another value appears (PIC24 from Microchip)

debuggingmicrochippicport

I am doing a small code for PIC24FJ1024GB610 from Microchip, where I want to test PORTA

The code Below

#include <xc.h>


#pragma config FWDTEN = OFF
#pragma config FNOSC = FRC
#pragma config ICS = PGD2

unsigned int Pattern;

void Ports (void)
{
    TRISA = 0x0000;//all outputs
    ANSAbits.ANSA6 = 0;
    ANSAbits.ANSA7 = 0;
    ANSAbits.ANSA9 = 0;
    ANSAbits.ANSA10 = 0;//all digital ports

    LATA = Pattern;


}


int main (void)
{
    Pattern = 0xBBAA;

    Ports ();


    while(1);

    return 0;
}

What I expected to happen was:

  • Pattern is declared as an unsigned int
  • at main () Pattern = 0xBBAA
  • Program calls Ports ()
  • PORTA configured as Output TRISA = 0x0000
  • PORTA is configured as Digital ANSA = 0x0000
  • LATA = Pattern, if I debug the program, I would expect LATA = 0xBBAA in the SFR window.

When I debug the program, and open the SFR window, I get LATA = 0x82AA, as you can see in the screenshot below.

enter image description here


Helpful info:


Any help is appreciated.

Best Answer

You didn't supply a link to the datasheet, so I didn't look it up. My guess is that not all 16 bits of port A are implemented.

Port A pins also are sometimes used for the oscillator pins, the MCLR input, etc. Those aren't available as port A digital pins when those other roles are used.

You really need to read the datasheet.