Dependence of the 27-day variation of cosmic rays on the global magnetic field of the Sun