A one-dimensional seasonal energy balance climate model has been developed for the Martian surface and coupled to a model of CO2 distribution between atmosphere, regolith, and polar caps. This model takes into account the greenhouse warming of carbon dioxide, the meridional transport of heat, the CO2 condensation and sublimation cycle, and its adsorption in the regolith. The model takes into consideration the diurnal variation of solar irradiation, since it is shown that disregard of this effect yields temperatures too high by several degrees. The yearly-averaged temperatures calculated from this climate model at different obliquities are used to estimate the importance of CO2 exchanges between the regolith and atmosphere-cap systems during the obliquity cycle. For this purpose, the equation of thermal diffusion into the ground is solved for each latitude belt. The results differ substantially from those of previous studies, due in part to the consideration of the diurnal and seasonal variations of the solar irradiance. The model shows the importance of taking these short-period variations into account instead of using yearly-averaged quantities, due to the strong nonlinearity of the climate system on Mars. The roles of meridional heat transport and greenhouse warming are analyzed and shown to be important. For example, a permanent polar cap of carbon dioxide is destroyed by heat transport when the obliquity is high, while at low obliquity, high-pressure systems without permanent cap can exist if enough exchangeable carbon dioxide is available. Further, the results show the possible existence of hysteresis cycles in the formation and sublimation of permanent deposits during the course of the obliquity cycle.