In the event of an emergency, pilots should transmit the following codes appropriate to their status:
EMERGENCY - Mode 3A Code 7700 (except that aircraft already receiving an air traffic service and transmitting a code normally retain the code in use - see discussion below)
COMMS FAILURE - Mode 3A Code 7600
UNLAWFUL INTERFERENCE - Mode 3A Code 7500
Aircraft already receiving an air traffic service, and transmitting a code, should retain the code in use. Aircraft in an emergency, who are not receiving an air traffic service should set the transponder to EMERGENCY (Mode 3A Code 7700) as part of their initial actions.
"A pilot may select Mode 3A Code 7700 whenever he has specific reason to believe that this would be the best course of action" [ ICAO Doc 8168 Vol 1.]