Project: PIC LED Sequencer

Thread Starter

MMcLaren

Joined Feb 14, 2010
861
For my very first project submission I'd like to present a relatively simple PIC based LED sequencer project. By "relatively simple" I mean each LED is directly driven from an I/O pin, and while this method generally uses more pins when compared to multiplexing to drive the same number of LEDs, it does make the PIC program much simpler.



Prerequisites
While you don't need to be a micro controller expert to build this project and create nifty LED FX (effects), you will need the (free) Microchip MPLAB IDE (integrated development environment) installed on a PC and a programmer such as the PICKIT2 to "burn" the program which contains your LED 'FX' sequences into the PIC device. You also need the basic skills and tools necessary to build the project on a solderless breadboard or a prototype board.

Hardware
While the project requires very few parts, you need to decide how you want to build it. I used an inexpensive phenolic prototype board available from Radio Shack (sku 276-149) with a plastic coated paper silkscreen glued onto the top, but you might decide to build the circuit on a solderless breadboard or perhaps etch your own printed circuit board.



Rich (BB code):
Parts List

1 ea. - C1, 0.1uf monolithic ceramic capacitor
8 ea. - D1-D8, generic discrete LED
8 ea. - R1-R8, 470 ohm, 1/8th watt carbon film resistor
1 ea. - R9, 10 kohm, 1/8th watt carbon film resistor
1 ea. - SW1, generic PCB momentary contact switch
1 ea. - U1, PIC16F628A micro controller
1 ea. - prototype board or solderless breadboard
1 ea. - regulated 5 volt D.C. power source
Software
The program is designed to continuously display LED sequences contained in one of eight FX (effects) tables. Each table can contain up to 255 sequences or steps and each step contains two parts, (1) the LED <pattern>, and (2) the <duration> for that pattern. The <pattern> part of each step is simply eight bits which match the position of the eight LEDs on the project board. A '1' bit will turn an LED on while a '0' bit will turn an LED off. The <duration> part of each step must contain a value from 1 to 255 which corresponds to the time the pattern will be displayed in 10-ms increments (1..255 duration = 10..2550 msecs) before going on to the next step. When the program has finished displaying the last step in an FX table, it wraps around to start again at the first step in that table. When you press the push button switch, the program will move on to displaying the next FX table. Here's what one of the program FX tables looks like (for a Knight Rider type effect);

Rich (BB code):
fx2
        dt      (fx3-fx2)/2     ; <steps>                         |B0
        dt      b'00000001',8   ; <pattern>, <duration>           |B0
        dt      b'00000010',8   ;                                 |B0
        dt      b'00000100',8   ;                                 |B0
        dt      b'00001000',8   ;                                 |B0
        dt      b'00010000',8   ;                                 |B0
        dt      b'00100000',8   ;                                 |B0
        dt      b'01000000',8   ;                                 |B0
        dt      b'10000000',8   ;                                 |B0
        dt      b'01000000',8   ;                                 |B0
        dt      b'00100000',8   ;                                 |B0
        dt      b'00010000',8   ;                                 |B0
        dt      b'00001000',8   ;                                 |B0
        dt      b'00000100',8   ;                                 |B0
        dt      b'00000010',8   ;                                 |B0
fx3
Using MPLAB, the user can edit or modify any line in an FX table or insert and delete lines in an FX table and the program will automatically keep track of the number of steps in each table.

Summary
Short of teaching someone how to use MPLAB, which is beyond the scope of this article, feel free to ask questions if, as I suspect, I've left out some important piece of information.

Cheerful regards, Mike
 

Attachments

Wendy

Joined Mar 24, 2008
23,429
Nice job! It is approved. I'll post a link in the index ASAP.

Much better submission than most. It sets the standard.

I put it in the Lighting, LED Flashlights, Etc catagory.

If you want me to move it to the Microprocessors / Micro Controllers class let me know.
 

Georacer

Joined Nov 25, 2009
5,182
Neat project, very compact.

I wonder: Am I the only one who uses stripped wires on the underside of the perfboard? I feel they 're more manipulable this way.
 

Wendy

Joined Mar 24, 2008
23,429
I like the insulation. I did buy some specialty teflon ultra fine wire though, both 28 and 30 gauge. Teflon won't melt when soldered, but it is expensive and soft (cold flows).
 

DerStrom8

Joined Feb 20, 2011
2,390
Well done, MMcLaren.

@Geo, I use insulated wire for a few reasons--One, it prevents shorts, two, it prevents shorts, and three, it prevents shorts. :D:p
 

gerty

Joined Aug 30, 2007
1,305
Am I the only one who uses stripped wires on the underside of the perfboard
I use 30 gauge wire wrap wire (insulated) for jobs like this. I use standard sockets and solder the connections.

Edit: here's a couple of lousy pics of the sequencer we made in class here for future students to learn programming.
It shows the type of wire I'm referring to.
 

Attachments

Last edited:

Thread Starter

MMcLaren

Joined Feb 14, 2010
861
While a printed circuit board (PCB) would be best, using 30 gauge kynar wire-wrap wire for these little point-to-point wiring projects does work quite well. The same wiring method will be used on an upcoming project board (preview below).

Cheerful regards, Mike
 

Attachments

tracecom

Joined Apr 16, 2010
3,944
I am a complete novice to PIC programming, so the answer to this question may be obvious to everyone but me. When I try to build the project, it fails with the following report.

Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 182 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 182 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 183 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 183 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 184 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 184 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 185 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 185 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 186 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 186 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 187 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 187 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 188 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 188 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 189 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 189 : Operand contains unresolvable labels or is too complex
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\Documents and Settings\Charles R. Hampton\Desktop\PIC MCU's\CRH Project Files\MPASM Playtime Projects\PIC16F628A LED Sequencer.mcp' failed.
Language tool versions: MPASMWIN.exe v5.43, mplink.exe v4.41, mplib.exe v4.41
Preprocessor symbol `__DEBUG' is defined.
Tue May 08 15:06:34 2012
----------------------------------------------------------------------
BUILD FAILED

The errors seem to point to this section of the code.

Rich (BB code):
;******************************************************************
;  directory of fx tables (index 0..7 -> fx1..fx8)                *
;******************************************************************
fxdir
        dt      fx1%256,fx1/256 ; fx1 array address               |B0
        dt      fx2%256,fx2/256 ; fx2 array address               |B0
        dt      fx3%256,fx3/256 ; fx3 array address               |B0
        dt      fx4%256,fx4/256 ; fx4 array address               |B0
        dt      fx5%256,fx5/256 ; fx5 array address               |B0
        dt      fx6%256,fx6/256 ; fx6 array address               |B0
        dt      fx7%256,fx7/256 ; fx7 array address               |B0
        dt      fx8%256,fx8/256 ; fx8 array address               |B0
Can someone tell my why and how to fix the problem? Thanks.
 

DerStrom8

Joined Feb 20, 2011
2,390
I am a complete novice to PIC programming, so the answer to this question may be obvious to everyone but me. When I try to build the project, it fails with the following report.

Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 182 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 182 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 183 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 183 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 184 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 184 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 185 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 185 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 186 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 186 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 187 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 187 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 188 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 188 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 189 : Operand contains unresolvable labels or is too complex
Error[151] C:\DOCUMENTS AND SETTINGS\CHARLES R. HAMPTON\DESKTOP\PIC MCU'S\CRH PROJECT FILES\MPASM PLAYTIME PROJECTS\16F628A LED SEQUENCER.ASM 189 : Operand contains unresolvable labels or is too complex
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\Documents and Settings\Charles R. Hampton\Desktop\PIC MCU's\CRH Project Files\MPASM Playtime Projects\PIC16F628A LED Sequencer.mcp' failed.
Language tool versions: MPASMWIN.exe v5.43, mplink.exe v4.41, mplib.exe v4.41
Preprocessor symbol `__DEBUG' is defined.
Tue May 08 15:06:34 2012
----------------------------------------------------------------------
BUILD FAILED

Can someone tell my why and how to fix the problem? Thanks.
Could you post your present code, please?

I think your problem is that you're building the program as relocatable code. If you change it in MPLAB to absolute code, it shouldn't give you the error. I may be wrong, but it's worth a shot.
 
Last edited:

tracecom

Joined Apr 16, 2010
3,944
Could you post your present code, please?

I think your problem is that you're building the program as absolute code. If you change it in MPLAB to relocatable code, it shouldn't give you the error. I may be wrong, but it's worth a shot.
I think I chose relocatable code, but I could be wrong.

I tried to post the code, but it exceeds the 10000 character limit. It's the code that was attached to the original post in this thread.
 

tracecom

Joined Apr 16, 2010
3,944
Sorry, please read my edited post. I had relocatable and absolute backwards. :rolleyes:
OK, I just changed it to absolute and it compiled. :confused: What I don't know about programming PICs is limitless.

So, I programmed the chip. Now, I have to disconnect the wires that were connected to pins 12 and 13, and use those pins (plus others) to connect to LEDs per the schematic. Correct?
 

DerStrom8

Joined Feb 20, 2011
2,390
OK, I just changed it to absolute and it compiled. :confused: What I don't know about programming PICs is limitless.

So, I programmed the chip. Now, I have to disconnect the wires that were connected to pins 12 and 13, and use those pins (plus others) to connect to LEDs per the schematic. Correct?
if 12 and 13 are PGC and PGD, and you want to use them as ports, then yes-- You'll need to disconnect your programmer from the circuit in order for it to work.
 
Top