How do I use MEGA pin number designations rather than RAMPS pin numbers in marlin I am designing my own shield for the MEGA2650 that I will use to control my printer. 

When defining pins in the marlin firmware, the pin numbers are the pin numbers of the RAMPS shield and not the Arduino MEGA itself.

How can I define pins so that I could write #define HEATER1PIN 5 and it will make heater1pin be on Arduino MEGA's pin 5 and NOT RAMPS's pin 5
The pin mapping that Marlin uses is defined in the file fastio_1280.h:

/**
 * Pin mapping for the 1280 and 2560
 *
 *   1280     22 23 24 25 26 27 28 29 53 52 51 50 10 11 12 13 37 36 35 34 33 32 31 30 21 20 19 18 81 82 83 38 00 01 78 05 02 03 79 80 54 55 56 57 58 59 60 61 41 40 39 71 70 04 17 16 84 06 07 08 09 85 15 14 72 73 75 76 77 74 62 63 64 65 66 67 68 69 49 48 47 46 45 44 43 42
 *   Port     A0 A1 A2 A3 A4 A5 A6 A7 B0 B1 B2 B3 B4 B5 B6 B7 C0 C1 C2 C3 C4 C5 C6 C7 D0 D1 D2 D3 D4 D5 D6 D7 E0 E1 E2 E3 E4 E5 E6 E7 F0 F1 F2 F3 F4 F5 F6 F7 G0 G1 G2 G3 G4 G5 H0 H1 H2 H3 H4 H5 H6 H7 J0 J1 J2 J3 J4 J5 J6 J7 K0 K1 K2 K3 K4 K5 K6 K7 L0 L1 L2 L3 L4 L5 L6 L7
 *   Marlin   00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
*/


Confusingly, the line labeled "1280" refers to the pin numbers as used by Marlin. The line labeled with "port" gives the corresponding port/pin combination as it applies to the AtMega2560 chip itself. To translate between the port numbers given above, and the Arduino Mega pin numbers, you can use the following pinout diagram:


Licensed under CC-BY-SA, www.bq.com

For instance, according to the pin mapping in fastio_1280.h, Marlin pin 34 is "port" C3. This corresponds to PC3 in the pinout diagram, which is Arduino Mega A11. Conversely, if we want to find out what PWM pin 9 is in Marlin, we can look at the diagram to find out it corresponds to PH6, which is Marlin pin 09.

If you want to change this numbering, then unfortunately, you have to make quite a few modifications to fastio_1280.h. For instance, the "reason" pin 5 corresponds to the pin it does, is the following set of definitions:

#define DIO5_PIN    PINE3
#define DIO5_RPORT  PINE
#define DIO5_WPORT  PORTE
#define DIO5_DDR    DDRE
#define DIO5_PWM    &amp;OCR3AL


If you wanted to point pin 5 towards another pin, you'd need to change all of these lines to point to the correct registers and pin numbers.