A cellular automaton (CA) based model for two-dimensional simulation of the grain morphology of high pressure die casting magnesium alloy was developed. The heterogeneous nucleation, the solute redistribution both in liquid and solid, the interface curvature and the growth anisotropy during solidification were also considered in the model. By fitting the curve of grain density distribution, parameters of continuous nucleation equation based on Gaussian distribution were calculated. The microstructure simulation of step-shape die castings of AM50 magnesium alloy was studied. The metallographic microstructure of the castings at the surface and center of three steps with different initial die temperature was investigated. The simulation results were compared with the experimental results and they were in good agreement on average grain size.