HomeArticlesProjectsBlogContact
Blog
How to program PIC12C508A
Colin Mitchell
Colin Mitchell
June 13, 2004
Make sure to subscribe to our newsletter and be the first to know the news.

Table Of Contents

01
HOW DO I PROGRAM A PIC12C508A?
02
A little Background
03
FEEDBACK
04
TALKING ELECTRONICS Interactive

HOW DO I PROGRAM A PIC12C508A?

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.

A little Background

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.

  1. Put Notepad++ or VS Code, MPASM and IC-Prog on your desktop.
  2. Put the blank template: BlankF84.asm into Notepad and rename it: Beacon-2.asm
  3. Read the project: Robot Beacon.
  4. Here are the data sheets and files you will need:

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.

  1. 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.

  2. 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.

  1. To burn a PIC12C508A, Open IC-Prog from your desktop.
    Select PIC12C508A as the processor and select Oscillator: IntRC. Untick: WDT, CP and MCLR. (MCLR is pin 4 and if you tick the box when programming, this pin can only be used as a RESET pin. It is then an active LOW pin so that when it is taken LOW, the chip resets. You lose GP3 - the “in-only” pin.)
    Click on the file ICON at the top left of the screen.
    A window will open up and show .hex files (if not, find a folder with the files).
    Click on the file you need and click OPEN.
    The .hex values will be loaded into the window.
    Click the icon with the lightening arrow and the chip will be “burnt.”
  2. Re-burning a PIC12C508A.
    We have said the PIC12C508A is a one-time programmable chip and this is true. But it means that each “cell” or “location” or “bit” can only be “burnt-down” once.
    Suppose you burn a new chip and the chip does not work. It could mean the cells (bits) have not been correctly burnt down. You can try re-burning again.
    You can also re-burn the chip (with exactly the same program) and replace any instruction with a NOP. You can re-burn a chip and make any bit a “zero.” To do this, you have to write the binary value of the instruction and see if the new instruction can be created by making any bit or bits a “zero.”
    Finally, you can move a program “up-memory” by counting the number of instructions (bytes) and placing an equal number of NOP’s in the new program (add say 2 more).
    If you have used CALL (and RETURN) instructions, you can move your program up memory until the end of the program reaches 0FFh.
    If you have not used CALL instructions, you can move the program to 1FE (the highest location for a ‘508A).

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.”

FEEDBACK

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

TALKING ELECTRONICS Interactive

Click to subscribe to TALKING ELECTRONICS Interactive.


Colin Mitchell

Colin Mitchell

Expertise

electronics
writing
PIC-Chips

Social Media

instagramtwitterwebsite

Related Posts

TODO
TE front P2
© 2021, All Rights Reserved.

Quick Links

Advertise with usAbout UsContact Us

Social Media