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 (u1RGBpwm.hex)
- 8-bit PWM: u1RGBpwm8bit.jal (u1RGBpwm8bit.hex)
- 4-bit exponential PWM: u1RGBpwmE.jal (u1RGBpwmE.hex)
Sample VB code and test application: 628SendRGBTestDR1r3.zip


May 3rd, 2007 at 5:34 am
Hi, Can you post asm for mplab?I don’t understand JAL.
thank you
May 3rd, 2007 at 10:19 am
I forgot: I like to store last data for next time power on. Can you help me?
Tomy
May 4th, 2007 at 3:38 pm
#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.
May 5th, 2007 at 1:49 am
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
May 13th, 2007 at 11:38 pm
#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!
July 15th, 2007 at 3:15 am
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
October 23rd, 2007 at 11:15 pm
HOW CAN I GET THE JAL
March 29th, 2008 at 8:04 am
Hi!
What would the code an the schematic look like for RGB LEDs that have an common anode?
Thank you
Rupert
September 11th, 2008 at 5:40 pm
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?