From the Emergency section in the Jepps manual.
2.4.1 The pilot of an aircraft encountering a
state of emergency shall set the transponder to
Mode A Code 7700 except when previously directed
by ATC to operate the transponder on a specified
code. In the latter case he shall maintain the specified
code unless otherwise advised by ATC. (Doc
8168, Vol I, Part VIII, 1.4.1)