Long-term evolution of the spin of Mercury. I. Effect of the obliquity and core-mantle friction