MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 1 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00001 ;************************************************************************** 00002 ; pp001.ASM 00003 ; 00004 ; PROGRAM: Perfect Pubround LED flasher 12/06/1009 00005 ; 00006 ; DESCRIPTION: A rechip of teh Maplin Lottery Picker to demo the "perfect pub round" or "endpoint Picked In Proportions" algorithm. 00007 ; 00008 ; AUTHOR: Douglas Rice 00009 ; Copyright 2009 00010 ; 00011 ; 00012 ;================================================================ 00013 ; "Perfect Pub Round" or "endpoints Picked In Proportion" demo 00014 ;================================================================ 00015 ; 00016 ; endpoints Picked in Proportion - 00017 ; 00018 ; Given a stream of events, and a set of N destinations, pick one and only one of the destinations or en dpoints for each event. 00019 ; 00020 ; Try to make sure the least bunching of events to each destination. 00021 ; 00022 ; e.g there are three destinations and the proportions required are 25%,50%,25% 00023 ; 00024 ; It would be possible to send events in this sequence. Send the next 25 events to endpoint A, then the next 50 events to endpoint B then the next 25 events to endpoint C and start again. 00025 ; this bunches the events excessively. This is not prefered. The systems receiving the events would need to be able at full event rate for the duration of these bunches. 00026 ; 00027 ; As reason for having N endpoints is to provide enough processing power to support an event rate of gre ater than X. 00028 ; The endpoints can only support an event rate of X. 00029 ; 00030 ; The endpoints have elastic buffers to assorb offered event rates of greater than X until the elastic b uffers are full. 00031 ; 00032 ; The best sequence would be: send next event to A, next event to B, next event to C, next event to B, n ext event to C 00033 ; 00034 ; Another sequence could be: send next event to A, next event to B, next event to B, next event to C, a nd start again. 00035 ; 00036 ; 00037 ; This demo does the Perfect Pub Round algorithm on a re-chiped Lottery Number Picker Kit I purchased fr om Maplin. 00038 ; I have also called it ePIP, which is "effective proportions in parts" or "endpoints Picked In Proporti on" 00039 ; 00040 ; It also allows you to enter the proportions, using the single button. 00041 ; 00042 ; For the demo we have 7 segment display so have 7 destinations, one segment per destination. The destin ation picked is shown by which segment is flashed. MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 2 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00043 ; 00044 ; 00045 ; Say we have three desintaions and you want to distribute calls in the proportions 25%, 40%, 35% to des tinations A, B, C. 00046 ; 00047 ; A call can only go to A, B or C. 00048 ; 00049 ; It is similar to having Oscillators whose frequencies are 25 times clock, 40 times clock , 35 times cl ock. 00050 ; 00051 ; Clock happens when a call needs to be distributed. 00052 ; 00053 ; If these are clocked, when they overflow, and the overflows are in proportions. However this is not qu ite what is required. 00054 ; 00055 ; The Perfect Pubround algorithm knocks back one of the "Oscillators" based on the one with the largest count, by the sum of proportions. 00056 ; 00057 ;================================================================ 00058 ; Demo overview 00059 ;================================================================ 00060 ; 00061 ; 00062 ; There is a display mode when the wants are used to set the frequency of 1:1 oscillators that clock eac h segment. 00063 ; 00064 ; 00065 ; It has two 7 segment displays, so for the load share output the destination picked by mapping the dest inations onto the segments. 00066 ; 00067 ; In summary you have a stream of calls and each call needs to be delivered to one of 7 destinations in the proportions specified. 00068 ; 00069 ; To acheive this have a list of wants, which can be set between 0 and F. 00070 ; 00071 ; For each destination ( or segment ) { 00072 ; have one want and a bucket variable. 00073 ; Add want to bucket 00074 ; note which is the fullest bucket. 00075 ; } 00076 ; 00077 ; The fullest bucket is the destination to pick. 00078 ; Now take summ of wants away from the fullest bucket. 00079 ; 00080 ; There is a problem if all wants are 0 as there must be a destination picked. 00081 ; On each itteration add the wants to 00082 ; 00083 ; 00084 ;================================================================ 00085 ; Operation 00086 ;================================================================ 00087 ; 00088 ; Turn on picker and the left segment displays ePIP using the porportions 8,8,8,8,8,8,8. MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 3 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00089 ; The right disply shows the segment's proportion. This can be between 0 to 0xF. 00090 ; 00091 ; The segments are picked using the proportions. 00092 ; 00093 ; Press the button, and the rate of picks increases. 00094 ; 00095 ; After the fastest rate, there is a display mode where the proportions are used to set the frequency of flash of the segments. 00096 ; The left display shows the frequencies as 1:1 oscillators, the right display shows the clock edge. 00097 ; This gives a pleasing display that slowly changes. 00098 ; 00099 ; Top set the proportions hold the button down for a long press, 00100 ; The left sisplay should light one segment and teh right display should show the current count. 00101 ; 00102 ; a short press of the button is used to increment the count. 00103 ; a long press increments the segment being set. 00104 ; 00105 ; The 8th segment is used to set special modes. No segment is displayed. If the count is 0 or even, the proportions are not modified. 00106 ; If the right number is odd, the proportions are modified tos that the display in more "interesting. 00107 ; A segments proportion is reduced based on the segment just picked for display. The proportions slowly decrese until all proportions reach 0. 00108 00109 ; A very long press returned to the display mode. 00110 ; 00111 00112 ;================================================================ 00113 ; Test of One button, 00114 ; 00115 ; 00116 ; Want a single button that if pressed quickly increments a counter. 00117 ; If there is a pause between rapid presses, then move onto the next digit. 00118 ; 00119 ; There is a problem with zero, On phone diallers, it is coded as 10, here is it coded as a long press. 00120 ; 00121 ; Generate events: 00122 ; SHORT_PRESS - If release timer running, then events 00123 ; LONG_PRESS - 00124 ; 00125 ; SHORT_PRESS Start Timer on press, if running on release, then SHORT_PRESS 00126 ; ______--______________________ 00127 ; 00128 ; ______tttt__ - Timer is stopped if running and restarted as release timer 00129 00130 ; LONG_PRESS Start Timer on press, on timout, increment a counter and restart timer. 00131 ; ______--------------__ 00132 ; 00133 ; ______tttt|tttt|ttttt_____ - Timer is stopped if running and restarted as release timer 00134 ; 00135 ; 00136 ; reset pressed counter on count 00137 ; ______----_______ count ticks while pressed and action on release 00138 ; MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 4 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00139 ; During press - count timeouts. These tick at about 1 per second. 00140 ; On release - switch of pressed Counter. 00141 ; On release - pressedCounter = 0 -SHORT PRESS - Increment LDwant for displayed segment 00142 ; On release - pressedCounter = 1 -LONG PRESS - Move onto next segment 00143 ; On release - pressedCounter = 2 -VERY LONG PRESS - return to RUN mode 00144 ; On release - pressedCounter > 2 -VERY LONG PRESS - return to RUN mode 00145 ; 00146 ; On release start a timer to end incrementing the same digit. 00147 ; 00148 ; On next press, if long release timer is stopped move onto next digit. 00149 ; On next press, if long release timer is running increment current digit 00150 ; 00151 ; long presses stop the timer. 00152 ; 00153 ; if count = 1 then ZERO 00154 ; if count = 0 then increment count and wait long release 00155 ; if pressed while timer running, then increment current digit 00156 ; 00157 ; The LONG PRESS timer is about 1 second, so a puase of presses of about a seconds moves onto the next d igit 00158 ; There is also an inactivity timer, which resets the input if no press is pressed for about 10 seconds. 00159 ; 00160 ; 00161 ; a short press on turn on cycles throuh the speed 00162 ; a short press in setting mode increments count for the digit. 00163 ; a long press enters segment setting mode and moves on to teh next segment 00164 ; a very long press goes back to display mode 00165 ; 00166 ;************************************************************************** 00167 ;Maplin Lottery picker 16F627A 00168 ;read from chip 00169 ; 00170 ; 00171 ;RA0 - Mux Left high to light to Transistor 00172 ;RA1 - Mux right 00173 ;RA3 - Switch pulled low by 10K goes high on press. 00174 ; 00175 ; LED 00176 ; | 00177 ; |/ 00178 ;RA0 ---[ 1K ]---| 00179 ; |\ 00180 ; | 00181 ; Vss 00182 ; 00183 ; 00184 ;Take port B high. 00185 ; 00186 ;Prort B ----[ 1K8 ]----LED 00187 ; 00188 ; rb3 00189 ;rb1 rb2 00190 ; rb0 MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 5 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00191 ;rb5 rb4 00192 ; rb6 00193 ; 00194 ;Left decimal point n/c 00195 ;right decimal point pulled high via 330F 00196 ; 00197 ;************************************************************************** 00198 ; 00199 ; flash segment being set with digit 00200 00201 ; 00202 ;mode: setting 00203 00204 ; display 00205 00206 00207 00208 00209 ; 00210 ; 00211 ; 00212 ;************************************************************************** 00213 00214 00215 00216 00217 #define dev16F628 00218 00219 ;-------------------------------------------------------------------------- 00220 ; Sec 0. Configs for different chips 00221 ;-------------------------------------------------------------------------- 00222 00223 00224 ;-------------------------------------------------------------------------- 00225 ; Sec 0.2 Device: 16F628 00226 ;-------------------------------------------------------------------------- 00227 00228 ifdef dev16F628 00229 00230 00231 list p=16f628 ; list directive to define processor 00232 #include ; processor specific variable definitions 00001 LIST 00002 ; P16F628.INC Standard Header File, Version 1.01 Microchip Technology, Inc. 00261 LIST 00233 2007 3F11 00234 __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _INTRC_OSC_CLKOUT & _MCLRE_OFF & _LVP_OF F 00235 Warning[207]: Found label after column 1. (PORTLEDS) 00000005 00236 PORTLEDS EQU PORTA Warning[207]: Found label after column 1. (RAMSTART) 00000020 00237 RAMSTART EQU 0x20 MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 6 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00238 00239 endif 00240 00241 ;-------------------------------------------------------------------------- 00242 ; Sec 1. Equates and Constants 00243 ;-------------------------------------------------------------------------- 00244 ; The General Purpose Registers start at the end of the 00245 ; Special Purpose Registers. 00246 00247 00248 00249 ; DoTimeSlice bits 00250 ; these bits are set to schedule a timer chain event 00000000 00251 DTsS4event EQU 0 00000001 00252 DTsSevent EQU 1 00253 00254 ;-------------------------------------------------------------------------- 00255 ; Sec 1.1 Button and LED 00256 ;-------------------------------------------------------------------------- 00257 00000002 00258 BUTTON_ONE EQU 2 00259 00260 ;-------------------------------------------------------------------------- 00261 ; Sec 1.0 MACROS 00262 ;-------------------------------------------------------------------------- 00263 00264 TEST_STRADDLE MACRO START 00265 if high( $ ) != high( START ) 00266 Error "Table straddles Page Boundary " + Start 00267 endif 00268 endm 00269 00270 ;-------------------------------------------------------------------------- 00271 ; Sec 2.0 Variables 00272 ;-------------------------------------------------------------------------- 00273 ; Variables start 0x20 00274 ; 00275 00276 cblock RAMSTART 00000020 00277 DoTimeSlice 00278 00279 ; clock chain variables 00000021 00280 CLtmr4sec ; counts quarter seconds 00000022 00281 CLnbcdS ; stores current time 00282 00000023 00283 IPlast ; Input variables 00000024 00284 IPnew 00285 00000025 00286 IPbuttonEvent 00000026 00287 IPbuttonEventt 00288 ;IPbuttonEventF 00000027 00289 IPsetState 00290 MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 7 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00000028 00291 IPoneTimer 00000029 00292 IPoneInactivityTimer 0000002A 00293 IPoneCnt 0000002B 00294 IPonePressedCnt 00295 0000002C 00296 IPonePORTB 00297 00298 ; Buckets 0000002D 00299 LDindex 0000002E 00300 LDtotalBucket 0000002F 00301 LDtotalWant 00000030 00302 LDbucketCarry 00000031 00303 LDbucketCarryOsc 00304 00000032 00305 LDmaxPtr 00000033 00306 LDmaxVal 00307 00000034 00308 LDtemp 00309 00000035 00310 LDbucket0 00000036 00311 LDbucket1 00000037 00312 LDbucket2 00000038 00313 LDbucket3 00000039 00314 LDbucket4 0000003A 00315 LDbucket5 0000003B 00316 LDbucket6 0000003C 00317 LDbucket7 00318 00319 ; 00320 ; Set these up in the proportions ( or Parts ) required 00321 ; 00322 ; Each segment of the 7 Segment LED display is a destination. 0000003D 00323 LDwant0 0000003E 00324 LDwant1 0000003F 00325 LDwant2 00000040 00326 LDwant3 00000041 00327 LDwant4 00000042 00328 LDwant5 00000043 00329 LDwant6 00000044 00330 LDwant7 00331 00332 00000045 00333 PPcnt 00000046 00334 PPindex 00000047 00335 PPsettingMode 00000048 00336 PPspeed 00337 00338 00339 00340 ; 00341 ; diplay Phase 00342 ; 00343 MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 8 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00000049 00344 PPphaseLast 0000004A 00345 PPphase 0000004B 00346 PPphaseEvent 00347 0000004C 00348 PPphaseLastH 0000004D 00349 PPphaseH 0000004E 00350 PPphaseEventH 00351 00352 00353 ; 00354 ; display buffers - these are multiplexed onto the diplay 00355 ; 0000004F 00356 PPdispLeft 00000050 00357 PPdispRight 00358 00359 ; 00000051 00360 PPmode ; if PPmode:0 is set then setting, else display 00361 00000052 00362 LastVar 00363 endc 00364 00365 00000030 00366 OPbufferStart EQU 0x30 ; 32 bytes of files that can store Dates 00367 00368 ;PORT_BUTTONS EQU IPonePORTB 00000005 00369 PORT_BUTTONS EQU PORTA 00370 00371 00372 ;-------------------------------------------------------------------------- 00373 ; Sec 3. Program Code 00374 ;-------------------------------------------------------------------------- 00375 0000 00376 ORG 0 0000 2829 00377 goto Start 00378 0004 00379 ORG 4 0004 2A09 00380 goto Intrtn 00381 00382 00383 ;-------------------------------------------------------------------------- 00384 ; Sec 4.3 Tables - look up 00385 ;-------------------------------------------------------------------------- 00386 00387 0005 00388 LDlookupBit 0005 00B4 00389 movwf LDtemp 0006 3000 00390 movlw high( IPjmpTable4Start ) 0007 008A 00391 movwf PCLATH 00392 ; Its not a CLICK or HOLD 0008 0834 00393 movfw LDtemp 00394 00395 ; 00396 ; set choice State Table - limited to 8 states MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 9 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00397 ; 00398 ; rb3 00399 ;rb1 rb2 00400 ; rb0 00401 ;rb5 rb4 00402 ; rb6 00403 ; 00404 ; spin clockwise 00405 ; 00406 00000001 00407 rb0 equ 1 << 0 00000002 00408 rb1 equ 1 << 1 00000004 00409 rb2 equ 1 << 2 00000008 00410 rb3 equ 1 << 3 00000010 00411 rb4 equ 1 << 4 00000020 00412 rb5 equ 1 << 5 00000040 00413 rb6 equ 1 << 6 00000080 00414 rb7 equ 1 << 7 00000000 00415 off equ 0 00416 00417 0009 00418 IPjmpTable4Start 0009 3907 00419 andlw 0x07 000A 0782 00420 addwf PCL,f 00421 000B 3401 00422 retlw rb0 000C 3402 00423 retlw rb1 000D 3408 00424 retlw rb3 000E 3404 00425 retlw rb2 00426 000F 3410 00427 retlw rb4 0010 3440 00428 retlw rb6 0011 3420 00429 retlw rb5 00430 0012 3400 00431 retlw 0x00 00432 IF 0 != ( high ( $ ) - high ( IPjmpTable4Start ) ) 00433 Error "Table 4 straddles Page Boundary " 00434 ENDIF 00435 0013 00436 IPjmpTable4End 00437 00438 ; 00439 ; set choice State Table - limited to 8 states 00440 ; 00441 ; rb3 00442 ;rb1 rb2 00443 ; rb0 00444 ;rb5 rb4 00445 ; rb6 00446 ; 00447 00448 0013 00449 LDlookupNum MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 10 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0013 00B4 00450 movwf LDtemp 0014 3000 00451 movlw high( IPjmpTable5Start ) 0015 008A 00452 movwf PCLATH 00453 ; Its not a CLICK or HOLD 00454 ; movfw LDmaxPtr 00455 0016 0834 00456 movfw LDtemp 00457 0017 00458 IPjmpTable5Start 00459 00460 ; 00461 ; 7 Segment display look up table 00462 ; 00463 0017 390F 00464 andlw 0x0F 0018 0782 00465 addwf PCL,f 0019 347E 00466 retlw rb1 | rb2 | rb3 | rb4 | rb5 | rb6 ; 0 001A 3414 00467 retlw rb2 | rb4 ; 1 001B 346D 00468 retlw rb0 | rb2 | rb3 | rb5 | rb6 ; 2 001C 345D 00469 retlw rb0 | rb2 | rb3 | rb4 | rb6 ; 3 001D 3417 00470 retlw rb0 | rb1 | rb2 | rb4 ; 4 001E 345B 00471 retlw rb0 | rb1 | rb3 | rb4 | rb6 ; 5 001F 347B 00472 retlw rb0 | rb1 | rb3 | rb4 | rb5 | rb6 ; 6 0020 341C 00473 retlw rb2 | rb3 | rb4 ; 7 0021 347F 00474 retlw rb0 | rb1 | rb2 | rb3 | rb4 | rb5 | rb6 ; 8 0022 345F 00475 retlw rb0 | rb1 | rb2 | rb3 | rb4 | rb6 ; 9 0023 343F 00476 retlw rb0 | rb1 | rb2 | rb3 | rb4 | rb5 ; A 0024 3473 00477 retlw rb0 | rb1 | rb4 | rb5 | rb6 ; b 0025 346A 00478 retlw rb1 | rb3 | rb5 | rb6 ; C 0026 3475 00479 retlw rb0 | rb2 | rb4 | rb5 | rb6 ; d 0027 346B 00480 retlw rb0 | rb1 | rb3 | rb5 | rb6 ; E 0028 342B 00481 retlw rb0 | rb1 | rb3 | rb5 ; F 00482 IF 0 != ( high ( $ ) - high ( IPjmpTable5Start ) ) 00483 Error "Table 5 straddles Page Boundary " 00484 ENDIF 00485 0029 00486 IPjmpTable5End 00487 00488 00489 IF 0 != high ( $ ) 00490 Error "Table not in page 0 " 00491 ENDIF 00492 00493 00494 00495 00496 00497 00498 00499 00500 00501 ;-------------------------------------------------------------------------- 00502 ; Sec 3.1 Main Program Init Code MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 11 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00503 ;-------------------------------------------------------------------------- 00504 0029 00505 Start 0029 2035 00506 call LDloadShareInit 002A 21F9 00507 call PPinit 002B 21D4 00508 call INinit 002C 282D 00509 goto MainLoop 00510 00511 ;-------------------------------------------------------------------------- 00512 ; Sec 3.2 Main Program 00513 ;-------------------------------------------------------------------------- 00514 002D 00515 MainLoop 002D 2120 00516 call CLtimeslice 00517 00518 ; Any events that exist 002E 1820 00519 BTFSC DoTimeSlice,DTsS4event ; On 1/4 Second Tick 002F 212C 00520 call SS4tick 00521 0030 18A0 00522 BTFSC DoTimeSlice,DTsSevent ; On Second Tick 0031 217E 00523 call SStick 00524 0032 1926 00525 BTFSC IPbuttonEventt,BUTTON_ONE ; On BUTTON_ONE Press 0033 2183 00526 call IPoneChanged 00527 00528 ; call IPtimesliceFast ; also does switch action if edge found. 0034 282D 00529 goto MainLoop 00530 00531 ;-------------------------------------------------------------------------- 00532 ; Sec 4. Subroutines, procedures and functions 00533 ;-------------------------------------------------------------------------- 00534 00535 ;-------------------------------------------------------------------------- 00536 ; Sec 4.1 Load Share routines - LD 00537 ;-------------------------------------------------------------------------- 00538 ; 00539 ; USing the Winner takes all method. 00540 ; For each destination, have a bucket and a corresponding want 00541 ; 00542 ; For each event add the want to the bucket 00543 ; Find out which bucket if fullest, i.e is the largest value. 00544 ; This this the destination to be used, so now subtract the sum of the wants from this bucket. 00545 ; 00546 ; 00547 00548 0035 00549 LDloadShareInit 0035 3000 00550 movlw 0 0036 00AD 00551 movwf LDindex 00552 00553 0037 01B2 00554 clrf LDmaxPtr 0038 20E3 00555 call LDclearBuckets MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 12 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00556 0039 3008 00557 movlw 8 003A 00BD 00558 movwf LDwant0 003B 3008 00559 movlw 8 003C 00BE 00560 movwf LDwant1 003D 3008 00561 movlw 8 003E 00BF 00562 movwf LDwant2 003F 3008 00563 movlw 8 0040 00C0 00564 movwf LDwant3 0041 3008 00565 movlw 8 0042 00C1 00566 movwf LDwant4 0043 3008 00567 movlw 8 0044 00C2 00568 movwf LDwant5 0045 3008 00569 movlw 8 0046 00C3 00570 movwf LDwant6 00571 00572 ; LDwant7 is being used for configuration 00573 ; bit 0 - select auto decrement. 00574 ; bit 1 - select speed 00575 ; bit 2 - select speed 0047 3003 00576 movlw 3 0048 00C4 00577 movwf LDwant7 00578 0049 0008 00579 return 00580 00581 expand 00582 ;Define macro Read 00583 LDloadShareMac macro n 00584 00585 MOVF LDwant#v(n),w 00586 addwf LDbucket#v(n),f 00587 00588 MOVF LDbucket#v(n),w 00589 addwf LDtotalBucket,f 00590 00591 00592 comf LDmaxVal,w 00593 addwf LDbucket#v(n),w 00594 00595 bc LDloadShare#v(n) 00596 ; New max value 00597 MOVF LDbucket#v(n),w 00598 movwf LDmaxVal 00599 movlw #v(n) 00600 movwf LDmaxPtr 00601 LDloadShare#v(n) Warning[205]: Found directive in column 1. (endm) 00602 endm 00603 004A 00604 LDdoloadShare 004A 3080 00605 movlw 0x80 004B 00B3 00606 movwf LDmaxVal 004C 01B2 00607 clrf LDmaxPtr MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 13 LOC OBJECT CODE LINE SOURCE TEXT VALUE 004D 01AE 00608 clrf LDtotalBucket 00609 00610 LDloadShareMac 0 M 004E 083D M MOVF LDwant0,w 004F 07B5 M addwf LDbucket0,f M 0050 0835 M MOVF LDbucket0,w 0051 07AE M addwf LDtotalBucket,f M M 0052 0933 M comf LDmaxVal,w 0053 0735 M addwf LDbucket0,w M 0054 1803 285A M bc LDloadShare0 M ; New max value 0056 0835 M MOVF LDbucket0,w 0057 00B3 M movwf LDmaxVal 0058 3000 M movlw 0 0059 00B2 M movwf LDmaxPtr 005A M LDloadShare0 00611 LDloadShareMac 1 M 005A 083E M MOVF LDwant1,w 005B 07B6 M addwf LDbucket1,f M 005C 0836 M MOVF LDbucket1,w 005D 07AE M addwf LDtotalBucket,f M M 005E 0933 M comf LDmaxVal,w 005F 0736 M addwf LDbucket1,w M 0060 1803 2866 M bc LDloadShare1 M ; New max value 0062 0836 M MOVF LDbucket1,w 0063 00B3 M movwf LDmaxVal 0064 3001 M movlw 1 0065 00B2 M movwf LDmaxPtr 0066 M LDloadShare1 00612 LDloadShareMac 2 M 0066 083F M MOVF LDwant2,w 0067 07B7 M addwf LDbucket2,f M 0068 0837 M MOVF LDbucket2,w 0069 07AE M addwf LDtotalBucket,f M M 006A 0933 M comf LDmaxVal,w 006B 0737 M addwf LDbucket2,w M 006C 1803 2872 M bc LDloadShare2 MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 14 LOC OBJECT CODE LINE SOURCE TEXT VALUE M ; New max value 006E 0837 M MOVF LDbucket2,w 006F 00B3 M movwf LDmaxVal 0070 3002 M movlw 2 0071 00B2 M movwf LDmaxPtr 0072 M LDloadShare2 00613 LDloadShareMac 3 M 0072 0840 M MOVF LDwant3,w 0073 07B8 M addwf LDbucket3,f M 0074 0838 M MOVF LDbucket3,w 0075 07AE M addwf LDtotalBucket,f M M 0076 0933 M comf LDmaxVal,w 0077 0738 M addwf LDbucket3,w M 0078 1803 287E M bc LDloadShare3 M ; New max value 007A 0838 M MOVF LDbucket3,w 007B 00B3 M movwf LDmaxVal 007C 3003 M movlw 3 007D 00B2 M movwf LDmaxPtr 007E M LDloadShare3 00614 LDloadShareMac 4 M 007E 0841 M MOVF LDwant4,w 007F 07B9 M addwf LDbucket4,f M 0080 0839 M MOVF LDbucket4,w 0081 07AE M addwf LDtotalBucket,f M M 0082 0933 M comf LDmaxVal,w 0083 0739 M addwf LDbucket4,w M 0084 1803 288A M bc LDloadShare4 M ; New max value 0086 0839 M MOVF LDbucket4,w 0087 00B3 M movwf LDmaxVal 0088 3004 M movlw 4 0089 00B2 M movwf LDmaxPtr 008A M LDloadShare4 00615 LDloadShareMac 5 M 008A 0842 M MOVF LDwant5,w 008B 07BA M addwf LDbucket5,f M 008C 083A M MOVF LDbucket5,w 008D 07AE M addwf LDtotalBucket,f M M MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 15 LOC OBJECT CODE LINE SOURCE TEXT VALUE 008E 0933 M comf LDmaxVal,w 008F 073A M addwf LDbucket5,w M 0090 1803 2896 M bc LDloadShare5 M ; New max value 0092 083A M MOVF LDbucket5,w 0093 00B3 M movwf LDmaxVal 0094 3005 M movlw 5 0095 00B2 M movwf LDmaxPtr 0096 M LDloadShare5 00616 LDloadShareMac 6 M 0096 0843 M MOVF LDwant6,w 0097 07BB M addwf LDbucket6,f M 0098 083B M MOVF LDbucket6,w 0099 07AE M addwf LDtotalBucket,f M M 009A 0933 M comf LDmaxVal,w 009B 073B M addwf LDbucket6,w M 009C 1803 28A2 M bc LDloadShare6 M ; New max value 009E 083B M MOVF LDbucket6,w 009F 00B3 M movwf LDmaxVal 00A0 3006 M movlw 6 00A1 00B2 M movwf LDmaxPtr 00A2 M LDloadShare6 00617 00618 ifdef doug 00619 LDloadShare0 00620 movfw LDwant0 00621 addwf LDbucket0,f 00622 MOVFw LDbucket0 00623 addwf LDtotalBucket,f 00624 00625 comf LDmaxVal,w 00626 addwf LDbucket0,w 00627 00628 bc LDloadShare1 00629 ; New max value 00630 movfw LDbucket0 00631 movwf LDmaxVal 00632 movlw 0 00633 movwf LDmaxPtr 00634 endif 00635 00636 ; 00637 ; now knock back the fullest bucket with the total counts. 00638 ; 00A2 1383 00639 bankisel LDwant0 00640 MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 16 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00A3 3035 00641 movlw LDbucket0 00A4 0732 00642 addwf LDmaxPtr,w 00A5 0084 00643 movwf FSR 00A6 082E 00644 movfw LDtotalBucket 00A7 0280 00645 subwf INDF,F 00646 00A8 0008 00647 return 00648 00649 00650 00651 00652 ;Define macro Read 00653 LDfreqMac macro n 00654 MOVF LDwant#v(n),w 00655 addwf LDbucket#v(n),f 00656 skpc 00657 goto LDfreqMac#v(n) 00658 movlw #v(n) 00659 call LDlookupBit 00660 iorwf LDbucketCarry,f 00661 xorwf LDbucketCarryOsc,f 00662 LDfreqMac#v(n) Warning[205]: Found directive in column 1. (endm) 00663 endm 00664 00665 00A9 00666 LDdoFreq 00A9 01B0 00667 clrf LDbucketCarry 00668 LDfreqMac 0 00AA 083D M MOVF LDwant0,w 00AB 07B5 M addwf LDbucket0,f 00AC 1C03 M skpc 00AD 28B2 M goto LDfreqMac0 00AE 3000 M movlw 0 00AF 2005 M call LDlookupBit 00B0 04B0 M iorwf LDbucketCarry,f 00B1 06B1 M xorwf LDbucketCarryOsc,f 00B2 M LDfreqMac0 00669 LDfreqMac 1 00B2 083E M MOVF LDwant1,w 00B3 07B6 M addwf LDbucket1,f 00B4 1C03 M skpc 00B5 28BA M goto LDfreqMac1 00B6 3001 M movlw 1 00B7 2005 M call LDlookupBit 00B8 04B0 M iorwf LDbucketCarry,f 00B9 06B1 M xorwf LDbucketCarryOsc,f 00BA M LDfreqMac1 00670 LDfreqMac 2 00BA 083F M MOVF LDwant2,w 00BB 07B7 M addwf LDbucket2,f 00BC 1C03 M skpc 00BD 28C2 M goto LDfreqMac2 MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 17 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00BE 3002 M movlw 2 00BF 2005 M call LDlookupBit 00C0 04B0 M iorwf LDbucketCarry,f 00C1 06B1 M xorwf LDbucketCarryOsc,f 00C2 M LDfreqMac2 00671 LDfreqMac 3 00C2 0840 M MOVF LDwant3,w 00C3 07B8 M addwf LDbucket3,f 00C4 1C03 M skpc 00C5 28CA M goto LDfreqMac3 00C6 3003 M movlw 3 00C7 2005 M call LDlookupBit 00C8 04B0 M iorwf LDbucketCarry,f 00C9 06B1 M xorwf LDbucketCarryOsc,f 00CA M LDfreqMac3 00672 LDfreqMac 4 00CA 0841 M MOVF LDwant4,w 00CB 07B9 M addwf LDbucket4,f 00CC 1C03 M skpc 00CD 28D2 M goto LDfreqMac4 00CE 3004 M movlw 4 00CF 2005 M call LDlookupBit 00D0 04B0 M iorwf LDbucketCarry,f 00D1 06B1 M xorwf LDbucketCarryOsc,f 00D2 M LDfreqMac4 00673 LDfreqMac 5 00D2 0842 M MOVF LDwant5,w 00D3 07BA M addwf LDbucket5,f 00D4 1C03 M skpc 00D5 28DA M goto LDfreqMac5 00D6 3005 M movlw 5 00D7 2005 M call LDlookupBit 00D8 04B0 M iorwf LDbucketCarry,f 00D9 06B1 M xorwf LDbucketCarryOsc,f 00DA M LDfreqMac5 00674 LDfreqMac 6 00DA 0843 M MOVF LDwant6,w 00DB 07BB M addwf LDbucket6,f 00DC 1C03 M skpc 00DD 28E2 M goto LDfreqMac6 00DE 3006 M movlw 6 00DF 2005 M call LDlookupBit 00E0 04B0 M iorwf LDbucketCarry,f 00E1 06B1 M xorwf LDbucketCarryOsc,f 00E2 M LDfreqMac6 00675 ; 00E2 0008 00676 return 00677 00678 00679 00E3 00680 LDclearBuckets 00E3 01B2 00681 clrf LDmaxPtr 00E4 01B5 00682 clrf LDbucket0 MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 18 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00E5 01B6 00683 clrf LDbucket1 00E6 01B7 00684 clrf LDbucket2 00E7 01B8 00685 clrf LDbucket3 00E8 01B9 00686 clrf LDbucket4 00E9 01BA 00687 clrf LDbucket5 00EA 01BB 00688 clrf LDbucket6 00EB 01BC 00689 clrf LDbucket7 00690 00EC 01B1 00691 clrf LDbucketCarryOsc 00692 00ED 0008 00693 return 00694 00695 00696 00697 00698 00EE 00699 LDloadShareDecWants 00700 00EE 0FC5 00701 incfsz PPcnt,f 00EF 0008 00702 return 00703 00F0 20E3 00704 call LDclearBuckets 00705 00F1 0BBD 00706 decfsz LDwant0,f 00F2 0008 00707 return 00708 00F3 0BBE 00709 decfsz LDwant1,f 00F4 0008 00710 return 00711 00F5 0BBF 00712 decfsz LDwant2,f 00F6 0008 00713 return 00714 00F7 0BC0 00715 decfsz LDwant3,f 00F8 0008 00716 return 00717 00F9 0BC1 00718 decfsz LDwant4,f 00FA 0008 00719 return 00720 00FB 0BC2 00721 decfsz LDwant5,f 00FC 0008 00722 return 00723 00FD 0BC3 00724 decfsz LDwant6,f 00FE 0008 00725 return 00726 00FF 0008 00727 return 00728 0100 00729 LDloadShareIncWants 0100 1283 1303 00730 banksel PPcnt 0102 0FC5 00731 incfsz PPcnt,f 0103 0008 00732 return 00733 00734 00735 ; W = want[ PPindex ] MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 19 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00736 0104 0832 00737 movfw LDmaxPtr 00738 00739 ; add offet into files 0105 3E3D 00740 addlw LDwant0 00741 0106 1383 00742 bankisel LDwant0 0107 0084 00743 movwf FSR 0108 0380 00744 decf INDF,f 00745 00746 ; clear buckets and maxPtr to start with a clean sheet. 0109 20E3 00747 call LDclearBuckets 010A 0008 00748 return 00749 00750 010B 00751 LDloadShareMaskCounts 010B 300F 00752 movlw 0x0F 010C 05BD 00753 andwf LDwant0,f 010D 05BE 00754 andwf LDwant1,f 010E 05BF 00755 andwf LDwant2,f 010F 05C0 00756 andwf LDwant3,f 0110 05C1 00757 andwf LDwant4,f 0111 05C2 00758 andwf LDwant5,f 0112 05C3 00759 andwf LDwant6,f 0113 05C4 00760 andwf LDwant7,f 0114 0008 00761 return 00762 00763 ;-------------------------------------------------------------------------- 00764 ; Sec 4.2 Button Poll Routine 00765 ;-------------------------------------------------------------------------- 00766 0115 00767 IPtimeslice 00768 ; ----___ 00769 ; --_____ 00770 ; 00771 ; This reads all Port A inputs and looks for Press 0115 0824 00772 movfw IPnew 0116 00A3 00773 movwf IPlast 0117 0805 00774 movfw PORT_BUTTONS 0118 00A4 00775 movwf IPnew 00776 00777 ; IP last contains new setting, IPlast contains previous 00778 00779 ; ----___ 00780 ; --_____ 00781 ; 00782 00783 ; trigger event on down and up 0119 0824 00784 movfw IPnew ; ----______ 011A 0623 00785 XORWF IPlast,W ; -----_____ 00786 ; ____-_____ 00787 ; now force IPbuttonEvent bits to high for new pressed button 00788 ; the service routine should clear the bit to clear the event. MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 20 LOC OBJECT CODE LINE SOURCE TEXT VALUE 011B 04A6 00789 iorwf IPbuttonEventt,F 00790 ; return 00791 00792 ; trigger event on press 00793 ; On press PA2 goes high 011C 0923 00794 comf IPlast,W ; -----_____ 011D 0524 00795 andwf IPnew,W ; ____------ 00796 ; ____-_____ 00797 ; now force IPbuttonEvent bits to high for new pressed button 00798 ; the service routine should clear the bit to clear the event. 011E 04A5 00799 iorwf IPbuttonEvent,F 011F 0008 00800 return 00801 00802 ;-------------------------------------------------------------------------- 00803 ; Sec 4.3 Clock Chain Routine 00804 ;-------------------------------------------------------------------------- 00805 0120 00806 CLtimeslice 00807 ; CLOCK TIME SLICE - run Timer chain 00808 ; Assuming: 00809 ; tmr0 is clocked by Osc. 00810 0120 1D0B 00811 btfss INTCON,T0IF 0121 0008 00812 return 00813 00814 ;slow down the button press code 0122 2115 00815 call IPtimeslice 00816 00817 ; TMR0 timeout 0123 110B 00818 bcf INTCON,T0IF 0124 1420 00819 bsf DoTimeSlice,DTsS4event 00820 00821 ; This ticks 1 per second, 00822 ; 0125 0BA1 00823 decfsz CLtmr4sec,f 0126 0008 00824 return 00825 00826 ; divide by 4 0127 3010 00827 movlw 10 0128 00A1 00828 movwf CLtmr4sec 0129 292A 00829 goto CLbcdS 00830 00831 ;-------------------------------------------------------------------------- 00832 ; Sec 4.4 BDC Clock Chain Routine 00833 ;-------------------------------------------------------------------------- 00834 00835 ; BCD Counter - Seconds 012A 00836 CLbcdS 012A 14A0 00837 bsf DoTimeSlice,DTsSevent 00838 00839 00840 012B 0008 00841 return MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 21 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00842 00843 00844 ;-------------------------------------------------------------------------- 00845 ; Sec 4.5 Event Handler Routines - Timer 00846 ;-------------------------------------------------------------------------- 00847 012C 00848 SS4tick ; do this 4 times a second 012C 1020 00849 bcf DoTimeSlice,DTsS4event 00850 00851 ; look for edge 012D 084A 00852 movfw PPphase 012E 00C9 00853 movwf PPphaseLast 00854 00855 ; look for edge 012F 084D 00856 movfw PPphaseH 0130 00CC 00857 movwf PPphaseLastH 00858 00859 0131 0ACA 00860 incf PPphase,f 0132 1903 00861 skpnz 0133 0ACD 00862 incf PPphaseH,f 00863 00864 ; trigger event on press 00865 ; On press PA2 goes high 0134 0949 00866 comf PPphaseLast,W ; -----_____ 0135 054A 00867 andwf PPphase,W ; ____------ 00868 ; ____-_____ 00869 00870 ; now force IPbuttonEvent bits to high for new pressed button 00871 ; the service routine should clear the bit to clear the event. 0136 04CB 00872 iorwf PPphaseEvent,F 00873 0137 094C 00874 comf PPphaseLastH,W ; -----_____ 0138 054D 00875 andwf PPphaseH,W ; ____------ 00876 ; ____-_____ 0139 04CE 00877 iorwf PPphaseEventH,F 00878 00879 00880 00881 013A 1ECE 00882 btfss PPphaseEventH,5 013B 294A 00883 goto SS4tick00 00884 00885 013C 12CE 00886 bcf PPphaseEventH,5 00887 00888 ; change speed if 013D 1CC4 00889 btfss LDwant7,1 013E 294A 00890 goto SS4tick00 00891 00892 013F 1003 00893 bcf STATUS,C 0140 0CC8 00894 rrf PPspeed,f MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 22 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00895 00896 ; if zero set it to 1 0141 08C8 00897 movf PPspeed,f 0142 1903 00898 skpnz 0143 1748 00899 bsf PPspeed,6 00900 00901 00902 00903 00904 ; cycle through 00905 ; fast 00906 ; medium 00907 ; slow 00908 ; freq 00909 00910 ; 00911 00912 00913 ; test bit in 00914 0144 00915 SS4tick000 00916 ; 00917 ; test if timer for inc has timed out 00918 ; 0144 1F4E 00919 btfss PPphaseEventH,6 0145 294A 00920 goto SS4tick00 0146 134E 00921 bcf PPphaseEventH,6 00922 0147 1844 00923 btfsc LDwant7,0 0148 2100 00924 call LDloadShareIncWants 0149 210B 00925 call LDloadShareMaskCounts 00926 00927 00928 014A 00929 SS4tick00 00930 014A 0848 00931 movfw PPspeed 00932 ; bit map: 1 selects freq display, 0 selects ePIP display 014B 3915 00933 andlw 0x15 00934 014C 1903 00935 skpnz 014D 295A 00936 goto SS4tickLoadShare 00937 00938 00939 ; has there been a PPphaseEvent 00940 ; movlw 1 << 0 00941 014E 0848 00942 movfw PPspeed 014F 054B 00943 andwf PPphaseEvent,w 0150 1903 2970 00944 bz SS4tick1 00945 00946 ; reset events 00947 ; movlw ~( 1 << 0 ) MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 23 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0152 0948 00948 comf PPspeed,w 0153 05CB 00949 andwf PPphaseEvent,f 00950 0154 20A9 00951 call LDdoFreq 00952 00953 ; look up the Oscillator and display on Left 00954 ; look up the Oscillator carry events and display on Right 00955 00956 ; store in display buffer for display 0155 0831 00957 movfw LDbucketCarryOsc 0156 00CF 00958 movwf PPdispLeft 00959 0157 0830 00960 movfw LDbucketCarry 0158 00D0 00961 movwf PPdispRight 00962 ; goto SS4tick1 00963 00964 0159 2970 00965 goto SS4tick1 00966 00967 015A 00968 SS4tickLoadShare 00969 00970 ; has timer event 015A 0848 00971 movfw PPspeed 015B 054B 00972 andwf PPphaseEvent,w 015C 1903 2961 00973 bz SS4tick0 00974 00975 ; reset events 015E 0948 00976 comf PPspeed,w 015F 05CB 00977 andwf PPphaseEvent,f 00978 0160 204A 00979 call LDdoloadShare 00980 00981 ; ; test bit in 00982 ; btfsc LDwant7,0 00983 ; call LDloadShareIncWants 00984 ; call LDloadShareMaskCounts 00985 00986 ; Multiplex display buffers onto LEDS now 00987 00988 00989 0161 00990 SS4tick0 00991 00992 ; look up count for PPindex 00993 ; PPindex 00994 0161 0846 00995 movfw PPindex 0162 1C51 00996 btfss PPmode,0 0163 0832 00997 movfw LDmaxPtr 00998 00999 ; 01000 ; display segment on left and num on right. MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 24 LOC OBJECT CODE LINE SOURCE TEXT VALUE 01001 ; 0164 2005 01002 call LDlookupBit 0165 00CF 01003 movwf PPdispLeft 01004 01005 01006 01007 ; W = want[ PPindex ] 0166 0846 01008 movfw PPindex 0167 1C51 01009 btfss PPmode,0 0168 0832 01010 movfw LDmaxPtr 01011 01012 ; add offet into files 0169 3E3D 01013 addlw LDwant0 01014 016A 1383 01015 bankisel LDwant0 016B 0084 01016 movwf FSR 016C 0800 01017 movfw INDF 01018 016D 2013 01019 call LDlookupNum 01020 016E 00D0 01021 movwf PPdispRight 016F 2970 01022 goto SS4tick1 01023 01024 01025 01026 01027 01028 0170 01029 SS4tick1 01030 ; multiplex left and right displays on alternate phases 01031 01032 ; 01033 ; turn off display 01034 ; 0170 1005 01035 bcf PORTA,0 0171 1085 01036 bcf PORTA,1 01037 01038 ;PPhase is incremented, so bit 1 selects which display is to be powered 0172 1CCA 01039 btfss PPphase,1 0173 2979 01040 goto SS4tick2 01041 01042 ; 01043 ; drive left hand display 01044 ; 0174 084F 01045 movfw PPdispLeft 0175 0086 01046 movwf PORTB 01047 0176 1405 01048 bsf PORTA,0 0177 1085 01049 bcf PORTA,1 0178 0008 01050 return 01051 0179 01052 SS4tick2 01053 ; MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 25 LOC OBJECT CODE LINE SOURCE TEXT VALUE 01054 ; drive right hand display 01055 ; 0179 0850 01056 movfw PPdispRight 017A 0086 01057 movwf PORTB 01058 017B 1005 01059 bcf PORTA,0 017C 1485 01060 bsf PORTA,1 017D 0008 01061 return 01062 01063 017E 01064 SStick 017E 10A0 01065 bcf DoTimeSlice,DTsSevent 017F 21BF 01066 call IPts 0180 0008 01067 return 01068 01069 0181 01070 SMtick 0181 10A0 01071 bcf DoTimeSlice,DTsSevent 0182 0008 01072 return 01073 01074 ;-------------------------------------------------------------------------- 01075 ; Sec 4.6 Event Handler Routine - Buttons 01076 ;-------------------------------------------------------------------------- 01077 ; come here and combine the current state and the current event to index into 01078 ; the state jump table. 01079 ; 01080 0183 01081 IPoneChanged 0183 1126 01082 bcf IPbuttonEventt,BUTTON_ONE 01083 01084 ; test for up/down 0184 1D24 01085 btfss IPnew,BUTTON_ONE 0185 298E 01086 goto IPoneReleased 01087 01088 ; 01089 ; During press - count timeouts 01090 ; On release start a timer to end incrementing the same digit. 01091 ; On next press, if timer is stopped move onto next digit. 01092 ; On next press, if timer is running increment current digit 01093 ; long presses stop the timer. 01094 01095 ; reset pressed counter on count 01096 ; ______----_______ count ticks while pressed and action on release 01097 ; 01098 01099 ; if count = 1 then ZERO 01100 ; if count = 0 then increment count and wait long release 01101 ; if pressed while timer running, then increment current digit 01102 ; 01103 0186 01104 IPonePressed 01105 01106 ; reset counter incremented during pressed. MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 26 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0186 01AB 01107 clrf IPonePressedCnt 01108 01109 01110 ; First test if timer is still running to indicate if the same digit is to be imcremente d. 01111 ; test if the timer has stopped. 0187 08A8 01112 MOVF IPoneTimer,f 0188 1903 01113 SKPNZ 0189 298C 01114 goto IPpressAfterLongPause 01115 01116 ; start of press 018A 21BA 01117 call IPstartTimer 01118 018B 0008 01119 return 01120 01121 018C 01122 IPpressAfterLongPause 01123 ; move onto the next digit 01124 ; NOTE: no range test 018C 21BA 01125 call IPstartTimer 018D 0008 01126 return 01127 01128 018E 01129 IPoneReleased 01130 ; The button has been released 01131 ; If a very long press, then reset the state machine 01132 ; If a long press then digit is zero 01133 ; If a short press then increment a digit 01134 ; 01135 ; test if the timer has stopped. 01136 ; If so the button was pressed for a very long time 018E 082B 01137 MOVF IPonePressedCnt,W 018F 1903 2995 01138 BZ IPReleasedAfterShortPress ; count = 0 0191 3EFF 01139 ADDLW -1 0192 1903 29A7 01140 BZ IPReleasedAfterLongPress ; count = 1 0194 29B1 01141 goto IPReleasedAfterVeryLongPress ; count = 2 or more 01142 0195 01143 IPReleasedAfterShortPress 01144 0195 1CC7 01145 btfss PPsettingMode,1 0196 29A1 01146 goto IPReleasedAfterShortPress1 01147 ; Incrementing counter 01148 ; Short press, do nothing until long release 01149 ; If timer still running the 01150 01151 ; inc 01152 0197 303D 01153 movlw LDwant0 0198 0746 01154 addwf PPindex,w 01155 0199 1383 01156 bankisel LDwant0 019A 0084 01157 movwf FSR 019B 0A80 01158 incf INDF,f MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 27 LOC OBJECT CODE LINE SOURCE TEXT VALUE 01159 019C 300F 01160 movlw 0x0F 019D 0580 01161 andwf INDF,f 01162 019E 1451 01163 bsf PPmode,0 01164 019F 21BA 01165 call IPstartTimer 01166 01A0 0008 01167 return 01168 01A1 01169 IPReleasedAfterShortPress1 01170 01A1 1003 01171 bcf STATUS,C 01A2 0CC8 01172 rrf PPspeed,f 01173 01174 ; if zero set it to 1 01A3 08C8 01175 movf PPspeed,f 01A4 1903 01176 skpnz 01A5 16C8 01177 bsf PPspeed,5 01178 01A6 0008 01179 return 01180 01181 01182 01A7 01183 IPReleasedAfterLongPress 01184 ; This indicates a long press, zero the current digit and increment pointer 01185 ; Clear the current digit. 01186 01A7 1383 01187 bankisel LDwant0 01188 01A8 1451 01189 bsf PPmode,0 01190 01A9 0AC6 01191 incf PPindex,f 01AA 3007 01192 movlw 0x07 01AB 05C6 01193 andwf PPindex,f 01194 01195 ; not sure why 01AC 01C7 01196 clrf PPsettingMode 01AD 14C7 01197 bsf PPsettingMode,1 01AE 20E3 01198 call LDclearBuckets 01199 01200 01201 ; Stop the timers to simulate a long pause to move onto the next digit. 01AF 01A8 01202 clrf IPoneTimer 01B0 0008 01203 return 01204 01205 01B1 01206 IPReleasedAfterVeryLongPress 01B1 3007 01207 movlw 7 01B2 00C6 01208 movwf PPindex 01209 01B3 01D1 01210 clrf PPmode 01B4 01C7 01211 clrf PPsettingMode MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 28 LOC OBJECT CODE LINE SOURCE TEXT VALUE 01B5 01C8 01212 clrf PPspeed 01B6 3008 01213 movlw 1 << 3 01B7 00C8 01214 movwf PPspeed 01B8 20E3 01215 call LDclearBuckets 01B9 0008 01216 return 01217 01218 01BA 01219 IPstartTimer 01220 ; clrf IPoneTimer ; clear the timer 01BA 3004 01221 movlw 4 01BB 00A8 01222 movwf IPoneTimer ; this timer uses a shitf reg 01223 01BC 3020 01224 movlw 20 01BD 00A9 01225 movwf IPoneInactivityTimer ; this timer uses a shitf reg 01BE 0008 01226 return 01227 01BF 01228 IPts 01229 ; 01230 ; Time Slice 01231 ; 01232 01233 ;is IPoneInactivityTimer timer is running, if so decrement it 01234 ; 01235 01BF 08A9 01236 MOVF IPoneInactivityTimer,f 01C0 1D03 01237 SKPZ Message[305]: Using default destination of 1 (file). 01C1 0BA9 01238 decfsz IPoneInactivityTimer 01C2 29C4 01239 goto IPtsActivity 01C3 0008 01240 return 01241 01242 01C4 01243 IPtsActivity 01244 ;test if timer is running, if so decrement it 01245 ; 01C4 08A8 01246 MOVF IPoneTimer,f 01C5 1903 01247 SKPNZ 01C6 0008 01248 return 01C7 0BA8 01249 decfsz IPoneTimer,f 01C8 0008 01250 return 01251 01252 ; Timeout 01253 ; Test if button pressed, if so increment Pressed Counter 01C9 1D23 01254 btfss IPlast,BUTTON_ONE 01CA 0008 01255 return 01256 01CB 01257 IPtsWhilePressed 01CB 0AAB 01258 incf IPonePressedCnt,f 01259 ; restart timer. Already blinked 01CC 21BA 01260 call IPstartTimer 01261 01CD 21CF 01262 call PPblink 01263 MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 29 LOC OBJECT CODE LINE SOURCE TEXT VALUE 01CE 0008 01264 return 01265 01266 01267 01268 ;-------------------------------------------------------------------------- 01269 ; Sec 4.7 Flash Display as Key Click 01270 ;-------------------------------------------------------------------------- 01271 01272 01CF 01273 PPblink 01CF 30FF 01274 movlw 0xFF 01D0 0086 01275 movwf PORTB 01D1 1405 01276 bsf PORTA,0 01D2 1085 01277 bcf PORTA,1 01D3 0008 01278 return 01279 01280 ;-------------------------------------------------------------------------- 01281 ; Sec 5. Initilization code - 01282 ;-------------------------------------------------------------------------- 01283 01284 01D4 01285 INinit 01286 01287 ; Enable Interupts 01D4 3000 01288 movlw H'00' 01D5 008B 01289 movwf INTCON 01290 01D6 0185 01291 clrf PORTA ;Initialize PORTA by setting 01292 ;output data latches 01293 ; you have to do this for the 16F628 01D7 1283 1303 01294 BANKSEL CMCON 01D9 3007 01295 movlw 0X07 ;Turn comparators off and 01DA 009F 01296 movwf CMCON ;enable pins for I/O 01297 01DB 1683 1303 01298 banksel TRISB 01DD 3080 01299 movlw 0X80 Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct. 01DE 0086 01300 movwf TRISB 01DF 30FC 01301 movlw 0xFC ; Make A0 and A1 outputs to drive LED display Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct. 01E0 0085 01302 movwf TRISA 01303 01304 ; Change Prescaler 01E1 0064 01305 CLRWDT 01306 01307 ; Set up prescaller for 8192 / 16 = 512 ticks perseconds. 01308 01309 ; movlw 0x0 + 7 ; For Tmr0 0=/2, 1=/4, 2=/8,3=/16 01E2 3004 01310 movlw 0x0 + 4 ; For Tmr0 0=/2, 1=/4, 2=/8,3=/16 Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct. 01E3 0081 01311 movwf OPTION_REG 01E4 1283 1303 01312 banksel STATUS 01E6 1283 01313 bcf STATUS,RP0 MPASM 5.30.01 PP001.ASM 7-17-2009 8:33:26 PAGE 30 LOC OBJECT CODE LINE SOURCE TEXT VALUE 01314 01315 ; Configure Tmr 1 01E7 3031 01316 movlw 0x0 | 1<