We report on a method to quantitatively measure the local energy distribution of surface states density within the band gap of semiconductors using Kelvin probe force microscopy. The method is based on measuring the contact potential difference of a cross-sectional $pn$ junction; as the tip scans the junction surface, the surface states population changes, thus modifying the measured local surface band bending. The energy distribution is then obtained by fitting the calculated surface potential to the measured contact potential difference. The method is applied to ${p}^{++}n$ and ${n}^{++}p$ Si (110) surfaces and ${p}^{++}n$ InP (110) surfaces measured under different environments. The results are compared to data obtained by theoretical models and other experimental methods.