9.9 PROJECT 9.9 – LED Candle

9.9.1 Project Description

In this project we design an LED candle – an LED that imitates a burning real candle. The operation of the project is such that a PWM waveform is sent to the LED with random duty cycle. Because of this randomness, the LED lights up and flickers such that it looks as if it is a real candle.

9.9.2 Block Diagram

The block diagram of the project is as shown in Figure 9.3.

9.9.3 Circuit Diagram

The circuit diagram of the project is as shown in Figure 9.4, except that the LED is connected to port pin CCP1 (pin RC2 in PIC18F45K22 microcontroller) via a current limiting resistor.

9.9.4 Project PDL

The PDL of this project is given in Figure 9.53.

Figure 9.53 PDL of the project

img

9.9.5 Project Program

The program is named LED17.C and the program listing of the project is shown in Figure 9.54. At the beginning of the main program, PORT C has been configured as digital output and Timer 2 and PWM modules have been configured to generate a PWM waveform on pin CCP1 (RC2) with a period of 2000 μs. A pseudorandom number generator function has been created.

Figure 9.54 Program listing of the project

img

The program operates in an endless loop created with a for statement. Inside this loop, a small delay is added between each iteration to slow down ...

Get Using LEDs, LCDs and GLCDs in Microcontroller Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.