Generation of solar spicules and subsequent atmospheric heating