Talking Electronics PIC Theory

Buy a kit


Page 1

This project is a dedicated device. It dials a single phone number when the handset is lifted. There are two different modes of operation.. A slide-switch on the PC board allows the project to operate in automatic or manual mode. If the switch is in "auto dial" mode,  a pre-programmed phone number is  AUTOMATICALLY dialled when the phone is lifted. If the switch is in "push to dial,"  the project dials the number when the phone is lifted and "push to dial" button is pressed. This allows the phone to be used as a normal phone. 
The complete circuit is shown below:

TAXI PHONE hasn't been designed exclusively as a taxi phone, that's just the name we gave it. 
It's the simplest phone dialing project you can get and since the program is so simple, it's an ideal place to start. 
The concept has so many possibilities. Take the example of a "Free Taxi Phone." Imagine a phone at the front of a night club or restaurant, to ring a taxi. 
As soon as you pick up the phone, it automatically dials a nominated taxi company and by quoting a code number, or sending a DTMF code down the line, the company knows where to pick you up.
Or take the example of a doctor's surgery, police station, fire station or real estate office.
A cheap wall phone can be mounted outside the premises for after-hour's use. By lifting the handset the call will be directed to an operator, the owner of the business or a representative.
The same can apply at professional suites, or land-development projects. The proliferation of mobile phones has brought remote communication into the hands of nearly everyone but this project still has its uses.
It's cheaper and free to the user. A customer would prefer to use the "Company Phone" than his own mobile.
Take the example of a "House for Sale." By lifting the phone connected to the sale board, you could be in touch with the agent and arranging a meeting before your enthusiasm is diverted to another property.
Or the example of a Panic Phone for a granny, babysitter convenience store. All they need do is lift the receiver and the call goes through. This is already available at some exchanges but the emergency number is only dialed if the exchange does not detect any other number being dialed within 3 seconds. In the Auto mode, our design prevents the phone being used for any other purpose. This can be an advantage in some circumstances, such as a boarding house or as a "hot line." It prevents the phone being used for any other calls.
The commercial advantage is also enormous. Imagine a phone at an airport or railway station linked to a local hotel or tourist attraction. A small display would highlight the features of the establishment and the free phone could be used to make a booking.
Even booking mini cruises and tours at the departure points could be made, when no-one is in attendance.
It all adds to the efficient running of a business and reduces the cost of attendance during the low periods.
I am sure we can all think of a use for a dedicated phone like this and even one at the front door of your own house would be "magic." 
How many times has a friend dropped by or a delivery been made when you were absent? 
Either the goods were left on the door step or brought back three day's later. How inconvenient. A simple phone call to your mobile could keep you in touch with everything.
The same with business addresses and suites. By providing a phone at the door, the owner will never miss a prospective client.
Not only that. The image and efficiency will rise in the eye of your customers. 
So, after seeing the potential of this project, why not put it together and use it yourself or sell it to others.
The only problem is a project like this has to be approved by the authorities for connection to a public telephone system. The cost of approval could be anything up to $5,000 to $10,000 or more and
the delay in approval could be 6 months or more.
Lots of ideas like this have not seen the marketplace, for this very reason. The cost of compliance is enormous. That's why we have presented the article as an idea, mainly to show what can be done with the '508A microcontroller.
Once you build the project, you can modify it to suit almost any requirement.
We have included a number of ideas but it's certain we haven't thought of everything.

When the handset is "on the hook" (handset down), no current flows in the telephone line and thus the project is not activated.
As soon as the handset is lifted, current flows in the line and the diodes in the bridge rectifier direct the current to flow in the project so that the top rail becomes positive.
The purpose of the bridge is to create a positive and negative rail, no matter which way the project is connected to the line.
The zener diode and the LED form a zener reference voltage of approx 5.6v and this allows the chip to be powered with its correct voltage of 5v to 5.6v
In microprocessor-terms, this voltage rises very gradually to full voltage (partially due to the 100u electrolytic across the rails) when the phone is lifted. The '508A has a delayed reset feature inside the chip but there is no guarantee it will see the delayed reset AFTER the full rail voltage. If it does not work, the micro will start anywhere in the program and fail to ring the number.
The answer is to utilise the watchdog timer. This is a completely separate oscillator that counts for 18mS and resets the micro. If this timer is enabled, you must make sure your program resets the
watchdog timer before the 18mS has expired. This is especially difficult to do if you have delay routines or operations such dialing a telephone number, as they run for longer than 18mS. It can be done, but it takes a lot of programming skills.
Fortunately the watchdog timer duration can be increased by feeding it into a divider circuit (it's called a divider but in fact it actually multiplies the duration).
By setting bits 0, 1 and 2 in the OPTION register, the WDT time-interval can be increased to 128 x 18mS = 2.3 seconds. This is what we have done. The only occasions when the WDT needs to be cleared is before entering a delay routine. 
If the micro gets powered up and the program counter starts the micro part-way through a routine where it gets "locked-up", it could take two seconds or more for the watchdog timer to time-out and reset the micro. 
This concept is not foolproof. It is essential the check the program for loops containing CLRWDT instructions, where the micro can enter the loop and never emerge.
If the micro enters the program at an undefined point, it may carry out instructions such RETLW and RETURN with a "junk" RETURN address from the stack and jump to any location in memory.
At the moment the only place the micro can get stuck is at Main5, where a loop has been created to hold it from escaping. The entrance to this loop is only 3 instructions wide and the chance of the micro
getting into it is fairly remote.
Under normal operating conditions the voltage across the micro will start from 0v and the micro will start at the beginning of the program. This will allow us to create a program to dial a pre-programmed number contained in table1.
This table has a rather unusual feature. It is burnt with the initial phone number at the beginning of the table. A further 100 RETLW 0FFh instructions are added to the table for future use. If you need to
change the phone number, the old number (including 0E) is burnt down to 00, i.e: to 00 00, and the next ten locations used for the new number. This allows the number to be changed up to 9 or 10 times. This is a brilliant concept for a chip that is supposed to be a one-time programmable device.
To allow this feature to be used, the chip must not be code-protected.

Some of the components used in the project are identified in the diagram below:

Identifying the components used in this project

As with all the projects designed by Talking Electronics, the PC board has an overlay that identifies all the components and their orientation. This is an essential part of a good design as you may be repairing the project at a later date and need to know the value or type of a component. All the boards also have a solder mask to assist in keeping the solder to the surrounding land. And the boards are roll-tinned to make soldering a very quick process. Naturally the boards are fibre-glass based and this helps you to work with a first-class product. 
Anything you design should come up to this standard as it smartens up the project and finishes off the presentation. 
It's an easy job to solder the components to the board, making sure the resistors, phone sockets, slide and push switch,  bridge, IC socket and zener diode fit against the board while the transistor, LED, crystal and electrolytics are mounted slightly above the board to prevent heat-damage.  The ceramic capacitors and choke can be fitted up to the board or slightly above it - there is no fixed rule for this type of component.
Take care when soldering and snip the lead very close to the joint after the soldering has been carried out. One project came in for repair and it took 30 minutes for us to realise one of the leads of a resistor had been snipped off close to the board before the soldering had been done. The resistor was sitting in position via one lead and the solder hadn't taken to the other lead. That's why we insist on soldering before cutting the lead.  
If you hold a finger on the component while soldering you will know how hot each part is getting. If you can't hold your finger on it, you are taking too long.
A constant-heat soldering iron improves the quality of the soldering 100%. Keeping the temperature at about 320C will prevent overheating any of the parts. 
The last thing that makes a neat connection is the use of fine solder. That's why we have included it in the kit. You will never go back to thick solder again. 
There are only two things that will prevent the project from working. Faulty soldering and the wrong placement of a component. The circuit works and the PC board has been tested. Take a little care with checking the value of the resistors and even use a multimeter to check the resistance as it is very easy to mistake a 100R resistor for 10k. 
Don't forget, the positive lead of the electro is identified on the board while the negative lead is identified on the body of the component. 
The short lead of the LED is the cathode and this corresponds with the line on the symbol on the board. The IC socket has a cut-out at one end and the bridge must match-up with the markings on the board. 
The crystal and choke can be placed around either way but the tactile switch has legs that are spaced wider in one direction to assist in placement.  The zener diode has a line or stripe at one end and this corresponds with the line on the board. 
Finally, the transistor has an outline on the board to help with placement. A little bit of care during assembly will save hours of frustration and checking.  The board looks easy to assembly because it is neatly laid-out. That's why you have to be doubly-careful. After building 10 or more of our projects you will find it easy to place the components. 
But start slowly because we use only the best and smallest components on the market and some of the parts-identification is very difficult to read. 

Taxi Phone
$xx.80 plus $2.20 postage

4  -  100R
1  -  220R
1  -  3k3
3  -  10k 
1  -  BC547 transistors
2  -  18p ceramics
1  -  4MHz crystal
1  -  100n monoblock or ceramic
2  -  1u 16v electrolytics
1  -  100u electrolytic
1  -  10mH choke
1  -  8 pin IC socket
1  -  3v3 400mW zener
            (or 3v9Z and 3mm red LED)
1  -  3mm green LED 
1  -  DF04 diode bridge 
2  -  SPDT slide switches
1  -  PC mount push-switch
2  -  4-pin modular telephone sockets
1  -  PIC12c508A microcontroller chips

1 - TAXIPHONE PC board

The Taxi Phone program uses three tables. The first stores the telephone number, the second holds the delay value for the low frequency of the DTMF tone and table3 holds the high tone delay value.
A table is the only way to hold data for a routine - it cannot be stored within the program.

When the power is applied (the handset lifted), the automatic reset for the chip comes into operation to reset the Program Counter to address zero. If this does not happen, the micro will jump to a random
part of the program and begin executing code.
If it does not come across a CLRWDT instruction, the watchdog timer will count down 2.3 seconds and cause a reset. The program will then GOTO the main routine and look for NOP's in the table, to find the
beginning of the phone number.
It will then GOTO Dial1 sub-routine. This routine picks up the first digit to be dialed from Table1 and uses the value from the table to jump down Table2 to find the delay value for the low tone. It loads
the low-tone file with the value and then goes to Table3 and jumps down the table for the high-tone value. The micro then goes to the DTMF routine where the low and high tone files are decremented and
when the count is zero, the appropriate output line is toggled and decrementing continues. This process continues for A0h (160) loops to produce a dual tone for approx 1/10th second.
A short delay is then executed and the jump counter for table 1 is incremented so that the next digit is picked up. This process continues until the End of Table marker (E) is detected. The micro then goes to a closed loop and continues in this loop until the handset is replaced.
The 10k across the supply rail makes sure the 100u is fully discharged so that the micro detects a LOW and starts at address 000 when power is applied. This feature, along with the watchdog timer, ensures the micro starts correctly. Each feature was omitted in a test run and it was proven that they were necessary. 
This project has a number of different applications and the circuit can be modified to suit different requirements.
One of the features of the circuit is to dial a number when a button is pressed. This gives the phone a dual role and the number is only dialed when the button is pressed. The button could be for a Taxi service, a hot line to a visa card approval centre or a pre-dial access number such as 1478 to a long-distance low-cost telephone company such as One Tel. The only components required are a push-switch and pull-up resistor. 
A few lines of code are needed so that the micro detects the state of GP3. When GP3 is high, the button is not pressed and the program waits in a loop until the button is pressed. If GP3 is LOW, the micro automatically dials the number.  

You will notice we have used GOTO instructions to move from one sub-routine to another. This is a very unusual way to implement a move as most programs are written with CALL and RETURN instructions. In fact we prepared the program with CALL instructions and changed them to GOTO
to show how GOTO commands can be used.
When using a GOTO instruction from one sub-routine to another, it means you are limiting yourself to a DEFINITE path for the micro.
A CALL instruction allows a sub-routine to be CALLed from any other sub-routine and the micro will go back to the previous sub-routine.
But when you have a very simple program like this one, where a sub-routine is only being CALLED once and it always RETURNs to the same place, a GOTO instruction can be used.
In this program you will notice GOTO Dial1 and GOTO DTMF have been used. This type of HARD DIRECTION can only be done after the whole program has been completed. A GOTO instruction does not affect the stack and if you have a program with a CALL instruction CALLing another routine, a further CALL cannot be made with the PIC12C508A and thus a GOTO instruction may be possible. 

The 3v3 and red LED form a zener reference for the micro and this simply means a fixed voltage for the processor so that it is not damaged by over-voltage.
We normally pass over the word ZENER very quickly but the way a zener reference (zener voltage) works is quite a complex thing to describe.
In simple terms the chip has an impedance (value of resistance) and as the voltage rises from zero, it begins to turn on and a current flows. During this time the zener reference (the zener diode and LED)
do not turn on as NO CURRENT flows through a zener diode or LED until the voltage across them reaches the zener reference voltage.
The red LED we have used has a characteristic voltage of 2.1v and this is exactly equivalent to a zener reference of 2.1v. In other words, the LED will not turn on or take any current until the voltage across it is 2.1v.
This means the combined zener reference is 3.3 + 2.1 = 5.4v  At 5.35v all the current flows through the chip and as the voltage rises to 5.4v, the zener diode and LED "breakdown." If the voltage tries to
rise above 5.4v, current flows through the zener branch to keep the voltage at exactly 5.4v.
The 100u across the zener regulator provides a reservoir of current for the times when the micro draws a higher current when producing the DTMF tones.
The 100n across the chip prevents high frequency instability in a project such as this where the supply rail is not a low impedance supply.
In this case the supply is fed via a dropper resistor and all sorts of high-frequency oscillations can start up when the supply rails cannot supply a very high current. This is what we mean by a low impedance

When a project operates in series with an existing load (the telephone, in this case), a design problem is encountered. It's an easy problem to solve, once you know the mathematics.
This type of circuit is called a "LEECH" design as it takes some of the current from the telephone, for its operation. This may sound a surprising thing to say but, the current through the phone drops
(a small amount) when the dialer is fitted.
The operation of the phone is not affected by the dialer as some electronic circuits are very tolerant - especially telephones, as they are required to work with a very wide operating voltage.
We will not be going over the mathematics except to say that the voltage developed across a 100R resistor is about 3.5v in the leach project, when a standard telephone is connected to the line.
This gives 5.6v + 3.5v = 9.1v across the power rails for the buffer transistor. Since the output of the DTMF wave-shaper circuit is about 3.5v, the emitter-follower will produce about 2.5v into the phone
line (there is a base-emitter loss of about 0.7v and a loss across the 100R in the emitter).
The purpose of the 100R feeding the zener regulator is to provide the lightest load for the buffer transistor.
As you can see, the buffer is producing a signal that is being fed into the phone line. This amplitude also appears across the 100R feeding the zener regulator. If the 100R were removed, the signal would be fed directly into the zener circuit and be totally absorbed.
By raising the value of the 100R, the output signal from the circuit will be increased but the voltage drop across the circuit will also increase and this may detract from the operation of the phone.
Since we only need 1v - 2v DTMF waveform down the line for the exchange to detect the frequencies, there is no point in providing a higher amplitude. 

Go to Page 2