I am basically reformatting this from the Mach4 mill gcode manual guide since I found their's not as easily readable.

M Code Descriptions

M00 – Mandatory Program Stop: To pause a program at any point specify an M00. All motion will be halted and the spindle stopped. To resume operation press the cycle start button.

M01 – Optional Program Stop: Program pauses same as M00, but only when the optional stop switch is turned on. This allows the operator to stop and check program points when needed, but also to run without stops.

M02 – Program End: Ends the program at the M02 block. All program operation will be ended and defaults (G54, G17, G90, etc.) reset. The program will not rewind and if the cycle start button is pressed program operation will begin with the next block following the M02.

M03 – Spindle Forward/Clockwise: Turns the spindle on in the forward direction at the designated speed. M03 is usually combined with an S word to define the speed. If an S word is not specified the last spindle speed is used.

M04 – Spindle Reverse/Counterclockwise: Turns the spindle on in the reverse direction at the designated speed. M04 is usually combined with an S word to define the speed. If an S word is not specified the last spindle speed is used.

M05 – Spindle Stop: Stops spindle rotation.

M06 – Tool Change: Tells the machine to change to a tool number specified by T. The T word must appear in the same block as the M06 or above it in the program. For example:

# Safe start line
G0 G90 G54 G17 G40 G49 G80
# Rapid move, pre call tool 1
G0 X4.0 Y0.0 Z1.0 T1 
# Tool change to tool 1
M6
# Rapid move
G0 X10.0 Y-5.0 Z1.0
# Tool change to tool 2
T2 M6
# Program end and rewind
M30 

M07 – Mist Coolant On: Turns on the mist coolant output.

M08 – Flood Coolant On: Turns on the flood coolant output.

M09 – All Coolant Off: Turns off all coolant outputs.

M19 – Spindle Orient: Although this code is not built into Mach and is completely user defined, it is required to orient the spindle for some machining cycles, G76 and G87 for example. Tool changers usually will require a spindle orientation, and although this orientation could be any M code defined by the user or even built into the M6, M19 is recommended as it is an industry standard M code. Usually, it would call the spindleorient.mcs macro

M30 – Program End and Rewind: Ends the current program and rewinds back to the beginning. Pressing the cycle start button will start program execution from the first block. All defaults (G54, G17, G90, etc.) will be reset.

M48 – Enable Feedrate/Spindle Speed Overrides: Enables the feedrate and spindle speed overrides after an M49 has been issued.

M49 – Disable Feedrate/Spindle Speed Overrides: Disables the feedrate and spindle speed overrides. This can be beneficial in production environments and also in programs or macros that are sensitive to feedrate and spindle speed by preventing accidental overrides.

M62 – Synchronized Output On: Turns on an output synchronized with the start of the next motion command. If no motion is commanded, the output will not turn on. It is best to specify motion immediately following the M62 command.

Format: M62 P__

P specifies the output number to turn on. For example: Output0 = 0, Output3 = 3, Output10 = 10, etc.

M63 – Synchronized Output Off: Turns off an output synchronized with the start of the next motion command. If no motion is commanded, the output will not turn off. It is best to specify motion immediately following the M63 command.

Format: M63 P__

P specifies the output number to turn off. For example: Output0 = 0, Output3 = 3, Output10 = 10, etc.

M64 – Immediate Output On: The specified output is turned on immediately.

Format: M64 P__

P specifies the output number to turn on. For example: Output0 = 0, Output3 = 3, Output10 = 10, etc.

M65 – Immediate Output Off: The specified output is turned off immediately.

Format: M65 P__

P specifies the output number to turn on. For example: Output0 = 0, Output3 = 3, Output10 = 10, etc.

M66 – Wait for Input: When specified, program execution will be paused until the selected input is activated. There are 5 wait modes:

  • Mode 0: No wait. Current state of the input is written to #5399: low = 0, high = 1.
  • Mode 1: Wait for the input to change state from low to high. If the input is high when called, the program will wait until the input goes low, then back to high.
  • Mode 2: Wait for the input to change state from high to low. If the input is low when called, the program will wait until the input goes high, then back to low.
  • Mode 3: Wait until the input is in the high state. If the input is high when called, the program will immediately continue.
  • Mode 4: Wait until the input is in the low state. If the input low when called, the program will immediately continue.

Format: M66 P L Q__

P specifies the desired input number. For example: Input0 = 0, Input4 = 4, Input12 = 12, etc.

L specifies the mode, 0 thru 4.

Q specifies how long to wait, in seconds, for the input. If the mode is not satisfied in the specified time then #5399 will be set to -1.0 and program execution will continue.

M98 – Subprogram Call: Subprograms are external programs referenced by the current running program. When called program execution will continue in the subprogram. This allows the user to reduce program length and complexity by providing the ability to easily repeat sections of code, run the same section of code in multiple locations or in multiple fixture offsets, the possibilities are limited only by the programmer. To call a subprogram command M98 with the program number as shown.

Format: M98 P__ Q L__

P specifies the number of the program to be called. This is a four digit integer number. When the M98 is read Mach scans the current file for a block containing the program number in the following form:

Format: O1234

Note that the letter “O” is used to specify the program number 1234, NOT the number “0”. Program execution will continue with the block following the O number. For this method the subprogram should be below the end of the current program:

# Main program header
(MAIN PROGRAM)
# Safe start line
G0 G90 G54 G17 G40 G49 G80 
# Rapid move
G0 X4.0 Y0.0 Z1.0 
# Tool change to tool 1
T1 M6 
# Rapid move
G0 X10.0 Y-5.0 Z1.0 
# Call subprogram number 1000
M98 P1000 
# Program end and rewind
M30 
# Subprogram number
O1000 (SUB PROGRAM BEGIN)
# Cut circle 
G12 I-0.25 
# Return to main program
M99 

There are limitations to this method; mainly the subprogram must be pasted into every program that it is to be called from. Mach also allows a subprogram to be called from an external file. This way, multiple programs can call the same subprogram, without having the program in the main file. If a change needs to be made to the subprogram it only needs to be done in one file, not every file in which the sub is called. If the control does not find the program number in the current file it will then search for it in the Mach4\Subroutines directory. This time it will be searching filenames. The files in this directory should be named with the program number as follows:

Format: O____

Note the letter “O” followed by four numbers, and no file extension; O1234 not O1234.txt. When the program is loaded this file will be found and loaded into the memory, the tool path display will reflect what is in the subprogram. When running the file the M98 block will be read and program execution will continue with the first block of the subprogram file.

The arguments Q and L are optional. Q specifies the sequence number in the subprogram to start at. If Q is omitted then execution will start at the beginning of the sub program; see figure 198-1. L is the number of repetitions. For example, if L=2 the subprogram is run two times before execution of the main program continues. If L is omitted the program will run only once.

Figure 198-1

Figure 198-1 Mach4 M-Codes Guide

M99 – Return From Subprogram / Rewind: To return to the main program from a subprogram an M99 is used.

Format: M99 P__

M99 specified in a subprogram will return to the main program at the block immediately following the M98 subprogram call. The addition of a P in the M99 block will return to a desired sequence number in the main program. See figure 199-1.

Figure 199-1: Return from sub program

Figure 199-1 Mach4 M-Codes Guide

If M99 is specified in a main program (not in a subprogram) a program rewind is performed. Execution will continue from the first block of the program.

Custom M Codes: Every machine is a little different and has different functions and options. Custom M codes allow the user to create simple programming calls for complex processes, activating or deactivating outputs, reading inputs, performing math, or whatever else the user and machine could require. These M codes are programmed in Lua and placed in the macros folder under each profile. Every profile can have its own unique set of M codes. The file name must be the macro to be called. For example to make a tool change macro, M6, add a Lua script with the filename M6.mcs to the macros folder in the desired profile. When an M6 is called in a program or in MDI the macro will be executed.