Rotary Dialer PIC Interface
by randofo in Circuits > Microcontrollers
27875 Views, 33 Favorites, 0 Comments
Rotary Dialer PIC Interface
![main01.jpg](/proxy/?url=https://content.instructables.com/FH6/9P9J/PSAEYVZDILH/FH69P9JPSAEYVZDILH.jpg&filename=main01.jpg)
I have found myself with an abundance of rotary phones. In fact, they're everywhere I look. In hopes that I may someday see less of them, I've begun taking them apart and re-using the parts for other purposes.
For some reason I got it into my brain that interfacing the rotary control with a PIC chip would be a good idea. I can only think of a couple of vague uses for it at the moment and none are particularly useful, but I hope to do something cool with this in the future.
For some reason I got it into my brain that interfacing the rotary control with a PIC chip would be a good idea. I can only think of a couple of vague uses for it at the moment and none are particularly useful, but I hope to do something cool with this in the future.
Go Get Stuff.
![2A.jpg](/proxy/?url=https://content.instructables.com/FKK/NA4P/D64EYVZDOGN/FKKNA4PD64EYVZDOGN.jpg&filename=2A.jpg)
You will need:
1 - Rotary phone
3 - 220 ohm resistors
2 - 0.1uF capacitors
2 - 20K resistor (can substitute anything between 10K and 47K)
2 - LEDs
1 - PIC development board (I used the Basic Micro development environment)
1 - 20 MHZ resonator or crystal
1 - Breadboard
1 - 5V power source
1 - A foot or so of hookup wire
1 - Screwdriver
1 - Wire stripper
1 - Rotary phone
3 - 220 ohm resistors
2 - 0.1uF capacitors
2 - 20K resistor (can substitute anything between 10K and 47K)
2 - LEDs
1 - PIC development board (I used the Basic Micro development environment)
1 - 20 MHZ resonator or crystal
1 - Breadboard
1 - 5V power source
1 - A foot or so of hookup wire
1 - Screwdriver
1 - Wire stripper
Dissect the Phone.
![2B.jpg](/proxy/?url=https://content.instructables.com/F6V/JMOI/F8TEYVZDOR7/F6VJMOIF8TEYVZDOR7.jpg&filename=2B.jpg)
![2C.jpg](/proxy/?url=https://content.instructables.com/FMY/L3VV/8SMEYVZDOXU/FMYL3VV8SMEYVZDOXU.jpg&filename=2C.jpg)
![2D.jpg](/proxy/?url=https://content.instructables.com/FE9/O9EC/G6REYVZDOYD/FE9O9ECG6REYVZDOYD.jpg&filename=2D.jpg)
Open up your rotary phone. On the inside you will notice the few basic parts; the rotary dial, the ringer, two jacks, the hook switch and the basic circuitry which is usually encased in a metal junction-box-like thing.
There will be four wires running from the rotary dialer to this junction-box-like thing. The wires should be held in place by little more than tightened screws. Loosen the screws and disconnect the wires.
After that, disconnect the rotary dialer from the phone itself.
There will be four wires running from the rotary dialer to this junction-box-like thing. The wires should be held in place by little more than tightened screws. Loosen the screws and disconnect the wires.
After that, disconnect the rotary dialer from the phone itself.
Determine What the Wires Do.
![3A.jpg](/proxy/?url=https://content.instructables.com/F4X/7UXR/54UEYVZDIN7/F4X7UXR54UEYVZDIN7.jpg&filename=3A.jpg)
![3B.jpg](/proxy/?url=https://content.instructables.com/FY6/6Y9U/LXPEYVZDPQW/FY66Y9ULXPEYVZDPQW.jpg&filename=3B.jpg)
Wire up two LEDs as shown in the diagram below.
The two white wires should be the pair that closes the switch that lets you know when the dial is turned. The blue and green wire should be the pair that lets you know what number was dialed.
As such, when you turn the dial, the LED connected to the white wires should turn on, and when you let go of the dial, the LED connected to the blue and green wires should blink on and off as many times as the number you dialed (see video).
For instance, if you dial 8, the LED connected to the green and blue wire will turn off and on 8 times. This happens because one way to dial a phone number is to rapidly break the connection the number of times for the digit you are trying to dial. So, again, to dial an 8 you would have to rapidly break the connection 8 times.
The two white wires should be the pair that closes the switch that lets you know when the dial is turned. The blue and green wire should be the pair that lets you know what number was dialed.
As such, when you turn the dial, the LED connected to the white wires should turn on, and when you let go of the dial, the LED connected to the blue and green wires should blink on and off as many times as the number you dialed (see video).
For instance, if you dial 8, the LED connected to the green and blue wire will turn off and on 8 times. This happens because one way to dial a phone number is to rapidly break the connection the number of times for the digit you are trying to dial. So, again, to dial an 8 you would have to rapidly break the connection 8 times.
Downloads
Connect the Dialer to the PIC Chip.
![4B1.jpg](/proxy/?url=https://content.instructables.com/F8R/FN64/0AVEYVZDPSN/F8RFN640AVEYVZDPSN.jpg&filename=4B1.jpg)
![4A.jpg](/proxy/?url=https://content.instructables.com/FVK/HI26/8PXEYVZDIOX/FVKHI268PXEYVZDIOX.jpg&filename=4A.jpg)
Connect the rotary dialer to the PIC chip as seen in the diagram. Notice that I am reading in the state of the rotary dialer by using RC-timing. In other words, the PIC chip is counting the number of times it takes for a capacitor to discharge (which changes when resistance is added).
That is where the 20K resistor comes in. Adding this to the input allows for a clear differentiation between the signal from a closed and open rotary switch connection.
That is where the 20K resistor comes in. Adding this to the input allows for a clear differentiation between the signal from a closed and open rotary switch connection.
Assemble the Code.
![5A.jpg](/proxy/?url=https://content.instructables.com/F3D/BAW9/YV7EYVZDQ06/F3DBAW9YV7EYVZDQ06.jpg&filename=5A.jpg)
To program the chip, I used the MBasic development environment available from Basic Micro. MBasic, quite simply, is a variation of Basic designed for use with PIC chips. It is easily convertible into a more universal (useful) language.
The code is essentially determining when someone has turned the dial and then does edge-detection on the signal (determining low-high transitions) until the dial recoils to its initial state. After tallying the number of times it measures a signal transition, it then blinks the LED accordingly.
For instance, if you dial 3, the PIC will count three low-high transitions and then blink an LED 3 times.
The LED, as you may have inferred, is unnecessary for this to operate and is just there to give you visible feedback. You can substitute any output device that you deem necessary.
*********************
Here is some code:
*********************
CPU = 16F877
MHZ = 20
CONFIG 16254
clicker var word
startcountin var word
countclicks var word
repvar var word
clacker var word
largefig var word
main:
countclicks = 0
repvar = 0
'sets/resets values
high B2
rctime B2,1,startcountin
countclicks = 0
if startcountin > 10 then goto countmeup
' checks to see if dial has been turned and goes to subroutine if it has
goto main
'================
countmeup:
high B1
rctime B1,1,clacker
'sets compare value
goto countmeuploop
'================
countmeuploop:
high B1
rctime B1,1,clicker
'checks counting value
largefig = clacker + 100
'sets a value for the threshold that will be larger
'than 0 but lesser than possible pin-high values
if largefig < clicker then
countclicks = countclicks + 1
endif
'adds 1 value every time a low to high transition is recorded
high B2
rctime B2,1,startcountin
if startcountin < 10 then
if countclicks > 0 then
goto blink
else
goto main
endif
endif
'checks to see if the dial has recoiled back to its initial state
'if it has and a number was dialed it goes to the LED routine
'otherwise, if no number was dialed it goes to main
clacker = clicker
'resets the comparison value to the current pin value
goto countmeuploop
'no pauses AT ALL in this routine!
'================
blinker:
repvar = repvar + 1
'counts each repetition of this routine
high B3
pause 1000
low B3
pause 1000
'blinks the LED
if repvar = countclicks then
repvar = 0
goto main
endif
'if the repetitions equal the number of times the LED should blink
'then it goes back to the main routine
goto blinker
The code is essentially determining when someone has turned the dial and then does edge-detection on the signal (determining low-high transitions) until the dial recoils to its initial state. After tallying the number of times it measures a signal transition, it then blinks the LED accordingly.
For instance, if you dial 3, the PIC will count three low-high transitions and then blink an LED 3 times.
The LED, as you may have inferred, is unnecessary for this to operate and is just there to give you visible feedback. You can substitute any output device that you deem necessary.
*********************
Here is some code:
*********************
CPU = 16F877
MHZ = 20
CONFIG 16254
clicker var word
startcountin var word
countclicks var word
repvar var word
clacker var word
largefig var word
main:
countclicks = 0
repvar = 0
'sets/resets values
high B2
rctime B2,1,startcountin
countclicks = 0
if startcountin > 10 then goto countmeup
' checks to see if dial has been turned and goes to subroutine if it has
goto main
'================
countmeup:
high B1
rctime B1,1,clacker
'sets compare value
goto countmeuploop
'================
countmeuploop:
high B1
rctime B1,1,clicker
'checks counting value
largefig = clacker + 100
'sets a value for the threshold that will be larger
'than 0 but lesser than possible pin-high values
if largefig < clicker then
countclicks = countclicks + 1
endif
'adds 1 value every time a low to high transition is recorded
high B2
rctime B2,1,startcountin
if startcountin < 10 then
if countclicks > 0 then
goto blink
else
goto main
endif
endif
'checks to see if the dial has recoiled back to its initial state
'if it has and a number was dialed it goes to the LED routine
'otherwise, if no number was dialed it goes to main
clacker = clicker
'resets the comparison value to the current pin value
goto countmeuploop
'no pauses AT ALL in this routine!
'================
blinker:
repvar = repvar + 1
'counts each repetition of this routine
high B3
pause 1000
low B3
pause 1000
'blinks the LED
if repvar = countclicks then
repvar = 0
goto main
endif
'if the repetitions equal the number of times the LED should blink
'then it goes back to the main routine
goto blinker
Testing.
![6A.jpg](/proxy/?url=https://content.instructables.com/FP7/ME2L/9KLEYVZDP3Y/FP7ME2L9KLEYVZDP3Y.jpg&filename=6A.jpg)
If you did everything the same as I, it should work (see video).
If it doesn't work, make sure that you wired everything correctly and that the code is copied correctly. Also, be certain that your resonator (or crystal) is 20 MHZ. If you wrote your own code make sure there are no pauses in the routine that checks for low-high transitions.
If it doesn't work, make sure that you wired everything correctly and that the code is copied correctly. Also, be certain that your resonator (or crystal) is 20 MHZ. If you wrote your own code make sure there are no pauses in the routine that checks for low-high transitions.
Downloads
Go Beyond.
![7A.jpg](/proxy/?url=https://content.instructables.com/FEB/D561/YVPEYVZDP6C/FEBD561YVPEYVZDP6C.jpg&filename=7A.jpg)
Figure out some sort of other use for the rotary dial other than blinking an LED.