3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Rotary dialer PIC interface

Step 5Assemble the code.

Assemble the code.
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
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
2360
Followers
200
Author:randofo(Randy Sarafan loves you!)
I am the Technology Editor here at Instructables. I am also the author of the books 'Simple Bots,' and '62 Projects to Make with a Dead Computer'. Subscribing to me = fun and excitement!