PIC16F628 Serial 1 RGB LED PWM Controller

This code is for a simple RGB LED controller for 1 LED using a PIC16F628 that has PWM control for the LED. It is controlled by sending 2 bytes to the PIC’s internal USART for the intensities of the red, green, and blue color channels. The operation is very simple and so is the wiring. The PIC loops and turns on the respective colors if they are less than or equal to theCount. Because of persistence of vision, the eye sees the LEDs as all being on at the same time. The 4-bit code below has 15 linear values of PWM. The 8-bit code has 255 linear values of PWM. The 4-bit exponential PWM code has 15 values fit to an exponential curve. This allows for more “even” color levels because the human eye does not readily perceive linear changes in light intensity. For LED applications, the 4-bit exponential code is recommended.

The microcontroller code can be downloaded here:
– 4-bit PWM: u1RGBpwm.jal (hex)
– 8-bit PWM: u1RGBpwm8bit.jal (hex)
– 4-bit exponential PWM: u1RGBpwmE (hex)

Sample VB code and test application: 628SendRGBTestDR1r3.zip

10 thoughts to “PIC16F628 Serial 1 RGB LED PWM Controller”

  1. #1 & #2 (tomy) – Unfortunately I don’t have the assembly for this project. However the JAL language is very similar to PASCAL and I’d be more than happy to step you through the code to explain what it does. Also, yes, it would be quite easy to store the data for the next power on. All that you would have to do is store the values in EEPROM every time they change.

  2. Thank you!
    Because I can’t to modify code myself, can you do it for me?I like 8 bit version.I’m beginner so is too difficult for me to start with jal, because I still learn in mplab.
    Sorry , my English is bad…
    Tomy

  3. #4 (Tomy) – I’ve emailed you the recompiled C files and corresponding hex files for a modification that saves the PWM to the EEPROM when they change. Please let me know if they work!

  4. Hi Steve,
    Sorry I’m late, but codes does not work. Can you add button “store” to vb code,
    and data will be stored to eeprom only when this button will be pressed?
    Maybe this is easier way.
    Thank you!
    Tomy

  5. Hi!
    What would the code an the schematic look like for RGB LEDs that have an common anode?

    Thank you
    Rupert

  6. I’m having a bit of difficulty with the code to this, every time I send a serial command the change is not smooth and the led’s flicker on and off (I have a VB app that is trying to do smooth fades up and down)…do you have any ideas what I can do?

Leave a Reply to AdamCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.