# PIC32 microcontroller c code

Discussion in 'Embedded Systems and Microcontrollers' started by metric_electric, Aug 21, 2013.

1. ### metric_electric Thread Starter New Member

Aug 21, 2013
19
0
Please can someone explain this code to me:

TRISA = 0x000C; //sets pins RA2 and RA3 to inputs, rest of PortA as outputs
TRISC = 0xA000; //sets pins RC13 and RC15 as inputs, all else as outputs

I do not understand how 0x000C represents pins RA2 and RA3 ...and how 0xA000 represents pins RC13 and RC15. I understand binary numbers and a bit of hexadecimal but the above code throws me off.

Help!

Aug 27, 2009
3,020
2,386
3. ### ErnieM AAC Fanatic!

Apr 24, 2011
7,443
1,628
As nsaspook said, you need to write out the whole 32 bit number in binary.

I like to see the bit numbers (RA2 or RC15), so I will write them down to construct the binary number. That was lots easier with 8 bit processors, but you can still do it with long words if you write the bit number vertically:

Code ( (Unknown Language)):
1. 3322 2222 2222 1111 1111 11
2. 1098 7654 3210 9876 5432 1098 7654 3210
3. ----.----.----.----.----.----.----.----
4. 0000 0000 0000 0000 0000 0000 0000 1100
5.    0    0    0    0    0    0    0    C = 0x 0000 000C
6.
7. 3322 2222 2222 1111 1111 11
8. 1098 7654 3210 9876 5432 1098 7654 3210
9. ----.----.----.----.----.----.----.----
10. 0000 0000 0000 0000 1100 0000 0000 0000
11.    0    0    0    0    A    0    0    0 = 0x 0000 A000
12.
It also helps to separate the bits into hex digits. When I'm doing this a lot I can look at the binary and write the hex digit.

As a final note, a 32 bit quantity needs a full 8 hex digits to fully specify it.

4. ### metric_electric Thread Starter New Member

Aug 21, 2013
19
0
nsaspook and ErnieM:

Thank you so much for the explanation, I now fully understand....I spent over week trying to grab that piece of code but you guys broke it down to me in minutes.

I have another question but it has to do with setting up the software and complier on my laptop.

I got the PIC32MX795F512L USB starter kit, the I/O expansion board and the cable from the starter kit to a USB port on my laptop. Do I still need the Explorer 16 development board (DM240001) and the MPLAB REAL ICE in-circuit debugger (DV244005)....?

5. ### ErnieM AAC Fanatic!

Apr 24, 2011
7,443
1,628
No and no. The Explorer 16 is a different system where you can change out processors. The USB starter kit has a fixed processor along with a 2nd processor to handle programming and debugging, which means you don't need a separate (ICE) debugger either.

I'm sure that kit comes with some tutorials. Crack them open and try out the first one.

6. ### metric_electric Thread Starter New Member

Aug 21, 2013
19
0
Thanks ErnieM!