The interaction between substitutional nitrogen atoms in graphene is studied by performing first principles calculations. The nearest neighbor interaction between nitrogen dopants is highly repulsive because of the strong electrostatic repulsion between nitrogen atoms, which prevents the full phase separation in nitrogen doped graphene. Interestingly, we find that there are two relatively stable nitrogen-nitrogen pairs due to the anisotropy charge redistribution induced by nitrogen doping. Our calculations reveal two stable semiconducting ordered N doped graphene structures C3N and C12N. In particular, C12N has a direct band gap of 0.98 eV. The heterojunctions between C12N and graphene nanoribbons might be promising new organic solar cells.