This code supports Application Note AN1138: A Digital Constant Current Power LED Driver, using the PIC12HV615? an 8-pin, PIC microcontroller (MCU) with many integrated analog features. The LED driver circuit is a buck (stepdown) solution and the circuit presented here can operate from most any input voltage source as long as it exceeds the forward voltage of the LEDs to be driven. A proportional-integral (PI) controller algorithm is used to regulate the LED current to a constant value. The PI controller is executed at a rate of 976 Hz, leaving plenty of CPU time available for other tasks. Although this sample rate would provide inadequate control response for most power supply applications, it works well for LED applications because the LED presents a constant load to the power stage. Therefore, the controller does not need to make frequent adjustments. The LED current is sampled using a resistor in series with the source of the MOSFET in the buck circuit and amplified using a single op amp. The LED current is sampled using one of the available ADC inputs on the PIC12HV615. The Enhanced Capture Compare PWM (ECCP) module of the MCU is used in PWM mode to drive the buck circuit. Since the MCU has an internal voltage regulator and 8 MHz oscillator, very few external components are required to complete the circuit.