Maintain compas heading when turned on

Is there a way to have set things up so as when the pilot is turned on it simply holds the current compass heading until turned off ?