All the tools, programs and routines to carry out this operation are on our website and it’s just a matter of having them all in easy reach.
That’s what we will do now.
To create a program for a PIC12C508A is very easy but since this chip is a one-time programmable (OTP) device, you don’t want to waste any chips during the “development” procedure. If you think you can get a project “up-and-running” in one or two “tries” - you are kidding yourself. It can take up to 100 tries before a project is working perfectly.To prevent wastage we have devised a method where you use a PIC16F84A to hold the program during the development stages and when everything is running perfectly, you “burn” a PIC12C508A. For this you need an 8-pin to 18-pin adapter to allow the PIC16F84A to plug into the project requiring a PIC12C508A.
This means you are learning to program the PIC16F84 at the same time!
All you have to do is put the utilities we have listed below on your desk-top and connect the Multi-Chip Programmer to your serial port.
The ‘508A is an 8-pin microcontroller with 5 input/output lines and one input-only line. It has an internal 4MHz clock and can be used for many different applications.
The days when an 8-pin chip was just a timer, oscillator, amplifier or op-amp, have gone. An 8-pin chip can now be a complete dialing alarm or the heart of a random sequencer, a battery monitor or security-code identifier, just to mention a few.
For simplicity, let’s say you want to modify the Robot Beacon project. The Robot Beacon project is in our “FREE Projects” section.
Here is what you will need: (Some of the items are in the PIC Programaming Course. The CD containing this course is available for $9.95)
Have the project you wish to develop on your work-bench.
A full list of sub-routines can be found in our Library of Routines.
Almost all the routines you will need for a program are included, such as “Change direction, Compare, Decrement, Delay, FSR, Increment, Input, Mask, Move, Output, Poll, Return, Rotate, SetUp, Shift, Swap, Table, Toggle, TRIS, Wait, XOR, Zero Flag, and many others.
To place these instructions into your program, you need them in a text-file format. This has been done in our ”Copy and Paste” library. It is in WordPad format. It also includes a template. This is your starting-point. Copy and Paste the template into a new WordPad screen and add instructions as needed by Copying and Pasting. This makes the job of creating a program, very easy.
To create a program, you can pull-apart Beacon-1.asm, or start a-fresh by getting the “template” mentioned above or the code for SetUp and put it in the file: Beacon-2.asm
It’s always easiest to pull-apart a previous program, however if you are starting from the beginning, use our preferred method of layout: (SetUp, sub-routines, then Main) and put sub-routines in alphabetical order, to make them easy to find. Keep Main at the end of your program.
Any program you create will be loaded into a PIC16F84A and tested in the project via the 8-pin to 18-pin adapter. This means you must only use instructions that are common to both chips. All the instructions in SetUp can be understood by a PIC16F84A and PIC12C508A.
The layout below shows how to write a program that can be read by the assembler to produce code for both a ‘508A and ‘F84A. Click HERE for a program you can copy and paste into Notepad.
<!---TODO FIXME: code is not inline--->
;NewIdea.asm ;Project: "Rotating xxx" - for F84A and then for a 508AYou don't have to put anything here for: (__CONFIG) as the program below will be assembled in MPASM by selecting 16F84A as the "Processor" (Click on Default for Radix, Warning Level, Macro Expansion, and Hex Output. Click Error file and List file. Tab size: 8) and the CONFIG values will be produced. Load: Source File Name into the window as "NewIdea.asm" and click Assemble. You will get a NewIdea.hex file. Burn a PIC16F84A and put it into the Adapter Socket in your project and keep modifying the file until the project works perfectly. When it works perfectly, select 12C508A in MPASM and burn a '508A. ORG 0 ;Start of memory for program SetUp MOVLW 08 ;Load W with 0000 1000 TRIS 06 ;Make RB3, (GP3) input OPTION 0DFh ;Make GP2 an output & disable weak pull-ups GOTO Main Main BSF 06,5 ;Make GP5 HIGH NOP NOP etc GOTO Main
If your program requires less than 256 bytes of space (half the memory of a ‘508A), you will have no problems with the CALL limitation of a ‘508A.
If your program requires more than 256 bytes (instructions), the simplest is to use the first 256 locations and if any more sub-routines are required, they are accessed as a GOTO. At the end of the sub-routine you place a GOTO to take the microcontroller back to the Main program. Remember this: any sub-routine with a GOTO can only be accessed ONCE from Main. If you want to access a sub-routine many times, put it in the first 256 locations and use CALL (with RETURN at the end of the sub-routine). Always put Tables in the first 256 locations.
Remember, we are teaching you how to START programming. There are lots of larger, more advanced, microcontrollers and you can select one of these AFTER you have confirmed your ability at “burning.”
A reader recently sent us a program that does not produce an output and asked us to fault-find it.
His program used “equates” and a number of expressions such as: Goto $-1. While these “short-cuts” are ideal in theory, we come to a point where the program does not work and we have to find a solution.
Our answer in all cases, is to go back to the simplest programming techniques as shown in all our programs, and use ONLY the instructions supplied for the chip.
Do not use any short-cuts or “clever” instructions or an instruction you “think” will work.
Only use those things you are familiar with.
Start with a simple program that sets up the ports correctly and some of the lines as outputs.
Turn on a line, call a delay, turn off the line, call the delay and loop.
Make sure the delay is long enough (say 0.5 seconds - 500,000 instructions long) and connect a LED to the output via a resistor.
Make sure the LED illuminates when the line goes low by checking the circuit with the chip removed.
Make sure the chip is clocking (working) and is not in a “frozen stage” via one of the lines.
Once you have the LED blinking, you can change the program to “equates” and observe the LED again.
You can now start to build your new program.
Add only a small amount at a time and check its operation. When it works, save it as “-1” and continue.
This is the only way I can guarantee you will be able to produce complex programs similar to those I have produced for this website.
It’s all in the secret of “starting correctly.”
For now,
Colin Mitchell,
Editor
Click to subscribe to TALKING ELECTRONICS Interactive.
Quick Links
Legal Stuff
Social Media