Context. With the Herschel Space Observatory, lines of simple molecules (C + , O, and high-J lines of CO, J up 14) have been observed in the atmosphere of protoplanetary disks. When combined with ground-based data on [C i], all principle forms of carbon can be studied. These data allow us to test model predictions for the main carbon-bearing species and verify the presence of a warm surface layer. The absence of neutral carbon [C i], which is predicted by models to be strong, can then be interpreted together with ionized carbon [C ii] and carbon monoxide. Aims. We study the gas temperature, excitation, and chemical abundance of the simple carbon-bearing species C, C + , and CO, as well as O by the method of chemical-physical modeling. Using the models, we explore the sensitivity of the lines to the entering parameters and constrain the region from which the line radiation emerges. Methods. Numerical models of the radiative transfer in the lines and dust are used together with a chemical network simulation and a calculation of the gas energetics to obtain the gas temperature. We present our new model, which is based on our previous models but includes several improvements that we report in detail, together with the results of benchmark tests. Results. A model of the disk around the Herbig Be star HD 100546 is able to reproduce the CO ladder together with the atomic finestructure lines of [O i] and either [C i] or [C ii]. We find that the high-J lines of CO can only be reproduced by a warm atmosphere with T gas T dust . The low-J lines of CO, observable from the ground, are dominated by the outer disk with a radius of several 100 AU, while the high-J CO observable with Herschel-PACS are dominated from regions within some tens of AU. The spectral profiles of high-J lines of CO are predicted to be broader than those of the low-J lines. We study the effect of several parameters including the size of the disk, the gas mass of the disk, the PAH abundance and distribution, and the amount of carbon in the gas phase. Conclusions. The main conclusions of our work are (i) only a warm atmosphere with T gas T dust can reproduce the CO ladder. (ii) The CO ladder together with [O i] and the upper limit to [C i] can be reproduced by models with a high gas/dust ratio and a low abundance of volatile carbon. These models however produce too small amounts of [C ii]. Models with a low gas/dust ratio and more volatile carbon also reproduce CO and [O i], are in closer agreement with observations of [C ii], but overproduce [C i]. Owing to the uncertain origin of the [C ii] emission, we prefer the high gas/dust ratio models, indicating a low abundance of volatile carbon.