Step 5Assemble the code.
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 Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|












































