PIC Fx-1


Home


 
Kits are available for this project from Talking Electronics for $12.00 plus postage.

You will also need:
PIC2 USB Burner
(MPASM and MPLAB come with PIC2)
and it includes USB lead
PIC Burner board $7.00

PIC12F629 Data Sheet (.pdf  4,926KB)
Instruction Set for PIC12F629
blank12F629.asm template

PIC12F629.inc

See more projects using micros:
Elektor,EPE,Silicon Chip

Notepad2.zip     Notepad2.exe 
Library of Sub-routines "Cut and Paste
"
Library of routines:   A-E   E-P    P-Z 

P2 - The Instructions
P3 - writing your own program
 

Use this project to burn your own chips for:
PIC DICE
XXXX
Build Logic Probe/Pulser
(slimline) $8.00 kit, to check the operation of the add-on circuits you design. 

You will also need:
- PIC Burner Board.   We will not be using the pins at the top of the PCB but burning the chip on the PIC Burner PCB and transferring it to the project. 

You will learn:
- PIC micro programming
- Design and build interface stages for input and output devices
- Build and use a Logic Probe to test circuit operation
- "Burn" (flash) (program) PIC chips using onboard ICSP pins
- Build additional projects using PIC micro's
- Get $1,000 worth of electronics skill for $50.00 !!!

 
"PIC Fx-1" is a DEVELOPMENT PLATFORM - a Prototyping Module.
It's a small board containing an 8-pin microcontroller and a matrix area for experiments.


$12.00

It's very similar to the original BASIC stamp-1, developed in about 1993 to get beginners into the world of programming.  The experimental section had no supply rails and a very awkward matrix-layout. A matrix layout needs to be long and thin as that is the way a circuit extends. There was no on-off switch and you had to constantly clip the battery to the battery-snap. My BASIC Stamp remained in pristine condition because it came with no components for experimenting and "did-nothing" when turned ON. On top of this I very soon realised the programming had nothing to do with PIC microcontrollers.  


$30.00

We have taken the concept and made it even simpler by providing "cut-and-paste" sub-routines and removed the need to learn a programming language.
The end result is more value for your money with a much-simpler approach to programming. And your program can be about 4 times larger.

The BASIC Stamp came "empty" and you had to download programs to see any results. PIC Fx-1 comes with 4 main PROGRAMS for the 3 input switches and 3 output LEDs.
You can see what can be done with a micro as soon as you assemble the kit.  The second part of this article teaches you how to produce a program by cutting and pasting sub-routines into a template.
This is how you create a program. You actually use the instructions needed by the micro (not a programming language called a "high-level language"). Only 35 instructions are needed for the micro and they are provided in a single-page layout, for easy access. 
You regularly use only about 20 of these and they are in the "cut-and-paste" code you take from other programs and also from the LIBRARY OF ROUTINES.
In most cases you go to a project and take the code that performs the function you require.
You place it in the sub-routine area of the template and CALL it from the MAIN routine.
Once your program is complete, it is "burnt" or "flashed" into the memory of the micro (called the program memory section) via a programmer (called USB Programmer) using the In-Circuit programming pins at the top of the board.
This will erase the programs supplied in the chip, so additional chips are recommended if you want to write your own programs.
The chip on the board comes fully programmed with the LED Fx-3 program (with more than 10 effects), plus 3 extra programs: Code Lock, Reaction Timer and  4-Alarm Sounds.
The 10 effects on the 3 LEDs include flashing, dimming and random flickering and you can produce your own sequence on the LEDs and store it. All these program use only 65% of the memory. That's how much you can get into a very small microcontroller. Only one of these program would fit into the BASIC Stamp due to the micro being filled without routines that are not needed and you program had to be fitted into an external chip that was limited to a maximum of about 80 instructions. Our 4 programs require about 600 instructions.
You cannot compare the two via the number of instructions as the BASIC Stamp can multiply an instruction to between 2 and 20 PIC instructions. However the BASIC Stamp may take 2 to 4 locations to hold an instruction (and up to 10 locations). So, the BASIC Stamp-1 runs out of programming capability very quickly and in the past 20 years we have only seen very small projects using it. That's why they upgraded their range to much larger PIC chips.
But our aim is not to compare or contrast our concept with any of the other modules on the market as they are fulfilling a need to get a simple project up-and-running via a micro.
We are showing HOW to PROGRAM, How the Micro Works and how 1,024 lines of code (instructions) can be used to produce very impressive projects.
   

Go to P2 for: "learning to write your own programs."  It has a set of experiments to teach PIC programming - starting with
flashing a LED.

The CIRCUIT
The circuit is very simple. It is just a micro, 3 LEDs and 3 switches. All the work is done by the micro.
We have added a 5v regulator so the project can be connected to any voltage from 7v to 15v.
It will work on 6v if the regulator is removed and a diode is placed between the "in" and "out" pads or on 7v to 15v DC with the regulator fitted to the board.
This makes it suitable for a 9v battery or the DC supply from a model railway.

The 5 In-Circuit Programming pins allow you to program the chip while it is in-circuit.


PIC Fx-1
PCB
The Matrix section is 21 holes x 10 holes

The matrix section is longer than shown and provides plenty of space to add components and design your own interface stages to drive motors, LCD displays, servo's, piezo's etc.  
Driving many of the output devices have already been covered in other projects, so you don't have to "re-invent the wheel." You just copy the required instructions into your own program.


The Complete PIC FX-1 Project.
The top and bottom lands are positive and negative rails


These pins are not used - the project has been updated
and we now use the PIC Burner board and transfer the chip
after it has been burnt

 

to USB Programmer to 9v battery

This connector-board is not used  - We now use the PIC Burner module


CONSTRUCTION
Build the project on the PC board provided in the kit. All the components are supplied, including parts for the experiments.
There are two things to note.
The 100u electrolytic is replaced with a 10u tantalum soldered under the board. The lands can just be seen at the edges of the component and by tinning the pads first and using a little fresh solder, the tantalum will solder very nicely to the pads. The other item to note is the link to pin-1 of the micro. This track is missing from the board and must be connected via a short length of fine tinned copper wire (included in the kit). The 5 programming pins are called "machine pins" and are soldered directly to the top of each land by adding a little solder to the land and the hollow end of the pin.
To make soldering these pins in place, insert a pin into the end-pin on the 5-pin connector and use it to place the pin onto the land you have  just added a small amount of solder to. Heat the pin and it will be soldered in place. Remove the 5-pin connector and add another pin to it. Re-connect the 5-pin connector and locate the next pin to the pre-tinned land. Solder it in place.
Repeat until all 5 pins have been added to the board.

SURFACE-MOUNT COMPONENTS
To make the PC board as small as possible, we have used surface-mount components. You will need fine tweezers to hold them in place while one end is soldered.
Always use very fine solder (as supplied in the kit) as you only need very little for each component and the main reason for adding extra is to take advantage of the flux to clean the connection. Always solder the SM resistors with the value showing.

PIC Fx  Modification
Turn the PC board over and connect the middle 47k and the end 47k surface mount resistors to the 22k resistor as shown in the image.


The surface mount components are clearly identified
820 on chip  = 82 and no zero's
223 = 22 + 000 = 22,000 ohms
4702 = 47 + 0 + 00 = 4700 ohms

THE LEDs
The LEDs supplied in the kit are high-bright 3mm white LEDs that take less than 17mA to achieve full brightness.  You can change them for other colours to suit your own application. The 82R dropper resistors will have to be increased to 220R (221 on a chip resistor) for any other colour.

TESTING
When you have constructed the project, you can tests its features:

Turn the project ON and the LEDs will “chase.”
Turn the project OFF and push button A and keep it pressed while you turn the project ON.  Now press button A 3 times and each time the LED will illuminate. Now stop and wait.   The LED will flash 3 times.
 Turn the project OFF and push button A and keep it pressed while you turn the project ON.  Now press button B once and wait.  The middle LED will flash.
Now do the same will all sorts of button sequences (up to 15) and see how the project responds.
Keep the micro and use another micro for your experimenting.


THE PROGRAMS
The 3 programs contained in the chips that comes with the kit of parts has a single program with sub-routines for the 3 programs.
The micro starts in the Set-Up routine and looks for the press of button A, B or C to go to the required section of the program.
If NO button is pressed, the micro goes to LED Fx-3 routine.
This allows four separate projects to be included in a single chip. This concept is very handy for a programmer to be able to get into a program (after installation) and change data values. The data values are stored in EEPROM  - more on this concept, later.

LED Fx-3
This program produces a number of flashing LED effects and can be set so that any of the sequences will show when the module is first turned on.
It uses about 400 instructions to produce the effects and the EEPROM is used to store the sequence produced by the user (sequence 1) - and show it at turn-on.
Here are the instructions:
 

INSTRUCTIONS FOR USE
There are 12 sequences.
The first sequence can be created by the user. It currently produces a very slow flash-rate as it has not be programmed. The other 11 sequences are pre-programmed.
Turn project ON.
Allow all the LEDs to flash two times then push the first button (called SwA) and hold it down and the sequence will change to the next sequence.
Release the button and allow the sequence to cycle.
Push SwA again and the sequence will change.
You need to allow each sequence to cycle with the button not-pressed and then push SwA and keep it pressed until a new sequence shows. This is due to the debouncing in the program.


TO CREATE YOU OWN SEQUENCE.
1. Press SwA and at the same time, turn project ON.
2. Release SwA and press the switches in any order (up to 15 steps).  A step or delay cannot be longer than 2 seconds as the program will "time out." When finished, wait 3 seconds and the sequence will show on the LEDs.
3. Turn project off and on. The new sequence will appear as the first sequence.

TO MAKE ANY SEQUENCE THE FIRST SEQUENCE
Any of the sequences can be saved as the first sequence, as follows:
1. Turn the project ON and increment the sequences.
2. To save the desired sequence, press SwB. The display will die.
3. Turn project OFF then ON.  The desired sequence will show at start-up.
4. To delete this feature, push SwC and at the same time, turn project ON.

CODE LOCK
This program is contained in the PIC Fx chip.
It is accessed by turning the project OFF.
Now press the first button.
Turn the project ON.
The first LED will flash to indicate the CODE LOCK program is accessed.

To open the "VAULT" you have to press the three buttons in a particular order.
This project is ideal for a DOOR LOCK.
Normally the code will freeze after 5 attempts, but we have removed this feature to see if you can "break the code."
The answer to the code is revealed at the bottom of this page.

REACTION TIMER
This program is contained in the PIC Fx chip.
It is accessed by turning the project OFF.
Now press the second button and keep it pressed.
Turn the project ON.
The second LED will flash to indicate the REACTION TIMER program is accessed.


This program will test your reaction time.
Press the first button and the first LED will come ON.
Keep the button pressed.
The first LED will remain ON an unknown period of time and when it extinguishes, you must  release the first button and press the third button (with the same finger).
The middle LED will flash to indicate tenths of a second.

4 ALARM SOUNDS
This program is contained in the PIC Fx chip.

It is accessed by turning the project OFF.
Now press the third button and keep it pressed.
Turn the project ON.
The third LED will flash to indicate the 4 ALARM SOUNDS program is accessed.

Press the first button to access the first sound. Press the button again for the second, third and fourth sound. 

 

THE PIC12F6299
The PIC12F629 is one of the smallest microcontrollers in the series that has enormous capability.
The smaller devices are very limited and cost about the same.
The chip has 8 pins.
Two pins are for the 0v and 5v connections. The 5v must not go above 5.5v and can be as low as 3v, but it is best to keep the supply at 5v.
A 100n should be placed next to the chip across the supply rails to make sure the chip works. The chip likes "tight" power rails and the 100n does this.
The chip has an inbuilt 4MHz oscillator and this is divided by 4 so it executes instructions at the rate of one million per second. Each instruction takes one microsecond.
When an instruction tells the micro to go to another part of the program, it takes two cycles (2uS) - called Machine Cycles. This is a skip, goto, call, or return.
The other 6 pins are input/output lines and these can be changed at any time during the running of the program.
The only thing to remember is pin 4 (General Purpose Input / Output) gpio,3 is INPUT ONLY. If you try to make it an output, nothing happens ! 
You can make any combination of pins "inputs or outputs" and this can be changed during the running of a program.
The pins have 3-states called TRI-STATE. Any pin can be HIGH or LOW and when it is configured as an input, it is HIGH IMPEDANCE. In other words it is not connected to anything.
An output pin can deliver up to 25mA and this is called SOURCING. This is enough to illuminate a LED and the white LEDs we have provided in the kit are too bright to look at. When a pin is LOW it can sink about 25mA.
That's all you need to know to get started.

HISTORY 
Let's go back and see how the microcontroller prototyping module started.
It started with Parallax producing a small board with a PIC chip and prototyping area in about 1993. The module cost about $50.00 (with a very large manual) and used a PIC16C56.


BASIC Stamp-1  (1993)

This is a one-time programmable device with one full port of 8 in-out lines and a half-port of 4 lines.
However the 4 lines of the half-port are taken up with connections to the 93LC56 (246 byte EEPROM) to store data and your program instructions and the In-circuit Programming pins. This leaves the 8-line full-port for experimenting.
The BASIC Stamp-1 has 256 bytes of program storage inside the 93LC56 and this is enough for 80 to 100 lines of PBASIC1 code. The PIC12F629 has this feature INSIDE the chip and that's why the extra chip is not needed for the PIC Fx-1 module.
None of the code you produce is placed in the normal programming section of the chip. This area is already taken up by Parallax's set of sub-routines and these routines are accessed by a code written by you and stored in the  93LC56 EEPROM.
This is like buying a diary and having it filled with examples of how to writes stories, essays and poems, and providing 20 pages in a folder, tacked on the the back of the diary, for your own work.
All the unused sub-routines should have been left on your computer and only those needed downloaded into the chip.
But to prevent anyone accessing the sub-routines, it has been contained within the chip and the CODE PROTECT 'bit" activated so the chip cannot be read.
This just leaves the 93LC56 EEPROM for you to use. The instructions written by you are called PBASIC instructions and they take a variable amount of space in the 93LC56 EEPROM. They vary due to the complexities of the command and the type of arguments you supply. Generally, each command takes 2 to 4 bytes of memory space, however, commands like SERIN, SEROUT, LOOKUP and LOOKDOWN, which accept a variable length list of arguments, may take tens of bytes or more.
It is difficult to equate this to lines of ASSEMBLY CODE, when you are programming the micro via the set of 56 instructions that come with the chip, as some PBASIC instructions will be equal to 3 lines of assembly code and others will be equal to more than 20 lines in a sub-routine.
But the main reason I did not use the module, and kept it in pristine condition for the past 20 years was due to the fact that programming the chip  in BASIC had nothing to do with a PIC MICROCONTROLLER.
Any project developed on the BASIC Stamp-1 could not be transferred to a PIC chip as a .hex file and this made the project very expensive.
Since the PIC chip we are using costs less than $2.00 and holds a program of  1,023 instructions, it seems only sensible to develop a Prototyping Module using the smallest PIC chip in the series and show what can be done.
The underlying approach of Talking Electronics is to present simple projects to get everyone STARTED.
The only way to achieve this is to lay everything out and explain things in the finest detail. 
It's no-good including complex words, involved terms or phrases that need a Philadelphia lawyer to interpret.
The BASIC Stamp-1 comes "empty," whereas the PIC Fx-1 modules comes "full."
It has 4 projects already "burnt" into the PROGRAM SPACE and all you have to do is build the project, connect a battery and turn it ON.
It will immediately come ON with LED Fx-3 program and by pressing buttons A, B or C before turning the project ON, you will be able to access the Code Lock, Reaction Timer or  4-Alarm Sounds.
Once you see how much can be fitted into this tiny chip, you will see why we started with such a small device. It's the place to start.
PIC Fx-1 module can duplicate almost all the projects designed for the Basic Stamp-1 that use up to 6 in-out lines. But compare the cost: (about $30.00 for the Basic Stamp-1 module plus $18.00 postage to $12.00 for the PIC Fx-1 Module, plus $6.50 postage from Talking Electronics).
The 4 projects that come with the PIC Fx-1 Module could NOT be fitted in the Basic Stamp-1 because there are over 500 instructions and the Basic Stamp-1 only has room for about 100. That's what limits the  Basic Stamp-1.  Most of the programs in the Stamp Manual and those submitted by readers have been very simple and equate to less than 300 lines of code in an ASSEMBLY PROGRAM.
There is one advantage of using assembly. As you increase the size of a program, you will be able to use some of the previous sub-routines and this will allow you to do a lot more with just a few lines of additional code, as you reach the end of memory. All the programs in the PIC Fx micro only occupy 664 locations, leaving about 360 locations (lines - instructions  -  for another program).
When you write a program in assembly, you are aware of the timing for each of the routines and understand what each line is doing. You are ACTUALLY programming and not writing an entry into your diary by writing the words MY DOG and having the book look up the pages of pre-written text on the features of MY DOG, to explain what is meant. 
No-one has thought of our copy-and-paste technique and that's why they came up with the Basic Stamp-1 concept.
Not only is our concept simpler, but you don't have to learn any language, and you get the full capability of the chip.
Overall, our approach will achieve two things.
It will get a new group of beginners into the world of microcontrollers at very low cost and show how to produce a program to do almost anything you want.
Once you get into microcontrollers, you will NEVER go back to complex discrete componentry.
The PIC Fx-1 Module can replace more than 12 individual chips, as proven by the programs it contains when purchased.
Don't be put-off by the small size. It has 3 inputs and 3 outputs. These can be changed, but to keep things simple, it is best to keep to projects having-up to this requirement.
The main idea is to duplicate projects you have seen in publications and think of your own ideas. You can program the module to carry out these tasks and cut the prototyping area to make the module as small as possible.

 

 

 

 


 

program your own chip or modify the program, the .hex file is available as well as the assembly file, so you can see how the program has been written and view the comments for each line of code.
The PIC12F629 is one of the smallest micros in the range but you will be surprised how much can be achieved with such a tiny micro.
The program contains sub-routines to produce delays, sequences on the display and both read and write EEPROM; jobs that require accurate code - including a special sequence - called a handshaking sequence that prevents the EEPROM being written due to glitches. 
Even a program as simple as this is not easy to put together and to assist in this area, we have provided a whole raft of support material.
Not only do we provide a number of programs with full documentation but our approach to programming is simple.
It involves a method of "copy and paste" whereby sub-routines are taken from previously written code and copied into your program. Any modifications are made in very small steps so that each can be tested before adding more code.
This is exactly how we produce a complex project. Each step is written and tested before adding the next step.
This saves a lot of frustration as it is very easy to add a line of code that is incorrect and get an unsuspected result. 
If you follow our suggestions you will buy a programmer ("burner") called a PICkit-2 if you are using a laptop. It is the cheapest and best on the market and comes with a USB cable and 2 CD's containing the programs needed to "burn" the chip. If you are using a desk-top and/or tower with a serial port, you can use a cheaper programmer called MultiChip Programmer from Talking Electronics. You will also need NotePad2 to write your .asm program. This can be downloaded from Talking Electronics website. You will use LED_FX.asm or LED_FX-asm.txt as a template for your program, plus a 6 pin to 5 pin connector that fits between the burner and the project. This is also available on Talking Electronics website.
As we said before, this project is for medium-to-advanced programmers as it is very compact and does not have in-circuit programming pins.
To be able to modify the chip you will need a programming socket and this can be obtained from one of our other projects that contains the 5 pins for in-circuit programming.
You can then put the chip into the other project to be programmed and modified and re-fit it into this project for execution.

PROGRAMMING LANGUAGE
There are a number of kits, programs and courses on the market that claim and suggest they teach PIC Programming.
Most of these modules and courses use a PIC microcontroller as the chip carrying out the processes, but the actual programming is done by a proprietary language invented by the designer of the course.
Although these courses are wonderful to get you into "Programming Microcontrollers" they do not use any of the terms or codes that apply to the PIC microcontroller family.
All our projects use the 33 instructions that come with the PIC Microcontroller and these are very easy to learn.
We use the full capability of the micro and our pre-programmed chip is less than the cost of doing it any other way.
In addition, anything designed via our method can be instantly transferred to a PIC die and mass produced. And we use all the input pins and all the memory of the chip. The other approaches use less than 25% of the capability of the memory and one of the pins is not available.
In fact it would be difficult to reproduce this project via any of the opposition methods. It would require a larger chip and more expense. 
You can use our method or the opposition. Just be aware that the two are not interchangeable.
Ours is classified as the lowest "form" (level) of programming - commonly called machine code - invented in the early days of microprocessors - and now called mnemonic programming as each line of code is made up of letters of a set of words. The opposition uses a higher level language where one instruction can carry out an operation similar to a sub-routine.
But you have to learn the "higher level language" in order to create a program. And this requires a fair amount of skill and capability.  
It sounds great and it is a good idea. But if you want to learn PIC programming, it does not assist you. It is "a step removed" from learning PIC language. The other disadvantage of the opposition is the "overhead." The 1,000 spaces allocated for your program is filled with pre-written sub-routines. You may require only 10 of these sub-routines but ALL of them are loaded in the memory space. And they take up all the memory.
You have no room for your own program.
To get around this the opposition uses a 93LC56 EEPROM to deliver instructions on how to apply the sub-routines. This provides about 80 powerful instructions using their language called BASIC (or a similar language). 
It's a bit like selling a diary filled with all the paragraphs you need to express yourself, and leaving a few blank pages at the back for you to write single lines such as: see page 24, paragraph 7, see page 63 paragraph 4, to create your diary entries.
A detailed report on the BASIC Stamp-1 is HERE.
It depends on how much you want to be in charge of writing a program. Using our method is like writing your own auto-biography. Using the opposition is like getting a "ghost writer."
When using a higher level language to create a program, you have absolutely no idea how the code is generated for the micro.
In some of the developmental kits, the code is "locked away" and you are NEVER able to access it.
Everything runs smoothly until a fault occurs. With our method you can see the code. With the other methods, you cannot see the code - it's like doing key-hole surgery without the advantage of an illuminated endoscope to see what you are doing.
Everything has its place and our method of hand-assembly is only suitable for very small micros and you will eventually need to "learn a high level language."   The PIC12F629 has over 1,000 locations for code and this equates to more than 20 pages when printed, so this is about the limit to doing things by hand.
But our drive is to show how much can be done with the simplest devices on the market, at the lowest cost.
Anyone can show you high-technology at a high price but this is not where you start and this is not where you get enthusiasm.
We provide the things to get you started. That's the difference.


 

 

OTHER PROJECTS
Many of the ideas you want to do have already been done in our PIC Projects section, such as driving a servo, producing a RUNNING SIGN, a LED chaser, an Audio CRO, a Touch Switch, Displaying letters on an 8x8 matrix. PIC Fx project has been developed for NEW ideas.
Almost any program you want to write will be able to utilize sub-routines that have already been written.
That's why it is best to look at all the projects in the PIC Projects section to familiarize yourself with what has been done.
You can then create a new program by copying and pasting routines onto the new template.
No matter what you are doing, you have to build a program "one small step at a time." This is to avoid frustration.
The biggest problem with any program is interfacing a switch. 
Notes on this are on the website under WRITING A PROGRAM.
The other helpful tip is to produce a marker so you know what the micro is doing.
The marker may be to let you know the contents of a file, or if the micro has executed a certain sub-routine.
To do this you add a small routine to flash a LED or output a tone to a piezo. You must be in control with each new sub-routine you add. It must work before you go on to the nest next addition.
If you think you can write a program, AND IT WILL WORK FIRST TIME, you are better than me and you don't need any advice.
No other site ASSISTS you in writing a program.
They all give the impression that everything will work as soon as you turn on the power.
The only way you can guarantee success is to do things in small steps.

MODIFYING THE
PROGRAM
To write programs or modify the project is a whole new world of learning and is covered in the next pages of this project.
To write a program you will need a PICkit-2 programmer.

The PIC Fx PROGRAM
The PIC Fx program does a bit of detecting when turned on. It detects to see if a bit has been set in EEPROM to tell the micro to go to a required sequence or start with sequence 1.
It also detects if switch A, B or C has been pressed at the instant the project is turned on so that the micro is directed to the sub-routine where the user-sequence can be entered or if the EEPROM bit is to be cancelled or if programs Code Lock, Reaction Timer or 4-Alarm sounds are being accessed.  
All this gets done in the SetUp routine and then the micro goes to one of the routines in the MAIN section of the program.
 
Increments a "jump" file and calls a table where it finds a directive to go to a particular sub-routine.
The sub-routine is executed and the micro goes back to Main where it looks for a release of SwA. This forms part of a key debounce as the key must be fully debounced as it is advancing the micro through the sequences.
To provide a totally reliable debounce, the key is detected as not being pushed for the duration of a whole cycle of a sequence and a separate loop is then executed where the key can be detected as being pushed, to advance the program to the next sequence.
To create your own sequence as sequence1, the project is turned off and SwA pressed while turning the project ON.
This sends the micro to a sub-routine called Attract.
As soon as SwA is released, the program starts to time the duration when a switch is not pressed and it "times-out" after 2.5 seconds.
The program also times the duration when a LED is illuminated. It also accepts 2 or 3 LEDs illuminated at the same time. These are all clever instructions that need to be looked at to see how they operate.
Up to 15 steps can be entered and each step occupies three bytes. The first value identifies the illuminated LEDs, the second byte identifies the ON duration (in increments of 5mS) and the third byte identifies the OFF time.
These 45 bytes are contained in files 30h to 5Fh.
When a switch is not pressed for 2.5 seconds, the program "times out" and sends the values to the EEPROM. It then shows the sequence on the LEDs.
If the project is turned off and on again, this sequence will be displayed as sequence1.
To replace the sequence with something else, simply repeat the steps above.
If you want one of the pre-programmed sequences to appear each time the project is turned on, simply advance through the sequences by pressing SwA and when the desired sequence is playing, push SwB.
This will record your choice. Turn the project OFF then ON again and the chosen sequence will be displayed.
To remove this feature, press SwC when the project is off and at the same time, turn the project ON.
All these feature have been added to the program, one at a time, and it is important to add them in the correct order. For instance, you can only add a removal feature after the initial feature has been produced. Reading and writing to the EEPROM is a most complex operation and the instructions must be laid out as shown in the program, as they include a hand-shaking sequence. When you need this code it is copied and pasted in its entirety, to prevent a mistake.
Nearly every instruction has a comment to explain not only what it does, but why it was chosen.
If you think you can start programming without reading programs from other developers, you are wasting your time.
No individual can work how to do many of the tasks via the simplest set of instructions and you will find some programmers have used complex code to do the simplest task.
That's why you have to pick out the "wheat from the chaff" and remember a good routine, while discarding the over-complex sets of code.
This brings up an important point.
Don't expect to be an A1 programmer in a week. It takes time to absorb the skills of programming and it is really only understood by a microscopic percentage of electronics enthusiasts. If you take it up and understand it, you are one of the microscopic few.
It is a world that, once you are in, will open up a whole new field of ideas and development.
It's like taking up a new spoken language and, in fact, a program reads like a book, so the analogy is very close.   
There are some very "clever" instructions such as XOR where you can compare two files by using the XOR function and determine if they are the same. And very powerful instructions such as djnz that decrements a file and if it is zero, the micro jumps over the next instruction.
Other clever instructions transfer the contents of a file to another via the "carry."
You cannot be expected to know these "tricks" unless you study programming. That's why we are here.

Here are the files you will need:
LED_FX.asm
LED_FX-asm.txt
LED_FX.hex

 
	
;*******************************
;;PIC Fx.asm
;  11-3-2010 
;*******************************

	list	p=12F629
	radix	dec
	include	"p12f629.inc"
	
	errorlevel	-302	; Don't complain about BANK 1 Registers during assembly

	__CONFIG	_MCLRE_OFF & _CP_OFF 
	& _WDT_OFF & _INTRC_OSC_NOCLKOUT  ;Internal osc.

;_MCLRE_OFF  - master clear must be off for gp3 to work as input pin 

;****************************************************************
; variables - names and files
;****************************************************************

temp1		equ 20h	;
temp2		equ 21h	;
temp3		equ 22h	;
temp4		equ 23h	; 
jump		equ 24h	;jump value for table1
fadeUp		equ 25h
fadeDwn		equ 26h
sequences		equ 27h
sw_duration	equ 28h
testing		equ 29h

;****************************************************************
;Equates
;****************************************************************
status	equ	0x03
rp1	equ	0x06
rp0	equ	0x05
GPIO 	equ 	0x05
			

status	equ	03h
option_reg	equ 	81h


	; bits on GPIO
				
pin7	equ	0	;GP0  LED C
pin6	equ	1	;GP1  LED B
pin5	equ	2	;GP2  LED A
pin4	equ	3	;GP3  Sw A  
pin3	equ	4	;GP4  Sw B
pin2	equ	5	;GP5  Sw C   
 

		;bits
				
rp0	equ	5	;bit 5 of the status register


;****************************************************************
;Beginning of program
;****************************************************************
	org	0x00
	nop
	nop
	nop
	nop
	nop			
SetUp	bsf	status, rp0 	;Bank 1			
       	movlw	b'11111000'	;Set TRIS  GP0,1,2 out   GP3,4,5 input
	movwf	TRISIO	       ;		
	bcf	status, rp0		;bank 0
	movlw   	07h         		;turn off Comparator ports
       	movwf   	CMCON       	;must be placed in bank 0  
	clrf 	GPIO       		;Clear GPIO of junk	
	call	_memory
	btfss	gpio,5		;SwA to: "record new sequence"		
	goto	record			
	btfsc	gpio,3		;SwC removes attract sequence
	goto	$+.10		
	movlw	0FFh
	bsf	status,rp0		;select bank1	
	movwf	EEDATA						
	bcf	status,rp0		;select bank0	
	movlw	.101
	bsf	status,rp0		;select bank1	
	movwf	EEADR			 
	bcf	status,rp0		;select bank0
	call 	write			
	movlw	.101
	bsf	status,rp0			
	movwf	EEADR						
	bsf	EECON1,0	;starts EEPROM read operation. Result in EEDATA
	movf	EEDATA,w	;move read data into w
	bcf	status,rp0				
	xorlw	.8		;look for 8 - for Attract mode
	btfsc	03,2
	goto	Attract_Seq	;selected sequence will appear first	
	goto 	Main				

;****************************************************************
;* Tables 			*
;****************************************************************

table1	addwf   PCL,F           ;02h,1  add W to program counter
	retlw   .10     ;
	retlw   .50 
        	retlw   .30     ;
	retlw   .50       
	retlw   .100     ;
	retlw   .40		;program starts at bottom of table
	retlw   .10     ;
	retlw   .50 
        	retlw   .30     ;
	retlw   .50       
	retlw   .60     ;
	retlw   .10     ;
	retlw   .50 
        	retlw   .10     ;
	retlw   .50       
	retlw   .100     ;
	retlw   .20     ;
	retlw   .50 
        	retlw   .30     ;
	retlw   .50       
	retlw   .70 
	retlw   .60     ;
	retlw   .100     ;
	retlw   .50 
        	retlw   .100     ;
	retlw   .50       
	retlw   .100     ;
	retlw   .70     ;
	retlw   .50 
        	retlw   .30     ;
	retlw   .50       
	retlw   .70     ;
		
table2	addwf   PCL,F           ;02h,1  add W to program counter
	goto	seq1   
	goto	seq2   
	goto	seq3   
	goto	seq4   
	goto	seq5   
	goto	seq6   
	goto	seq7   
	goto	seq8   
	goto	seq9   
	goto	seq10 
	goto	seq11     
	goto	seq12		

;****************************************************************
;* Delays 			*
;****************************************************************

_xuS	movwf	temp2
_uS	movlw	.10
	movwf	temp1
	decfsz	temp1,f
	goto	$-1				
	decfsz 	temp2,f
	goto 	_uS		
	retlw 	00
		
_ZuS	movwf	temp2
	goto	$+2
	goto	$+2		
	decfsz 	temp2,f
	goto 	$-3		
	retlw 	00		


_xmS	movwf	temp2
_x	nop
	decfsz 	temp1,f
	goto 	_x
	decfsz 	temp2,f
	goto 	_x	
	retlw 	00
		
	;5mS delay for increments in timing for "New Sequence" 
		
_5mS	movlw	05h
	movwf	temp2
_5	nop
	decfsz 	temp1,f
	goto 	_5
	decfsz 	temp2,f
	goto 	_5	
	retlw 	00	
		
		
_10mS	movlw	0Ah
	movwf	temp2
_10	nop
	decfsz 	temp1,f
	goto 	_10
	decfsz 	temp2,f
	goto 	_10	
	retlw 	00		
		

_50mS	movlw	.50
	movwf	temp2
_50	nop
	decfsz 	temp1,f
	goto 	_50
	decfsz 	temp2,f
	goto 	_50	
	retlw 	00
		
_100mS	movlw	.100
	movwf	temp2
_100	nop
	decfsz 	temp1,f
	goto 	_100
	decfsz 	temp2,f
	goto 	_100	
	retlw 	00	
		
		
_150mS	movlw	.150
	movwf	temp2
_150	nop
	decfsz 	temp1,f
	goto 	_150
	decfsz 	temp2,f
	goto 	_150	
	retlw 	00				


;****************************************************************
;* Sub Routines 			*
;****************************************************************
			
_memory			
			
	movlw	.48
	movwf	temp1
	movlw	2Fh
	movwf	fsr
	incf	fsr,f
	movlw	0FFh
	movwf	indf
	decfsz	temp1,f
	goto	$-4
	retlw	00
		
	   ;SwB puts current sequence into EEPROM for turn on. 
	   ;and puts "marker" in location 101
		   
Attract	
	movf	sequences,w	;put sequence number into w	
	bsf	status,rp0	;select bank1	
	movwf	EEDATA						
	bcf	status,rp0	;select bank0	
	movlw	.100
	bsf	status,rp0	;select bank1	
	movwf	EEADR			 
	bcf	status,rp0	;select bank0
	call 	write
	movlw	.8	
	bsf	status,rp0	;select bank1	
	movwf	EEDATA				
	incf	EEADR,1			 
	bcf	status,rp0	;select bank0
	call 	write		
	nop
	goto	$-1   ;Project must now be turned off
		
		
	;Seq selected as Attract will be displayed when project turned on		
		
Attract_Seq	
	movlw	.100
	bsf	status,rp0			
	movwf	EEADR						
	bsf	EECON1,0	;starts EEPROM read operation. Result in EEDATA
	movf	EEDATA,w	;move read data into w
	bcf	status,rp0
	movwf	temp4
	movf	temp4,w				
	call	table2		
	goto	$-2		


	;record new sequence - looks for "no switch pressed" for 1.25 seconds to exit
	;uses files 30h to 5Fh  (48 files)
	;three files per "step"   1st file = LEDs,  2nd = Off time, 3rd = on time
	;15 steps allowed - look for 5Dh 
		
record	btfss	gpio,5	;wait for release of button A
	goto	$-1
	movlw	30h
	movwf	fsr	;start storage at file 30h
		
	;look at keys being pressed - identifies 2 or 3 keys pressed together
			
_r1	clrf	sw_duration
_r1a	call	_5mS
	incfsz	sw_duration,1	;5mS x 256 = 1.25seconds
	goto	$+2
	goto	Store		;time out! store files 30h to 5Fh in EEPROM	
	btfss	gpio,5		;see if one or more Sw is pressed
	goto	$+5
	btfss	gpio,4
	goto	$+3
	btfsc	gpio,3
	goto	_r1a		;no sw pressed create 2.5 sec timing
				;1,2,or 3 sw pressed
		
	call	_10mS		;delay to detect 2 or 3 switches
	incfsz	sw_duration,1
	goto	$+2
	goto	Main		
	btfsc	gpio,5		;SwA
	goto	$+2
	bsf	gpio,0		;turn on LED A		
	btfsc	gpio,4		;SwB
	goto	$+2
	bsf	gpio,1		;turn on LED B		
	btfsc	gpio,3		;SwC
	goto	$+2			;
	bsf	gpio,2		;turn on LED C
				;LEDs have been illuminated
	movf	gpio,w		
	movwf	indf		;w moved to fsr's file (30h+)	
	incf	fsr,f			
	movf	sw_duration,w	;off time!!
	movwf	indf		;w moved to fsr's file (30h+)	
	incf	fsr,f		
	clrf	sw_duration					
_r2	call	_5mS
	incfsz	sw_duration,1					
	goto	$+2
	goto	record		;time out! keys pressed too long. Start again
	btfss	gpio,5
	goto	_r2		;sw pressed
	btfss	gpio,4
	goto	_r2		;sw pressed
	btfss	gpio,3
	goto	_r2		;sw pressed			
				;file empty. Put duration into file
	movf	sw_duration,w	;on time				
	movwf	indf			;w moved to fsr's file (30h+)	
	incf	fsr,f			
	movlw	5Dh
	xorwf	fsr,w
	btfss	03,2				
	goto	$+2
	goto	Store	;stop at 15 steps. store files 30h to 5Fh in EEPROM
	clrf	gpio		
	goto	_r1				
			
	;sequences:
			
	;seq1 Self-Programmed sequence 
	;1St file:LEDs  2nd file:OFF time  3rd file:On time
			
seq1	bsf	status,rp0			
	clrf	EEADR		
	bcf	status,rp0		
	bsf	status,rp0					
	bsf	EECON1,0	;starts EEPROM read operation. Result in EEDATA
	movf	EEDATA,w	;move read data into w
	bcf	status,rp0				
	movwf	gpio
	bsf	status,rp0
	incf	EEADR,1						
	bsf	EECON1,0	;				
	movf	EEDATA,w	;move read data into w
	bcf	status,rp0		
	movwf	temp4		;this is OFF time. Store it
	bsf	status,rp0
	incf	EEADR,1						
	bsf	EECON1,0	;				
	movf	EEDATA,w	;move read data into w
	bcf	status,rp0		
	movwf	sw_duration 	;this is ON time
	call	_5mS
	decfsz	sw_duration,1
	goto	$-2
	clrf	gpio
	call	_5mS
	decfsz	temp4,f	;create OFF duration
	goto	$-2		
	bsf	status,rp0
	incf	EEADR,1						
	bsf	EECON1,0	;		
	movf	EEDATA,w	;move read data into w
	bcf	status,rp0			
	xorlw	0FFh	;look for 0FFh - end of routine
	btfss	03,2
	goto	$-31
	retlw	00
			
			
	;seq2  chase right - very fast

				
seq2	bsf	gpio,0
	call	_100mS
	bcf	gpio,0
	bsf	gpio,1
	call	_100mS
	bcf	gpio,1
	bsf	gpio,2
	call	_100mS
	bcf	gpio,2
	call	_100mS
	clrf	gpio
	retlw	00
		
	;seq3  chase right 
		
		
seq3	bsf	gpio,0
	call	_150mS
	bcf	gpio,0
	bsf	gpio,1
	call	_150mS
	bcf	gpio,1
	bsf	gpio,2
	call	_150mS
	bcf	gpio,2
	call	_150mS
	clrf	gpio
	retlw	00	
		
	;seq4  chase right with off-delay at end	
		
		
seq4	bsf	gpio,0
	call	_150mS
	bcf	gpio,0
	bsf	gpio,1
	call	_150mS
	bcf	gpio,1
	bsf	gpio,2
	call	_150mS
	bcf	gpio,2
	call	_150mS		
	retlw	00	
		
	;seq5  left right left right 
		
seq5	bsf	gpio,0
	call	_150mS
	bcf	gpio,0		
	bsf	gpio,2
	call	_150mS
	bcf	gpio,2				
	retlw	00
		
		
	;seq6  middle on   middle off
		
seq6	bsf	gpio,1
	call	_150mS
	bcf	gpio,1	
	call	_150mS			
	clrf	gpio			
	retlw	00
				
		
	;seq7  All on   all off
		
seq7	clrf	gpio
	call	_150mS
	decf	gpio,f
	call	_150mS
	clrf	gpio					
	retlw	00	
		
		
seq8	;seq8  middle on then sides on 	
		
	bsf	gpio,1
	call	_150mS
	bcf	gpio,1
	bsf	gpio,0
	bsf	gpio,2
	call	_150mS
	clrf	gpio					
	retlw	00
		
	;seq9  police flasher  3 times left 3 times right 
		
seq9	bsf	gpio,0
	call	_50mS
	bcf	gpio,0
	call	_50mS
	bsf	gpio,0
	call	_50mS
	bcf	gpio,0
	call	_50mS
	bsf	gpio,0
	call	_50mS
	bcf	gpio,0
	call	_50mS		
	bsf	gpio,2
	call	_50mS
	bcf	gpio,2
	call	_50mS
	bsf	gpio,2
	call	_50mS
	bcf	gpio,2
	call	_50mS
	bsf	gpio,2
	call	_50mS
	bcf	gpio,2
	clrf	gpio
	call	_50mS				
	retlw	00	
		
	;seq10  random flicker
		
seq10	movlw	.32	;start at bottom of table
	movwf	jump
	bsf	gpio,1
	movf	jump,w	;put table jump value into w
	call 	table1
	call	_xmS	
	bcf	gpio,1
	decfsz	jump,f
	goto	$+2
	retlw	00	;top of table found
	movf	jump,w	;put table jump value into w
	call 	table1
	call	_xmS				
	goto	$-11
		
		
	;seq11  slow fade up down
		
seq11	clrf	fadeUp		;
	clrf	fadeDwn
	incf	fadeUp,f	;to create 1 (delay routine does not like 00)	
	bsf	gpio,1
	movf	fadeUp,w
	call	_xuS
	bcf	gpio,1
	movf	fadeDwn,w
	call	_xuS					
	decfsz	fadeDwn,f	;
	goto	$-8
	incf	fadeDwn,f 		;to produce 1
	bsf	gpio,1
	movf	fadeUp,w
	call	_xuS
	bcf	gpio,1
	movf	fadeDwn,w
	call	_xuS
	decf	fadeUp,f			
	incfsz	fadeDwn,f		
	goto	$-8			
	clrf	gpio
	retlw	00
		
		
	;seq12  fast fade up down
		
seq12	clrf	fadeUp		
	clrf	fadeDwn
	incf	fadeUp,f	;to create 1 (delay routine does not like 00)	
	bsf	gpio,1
	movf	fadeUp,w
	call	_ZuS
	bcf	gpio,1
	movf	fadeDwn,w
	call	_ZuS					
	decfsz	fadeDwn,f	;
	goto	$-8
	incf	fadeDwn,f 		;to produce 1
	bsf	gpio,1
	movf	fadeUp,w
	call	_ZuS
	bcf	gpio,1
	movf	fadeDwn,w
	call	_ZuS
	decf	fadeUp,f			
	incfsz	fadeDwn,f		
	goto	$-8			
	clrf	gpio
	retlw	00		
		
		
	;Store   Store the 15 steps in EEPROM		
		
Store	bsf	status,rp0	;select bank1	
	clrf	eeadr						
	bcf	status,rp0	;select bank0		
	movlw	.48
	movwf	temp1
	movlw	2Fh
	movwf	fsr
	incf	fsr,f	;fsr starts at file 30h
	movf	indf,w	;retreive data in file 30h
	bsf	status,rp0	;select bank1	
	movwf	eedata		; 
	bcf	status,rp0	;select bank0
	call 	write
	bsf	status,rp0	;select bank1	
	incf	eeadr,1						
	bcf	status,rp0	;select bank0
	decfsz	temp1,f
	goto	$-10
	goto	Main
	
		
		
write	bsf	status,rp0		;select bank1	
	bsf	eecon1,wren	;enable write		
	movlw	55h 		;unlock codes
	movwf	eecon2
	movlw	0aah
	movwf	eecon2
	bsf	eecon1,wr		;write begins
	bcf	status,rp0		;select bank0		
writeA	btfss	pir1,eeif		;wait for write to complete
	goto	writeA
	bcf	pir1,eeif
	bsf	status,rp0		;select bank1
	bcf	eecon1,wren	;disable other writes
	bcf	status,rp0		;select bank0
	retlw	00			
		
						
;****************************************************************
;* Main 					*
;****************************************************************

Main	clrf	sequences	
	movf	sequences,w
	call	table2
	btfss	gpio,5		;Is swA still pressed?
	goto	$-3			;SwA still pressed		
	movf	sequences,w	;SwA released
	call	table2
	btfss	gpio,4		;SwB puts current sequence at turn-on	
	goto	Attract
	btfsc	gpio,5
	goto	$-5			;SwA not pressed
	incf	sequences,f
	movlw	.12
	xorwf	sequences,w
	btfss	03,2
	goto	$-12
	goto	Main		
				
;****************************************************************
;*EEPROM     				*
;****************************************************************
								
	org	2100h			
					
							
	END


GOING FURTHER
We have not produced all the possible sequences and you can add more by simply creating a new sub-routine.
You need to add it to the table and make sure you end with retlw 00 to send the micro back to Main.
We have provided all the hardware and software for you to do this. Now it's now up to you.

 

PIC Fx-1
Parts List

Cost: au
$12.00 plus postage
Kits are available

3   -  82R (820) SM resistors
2  -  22k  (223) SM resistors
2  -  47k  (473) SM resistors

1  -  100n SM capacitor
1  -  10u tantalum

1  -  SPDT mini slide switch

1  -  LM78L05 voltage regulator
1  -  PIC12F629 chip (with routines)
1  -  8 pin IC socket 
3  -  super bright white 3mm LEDs
3  -  mini tactile switches
5  -  machine pins
5  -  component header pins (alternative)
5cm fine tinned copper wire for link
1  -  piezo diaphragm
1  -  9v battery snap
20cm very fine solder 
1  -  PIC Fx-1 PC board
 


P2 - The Instructions
P3 - writing your own program

 14/6/14