Search code examples
microchippic32

How to find which I/O register in PIC32 my input is connected to


I have a PIC32MX795F512L on a chipkit max32.

I need to use assembly to read when a button I have connected has been pushed.

In looking at the documentation (http://ww1.microchip.com/downloads/en/DeviceDoc/61120D.pdf) it says that the TRISx, PORTx, LATx registers are used. But how do I find the correct ones? If the pin on the board says its connected to pin 74 of the pic 32, is it just TRIS74, PORT74, LAT74?

In the reference for the board (http://www.digilentinc.com/Data/Products/CHIPKIT-MAX32/chipKIT_Max32_RM.pdf page 11) it says that the PIC32 signal for that pin is SOSCO/T1CK/CN0/RC14, but I have no idea what that means.

I'm pretty confused. Any help would be greatly appreciated. Ive spent several hours trying to figure this out to no avail. thanks


Solution

  • All of this is explained in the various application/specification sheets. As I know these can be overwhelming at first, I'll summarize here :

    TRISx is the Tri-state control register were you set the pin as input or output. LATx is the output latch register were you can set the output value (if set as output in the TRISx register). PORTx is the port read register were you can read the port value (if set as input in the TRISx register).

    Depending on the pin you want to use, there may be some other registers that may limit your ability to read said pin, such as the ANSELx registers which sets pins to analog mode (disables the digital input).

    For the information regarding which pin is attributed to which ***.x, have a look at the main specification sheet for your processor. From the link you supplied, the board your using seems to be a TQFP, therefore, page 15 of the specification sheet (http://ww1.microchip.com/downloads/en/DeviceDoc/61156H.pdf) should have the information you are looking for. Using your example above of pin 74, it is labelled as "SOSCO/T1CK/CN0/RC14". The important part is RC14, it means PORT C, bit 14.

    To read from it you can do PORTCbits.PORTC14 or you can "if(PORTC & 0x4000)...". The other registers work the same way ("TRISCbits.TRISC14 = 0; LATCbits.LATC14 = 1;").