Principles of Solar Cells, LEDs and Diodes: The role of the PN junction