-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.asm
1089 lines (870 loc) · 41 KB
/
functions.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
fAlwaysOff ;{
; keeps an output pin always off
; in: funcOutBits
; out: outputLo | outputHi
; mod: bitmaskLo
; mod: bitmaskHi
movfw funcOutBits ; get output bit
pcall genBitmask ; generate bitmask for output
outputOff ; switch output off
goto dispatchCont ;}
fAlwaysOn ;{
; keeps an output pin always off
; in: funcOutBits
; out: outputLo | outputHi
; mod: bitmaskLo
; mod: bitmaskHi
movfw funcOutBits ; get output bit
pcall genBitmask ; generate bitmask for output
outputOn ; switch output on
goto dispatchCont ;}
fPassThrough ;{
; a single output pin follows the state of the corresponding input
; in: rxInput
; in: funcOutBits
; out: outputLo | outputHi
; mod: bitmaskLo
; mod: bitmaskHi
btfsc rxInput,4 ; check for pressed key (positive edge)
goto fPassThrough1
btfss rxInput,5 ; check for released key (negative edge)
goto dispatchCont
movfw funcOutBits ; get output bit
pcall genBitmask ; generate bitmask for output
outputOff
goto dispatchCont
fPassThrough1 movfw funcOutBits ; get output bit
pcall genBitmask ; generate bitmask for output
outputOn
goto dispatchCont ;}
fToggle ;{
; toggles a single output pin when the corresponding key is pressed
; in: rxInput
; in: funcOutBits
; out: outputLo | outputHi
; mod: bitmaskLo
; mod: bitmaskHi
bankisel functionRam
btfss funcUber,4 ; need to check the output bit?
goto fToggleS1 ; no
movfw funcUber
xorwf funcOutBits,w
andlw 0x0f
bnz dispatchCont ; not the output bit we searched for
btfsc funcUber,7 ; test for on/off mode
goto fToggleS3 ; lights on
goto fToggleS5 ; lights off
fToggleS1 btfsc funcSemaphore,0 ; check for lights on
goto fToggleS3 ; light on
btfsc funcSemaphore,1 ; check for lights off
goto fToggleS5 ; light off
fToggleS2 btfss rxInput,4 ; check for pressed key (positive edge)
goto fToggleS4 ; continue if no positive edge
incf paramPtr2,w
pcall clrDelay ; clear delay timer
movfw funcOutBits ; check for output status
pcall genBitmask
pcall checkOutput
bnz fToggleS5 ; output is currently on => turn output off
movfw funcPrescMode
andlw 0xf0
bz fToggleS3 ; no timer mode
incf paramPtr2,w
pcall genDelay ; set delay after which we turn of the output
fToggleS3 movfw funcOutBits
pcall genBitmask
outputOn ; switch output on
goto dispatchCont
fToggleS4 incf paramPtr2,w
pcall compareTime ; on-time already elapsed
bc dispatchCont ; no
incf paramPtr2,w
pcall chkDelay
bz dispatchCont ; continue if delay timer alreay cleared
movfw paramPtr2
movwf FSR
btfsc INDF,7 ; test twoStage status if key is still pressed
goto dispatchCont ; there is also a twoStageToggle running
fToggleS5 incf paramPtr2,w
pcall clrDelay ; clear delay timer
movfw funcOutBits
pcall genBitmask
outputOff ; switch output off
goto dispatchCont ;}
fToggleDual ;{
; toggles two output pins when the corresponding key is pressed (output 1 is master)
; in: rxInput
; in: funcOutBits (lower and upper nibble)
; out: outputLo &/| outputHi
; mod: bitmaskLo
; mod: bitmaskHi
bankisel functionRam
btfss funcUber,4 ; need to check the output bit?
goto fToggleDual0 ; no
movfw funcOutBits
xorwf funcUber,w
andlw 0x0f
bz fToggleDualA ; one of our output bits we searched for
swapf funcOutBits,w
xorwf funcUber,w
andlw 0x0f
bnz dispatchCont ; not the output bit we searched for
fToggleDualA btfsc funcUber,7 ; test for on/off mode
goto fToggleDual3 ; lights on
goto fToggleDual1 ; lights off
fToggleDual0 btfsc funcSemaphore,0 ; check for lights on
goto fToggleDual3
btfsc funcSemaphore,1 ; check for lights off
goto fToggleDual1
btfss rxInput,4 ; check for pressed key (positive edge)
goto fToggleDual4
incf paramPtr2,w
pcall clrDelay ; clear delay timer
incf paramPtr3,w
pcall clrDelay ; clear delay timer
swapf funcOutBits,w
pcall genBitmask ; generate bitmask for output2
pcall checkOutput
bz fToggleDual2 ; output2 clear
movfw funcOutBits
pcall genBitmask ; generate bitmask for output1
pcall checkOutput
bz fToggleDual2 ; output1 clear
fToggleDual1 movfw funcOutBits
pcall genBitmask ; generate bitmask for output1
outputOff
swapf funcOutBits,w
pcall genBitmask ; generate bitmask for output2
outputOff
goto dispatchCont
fToggleDual2 movfw funcPrescMode
andlw 0xf0
bz fToggleDual3
incf paramPtr2,w
pcall genDelay
incf paramPtr3,w
pcall genDelay
fToggleDual3 movfw funcOutBits
pcall genBitmask ; generate bitmask for output1
outputOn
swapf funcOutBits,w
pcall genBitmask ; generate bitmask for output2
outputOn
goto dispatchCont
fToggleDual4 incf paramPtr2,w
pcall compareTime ; time already elapsed
bc fToggleDual5 ; no
incf paramPtr2,w
pcall chkDelay
bz fToggleDual5 ; continue if delay timer alreay cleared
incf paramPtr2,w
pcall clrDelay ; clear delay timer
movfw funcOutBits
pcall genBitmask
outputOff ; switch output off
fToggleDual5 incf paramPtr3,w
pcall compareTime ; time already elapsed
bc dispatchCont ; no
incf paramPtr3,w
pcall chkDelay
bz dispatchCont ; continue if delay timer alreay cleared
incf paramPtr3,w
pcall clrDelay ; clear delay timer
swapf funcOutBits,w
pcall genBitmask
outputOff ; switch output off
goto dispatchCont ;}
fTwoStage ;{
; toggles first output on short keypress, when the first output toggles on and the
; key is held for a longer time the second output turns on
; in: rxInput
; in: funcOutBits (lower and upper nibble)
; out: outputLo &/| outputHi
; mod: bitmaskLo
; mod: bitmaskHi
bankisel functionRam
btfss funcUber,4 ; need to check the output bit?
goto fTwoStage2 ; no
movfw funcOutBits
xorwf funcUber,w
andlw 0x0f
bz fTwoStage1 ; one of our output bits we searched for
swapf funcOutBits,w
xorwf funcUber,w
andlw 0x0f
bnz dispatchCont ; not the output bit we searched for
fTwoStage1 btfsc funcUber,7 ; test for on/off mode
goto fTwoStage6 ; lights on
goto fTwoStage7 ; lights off
fTwoStage2 btfsc funcSemaphore,0 ; check for lights on
goto fTwoStage6
btfsc funcSemaphore,1 ; check for lights off
goto fTwoStage7
btfsc rxInput,4 ; check for pressed key (positive edge)
goto fTwoStage3
btfss rxInput,5 ; check for released key (negative edge)
goto fTwoStage5
movfw paramPtr2
movwf FSR
bcf INDF,7 ; clear flag 'positive edge received' on twoStage status
incf paramPtr2,w
pcall clrDelay ; clear delay timer
goto dispatchCont
fTwoStage3 movfw funcOutBits
pcall genBitmask ; generate bitmask for output
pcall checkOutput ; check if output already set
bnz fTwoStage4
outputOn ; switch output 1 on (gang 1)
movfw paramPtr2
movwf FSR
bsf INDF,7 ; set flag 'positive edge received' on twoStage status
movlw 0x01 ; we use only the prescaler for this delay
movwf funcDelay
incf paramPtr2,w
pcall genDelay
goto dispatchCont
fTwoStage4 outputOff ; switch output 1 off
swapf funcOutBits,w
pcall genBitmask
outputOff ; switch output 2 off
goto dispatchCont
fTwoStage5 movfw paramPtr2
movwf FSR
btfss INDF,7 ; test twoStage status if key is still pressed
goto dispatchCont
incf paramPtr2,w
pcall compareTime
bc dispatchCont
movfw paramPtr2
movwf FSR
bcf INDF,7 ; clear flag 'positive edge received' on twoStage status
incf paramPtr2,w
pcall clrDelay ; clear delay timer
movfw funcOutBits ; check if output 1 is already set
pcall genBitmask
pcall checkOutput
bz dispatchCont ; no
swapf funcOutBits,w
pcall genBitmask
outputOn ; switch output 2 on (gang 2)
goto dispatchCont
fTwoStage6 movfw funcOutBits
pcall genBitmask ; generate bitmask for output
outputOn ; switch output 1 on
swapf funcOutBits,w
pcall genBitmask
outputOn ; switch output 2 on
incf paramPtr2,w
pcall clrDelay ; clear delay timer
goto dispatchCont
fTwoStage7 movfw funcOutBits
pcall genBitmask ; generate bitmask for output
outputOff ; switch output 1 off
swapf funcOutBits,w
pcall genBitmask
outputOff ; switch output 2 off
incf paramPtr2,w
pcall clrDelay ; clear delay timer
goto dispatchCont ;}
fTimerR ;{
; retriggerable timer
; ouptut is turned on until delay time has elapsed
; in: rxDevID
; in: rxInput
; in: funcOutBits lower nibble
; out: outputLo &/| outputHi
; mod: bitmaskLo
; mod: bitmaskHi
bankisel functionRam
btfss funcUber,4 ; need to check the output bit?
goto fTimerRa ; no
movfw funcUber
xorwf funcOutBits,w
andlw 0x0f
bnz dispatchCont ; not the output bit we searched for
btfsc funcUber,7 ; test for on/off mode
goto fTimerR1 ; lights on
goto fTimerR0 ; lights off
fTimerRa btfsc funcSemaphore,0 ; check for lights on
goto fTimerR1
btfsc funcSemaphore,1 ; check for lights off
goto fTimerR0
btfsc rxInput,4 ; check for pressed key (positive edge)
goto fTimerR1
incf paramPtr2,w
pcall compareTime ; time already elapsed
bc dispatchCont ; no
incf paramPtr2,w
pcall chkDelay
bz dispatchCont ; continue if delay timer alreay cleared
fTimerR0 movfw funcOutBits
pcall genBitmask
outputOff ; switch output off
incf paramPtr2,w
pcall clrDelay ; clear delay timer
goto dispatchCont
fTimerR1 incf paramPtr2,w
pcall genDelay
movfw funcOutBits
pcall genBitmask
outputOn ; switch output on
goto dispatchCont ;}
fBlinker ;{
; blinker / inverted blinker
; toggles output with configurable frequency and duty cycle
; in: rxDevID
; in: rxInput
; in: funcOutBits lower nibble
; in: funcTypeInput bit 4 (inverted mode)
; out: outputLo &/| outputHi
; mod: bitmaskLo
; mod: bitmaskHi
; 6.0ms cycle
; 0.5ms low
; 5.5ms high
bankisel functionRam
movfw paramPtr2
movwf FSR
btfss rxInput,4 ; check for pressed key (positive edge)
goto fBlinker1
bsf INDF,0
goto fBlinker3
fBlinker1: btfss rxInput,5 ; check for released key (negative edge)
goto fBlinker2
clrf INDF
incf paramPtr2,w
pcall clrDelay ; clear delay timer
btfsc funcTypeInput,4 ; test for inverted mode
goto fBlinkerOn
fBlinkerOff: movfw funcOutBits
pcall genBitmask
outputOff ; switch output off
goto dispatchCont
fBlinkerOn: movfw funcOutBits
pcall genBitmask
outputOn ; switch output on
goto dispatchCont
fBlinker2: btfss INDF,0
goto dispatchCont
incf paramPtr2,w
pcall compareTime ; time already elapsed
bc dispatchCont ; no
movfw paramPtr2
movwf FSR
btfsc INDF,1
goto fBlinker4
fBlinker3: bsf INDF,1
incf paramPtr2,w
pcall genDelayF ; set up delay T1
goto fBlinkerOn
fBlinker4: bcf INDF,1
movlw devID2 ; we use funcDevID2 as T2 low phase
addwf paramPtr1,w
longcall eeRead
banksel funcDelay
movwf funcDelay
incf paramPtr2,w
pcall genDelayF ; set up delay T2
goto fBlinkerOff
fAwning ;{
; +-----+ T3 T3 +-----+
; | |------+ +------| |
; +---->| S01 | O+ | | C+ | S11 |<----+
; | |full |----->| |<-----|full | |
; | |close| C+ | | O+ |open | |
; | | |----->| |<-----| | |
; | +-----+ | | +-----+ |
; | v v |
; | +----------+ |
; | | S02 | |
; | |protection| |
; | | interval | |
; | +----------+ |
; | | |
; | | T4 |
; | v |
; | +------+ |
; | C+ | S00 | O+ |
; +----------------| stop |----------------+
; | |
; +------+
bankisel functionRam
btfss funcUber,4 ; need to check the output bit?
goto fAwningA ; no
movfw funcOutBits
xorwf funcUber,w
andlw 0x0f
bz fAwningB ; one of our output bits we searched for
swapf funcOutBits,w
xorwf funcUber,w
andlw 0x0f
bnz dispatchCont ; not the output bit we searched for
fAwningB btfsc funcUber,7 ; test for open/close mode
goto fAwningO ; open awning
goto fAwningC ; close awning
fAwningA btfsc funcSemaphore,6 ; check for awning closing
goto fAwningC
btfsc funcSemaphore,7 ; check for awning opening
goto fAwningO
movfw paramPtr2
movwf FSR
tstf INDF ; test for state 00
bz fAwningS00
movlw 0x01
xorwf INDF,w ; test for state 01
bz fAwningS01
movlw 0x02
xorwf INDF,w ; test for state 02
bz fAwningS02
goto fAwningStop ; nothing matched; set state 00
fAwningS00 btfss rxInput,4 ; check for pressed key (positive edge)
goto dispatchCont
movlw 0x01 ; next state S01
movwf INDF
swapf funcOutBits,w ; generate bitmask for close/open (upper nibble)
pcall genBitmask
btfsc funcUber,5 ; test if second input key (close) matched
goto fAwningS00a ; no, we are opening
outputOff ; switch close/open off (close)
goto fAwningS00b
fAwningS00a outputOn ; switch close/open on (open)
fAwningS00b movfw funcOutBits
pcall genBitmask ; generate bitmask for power (lower nibble)
outputOn ; switch power on
incf paramPtr2,w
pcall genDelay ; set up delay T3
goto dispatchCont
fAwningS01 btfsc rxInput,4 ; check for pressed key (positive edge)
goto fAwningStop
incf paramPtr2,w
pcall compareTime ; check if delay T3 has elapsed
bc dispatchCont ; not yet
fAwningStop movfw paramPtr2
movwf FSR
movlw 0x02 ; next state S02 (protection interval)
movwf INDF
movfw funcOutBits
pcall genBitmask ; generate bitmask for power (lower nibble)
outputOff ; switch power off
swapf funcOutBits,w ; generate bitmask for close/open (upper nibble)
pcall genBitmask
outputOff ; switch close/open off (close)
movfw funcPrescMode ; set up prescaler
andlw 0x0f
iorlw 0x10
movwf funcPrescMode
movlw 0x05 ; set up delay
movwf funcDelay
incf paramPtr2,w
pcall genDelay ; set up delay T4
goto dispatchCont
fAwningS02 btfsc rxInput,4 ; check for pressed key (positive edge)
goto fAwningStop
btfsc rxInput,5 ; check for released key (negative edge)
goto fAwningStop
incf paramPtr2,w
pcall compareTime ; check if delay T4 has elapsed
bc dispatchCont ; not yet
movfw paramPtr2
movwf FSR
clrf INDF ; next state is S00 (idle)
goto dispatchCont
fAwningC swapf funcOutBits,w ; generate bitmask for close/open (upper nibble)
pcall genBitmask
outputOff ; switch close/open off (close)
goto fAwningS00b
fAwningO swapf funcOutBits,w ; generate bitmask for close/open (upper nibble)
pcall genBitmask
outputOn ; switch close/open on (open)
goto fAwningS00b ;}
fBlind ;{
; +-----+ U- D- +-----+
; | S01 |------+ +------| S11 |
; +---->|short| D+ | | U+ |short|<----+
; | | up |----->| |<-----|down | |
; | +-----+ | | +-----+ |
; | | | | | |
; | | T1 | | T1 | |
; | v | | v |
; | +-----+ U- | | D- +-----+ |
; | | S02 |----->| |<-----| S12 | |
; | |short| D+ | | U+ |short| |
; | |stop |----->| |<-----|stop | |
; | +-----+ | | +-----+ |
; | | | | | |
; | | T2 | | T2 | |
; | v | | v |
; | +-----+ T3 | | T3 +-----+ |
; | | S03 |----->| |<-----| S13 | |
; | |full | D+ | | U+ |full | |
; | | up |----->| |<-----|down | |
; | +-----+ | | +-----+ |
; | v v |
; | +----------+ |
; | | S04 | |
; | |protection| |
; | | interval | |
; | +----------+ |
; | | |
; | | T4 |
; | v |
; | +------+ |
; | U+ | S00 | D+ |
; +----------------| stop |----------------+
; | |
; +------+
bankisel functionRam
btfss funcUber,4 ; need to check the output bit?
goto fBlindA ; no
movfw funcOutBits
xorwf funcUber,w
andlw 0x0f
bz fBlindB ; one of our output bits we searched for
swapf funcOutBits,w
xorwf funcUber,w
andlw 0x0f
bnz dispatchCont ; not the output bit we searched for
fBlindB btfsc funcUber,7 ; test for down/up mode
goto fBlindD ; blinds down
goto fBlindU ; blinds up
fBlindA btfsc funcSemaphore,2 ; check for blinds up
goto fBlindU
btfsc funcSemaphore,3 ; check for blinds down
goto fBlindD
movfw paramPtr2
movwf FSR
tstf INDF ; test for state 00
bz fBlindS00
movlw 0x01
xorwf INDF,w ; test for state 01
bz fBlindS01
movlw 0x02
xorwf INDF,w ; test for state 02
bz fBlindS02
movlw 0x03
xorwf INDF,w ; test for state 03
bz fBlindS03
movlw 0x04
xorwf INDF,w ; test for state 04
bz fBlindS04
goto fBlindStop ; nothing matched; set state 00
fBlindS00 btfss rxInput,4 ; check for pressed key (positive edge)
goto dispatchCont
movlw 0x01 ; next state S01
movwf INDF
swapf funcOutBits,w ; generate bitmask for up/down (upper nibble)
pcall genBitmask
btfsc funcUber,5 ; test if second input key (up) matched
goto fBlindS00a ; no, we move down
outputOff ; switch up/down off (up)
goto fBlindS00b
fBlindS00a outputOn ; switch up/down on (down)
fBlindS00b movfw funcOutBits
pcall genBitmask ; generate bitmask for power (lower nibble)
outputOn ; switch power on
movfw funcPrescMode ; set up prescaler
andlw 0x0f
iorlw 0x70
movwf funcPrescMode
movlw 0x01 ; set up delay
movwf funcDelay
incf paramPtr2,w
pcall genDelay ; set up delay T1
goto dispatchCont
fBlindS01 btfsc rxInput,4 ; check for pressed key (positive edge)
goto fBlindStop
btfsc rxInput,5 ; check for released key (negative edge)
goto fBlindStop
incf paramPtr2,w
pcall compareTime ; check if delay T1 has elapsed
bc dispatchCont ; not yet
fBlindS01a movfw paramPtr2
movwf FSR
movlw 0x02 ; next state S02
movwf INDF
movfw funcOutBits
pcall genBitmask ; generate bitmask for power (lower nibble)
outputOff ; switch power off
movfw funcPrescMode ; set up prescaler
andlw 0x0f
iorlw 0x50
movwf funcPrescMode
movlw 0x01 ; set up delay
movwf funcDelay
incf paramPtr2,w
pcall genDelay ; set up delay T2
goto dispatchCont
fBlindS02 btfsc rxInput,4 ; check for pressed key (positive edge)
goto fBlindStop
btfsc rxInput,5 ; check for released key (negative edge)
goto fBlindStop
incf paramPtr2,w
pcall compareTime ; check if delay T2 has elapsed
bc dispatchCont ; not yet
fBlindS02a movfw paramPtr2
movwf FSR
movlw 0x03 ; next state S03
movwf INDF
movfw funcOutBits
pcall genBitmask ; generate bitmask for power (lower nibble)
outputOn ; switch power on
incf paramPtr2,w
pcall genDelay ; set up delay T3
goto dispatchCont
fBlindS03 btfsc rxInput,4 ; check for pressed key (positive edge)
goto fBlindStop
incf paramPtr2,w
pcall compareTime ; check if delay T3 has elapsed
bc dispatchCont ; not yet
fBlindStop movfw paramPtr2
movwf FSR
movlw 0x04 ; next state S04 (protection interval)
movwf INDF
movfw funcOutBits
pcall genBitmask ; generate bitmask for power (lower nibble)
outputOff ; switch power off
swapf funcOutBits,w ; generate bitmask for up/down (upper nibble)
pcall genBitmask
outputOff ; switch up/down off (up)
movfw funcPrescMode ; set up prescaler
andlw 0x0f
iorlw 0x10
movwf funcPrescMode
movlw 0x05 ; set up delay
movwf funcDelay
incf paramPtr2,w
pcall genDelay ; set up delay T4
goto dispatchCont
fBlindS04 btfsc rxInput,4 ; check for pressed key (positive edge)
goto fBlindStop
btfsc rxInput,5 ; check for released key (negative edge)
goto fBlindStop
incf paramPtr2,w
pcall compareTime ; check if delay T4 has elapsed
bc dispatchCont ; not yet
movfw paramPtr2
movwf FSR
clrf INDF ; next state is S00 (idle)
goto dispatchCont
fBlindU swapf funcOutBits,w ; generate bitmask for up/down (upper nibble)
pcall genBitmask
outputOff ; switch up/down off (up)
goto fBlindS01a
fBlindD swapf funcOutBits,w ; generate bitmask for up/down (upper nibble)
pcall genBitmask
outputOn ; switch up/down on (down)
goto fBlindS01a ;}
fWindow ;{
; +-----+ U- D- +-----+
; | S01 |------+ +------| S11 |
; +---->|short| D+ | | U+ |short|<----+
; | | up |----->| |<-----|down | |
; | +-----+ | | +-----+ |
; | | | | | |
; | | T1 | | T1 | |
; | v | | v |
; | +-----+ U- | | D- +-----+ |
; | | S02 |----->| |<-----| S12 | |
; | |short| D+ | | U+ |short| |
; | |stop |----->| |<-----|stop | |
; | +-----+ | | +-----+ |
; | | | | | |
; | | T2 | | T2 | |
; | v | | v |
; | +-----+ T3 | | T3 +-----+ |
; | | S03 |----->| |<-----| S13 | |
; | |full | D+ | | U+ |full | |
; | | up |----->| |<-----|down | |
; | +-----+ | | +-----+ |
; | v v |
; | +----------+ |
; | | S04 | |
; | |protection| |
; | | interval | |
; | +----------+ |
; | | |
; | | T4 |
; | v |
; | +------+ |
; | U+ | S00 | D+ |
; +----------------| stop |----------------+
; | |
; +------+
bankisel functionRam
btfss funcUber,4 ; need to check the output bit?
goto fWindowA ; no
movfw funcOutBits
xorwf funcUber,w
andlw 0x0f
bz fWindowB ; one of our output bits we searched for
swapf funcOutBits,w
xorwf funcUber,w
andlw 0x0f
bnz dispatchCont ; not the output bit we searched for
fWindowB btfsc funcUber,7 ; test for open/close mode
goto fWindowO ; windows open
goto fWindowC ; windows close
fWindowA btfsc funcSemaphore,4 ; check for window close
goto fWindowC
btfsc funcSemaphore,5 ; check for windows open
goto fWindowO
movfw paramPtr2
movwf FSR
tstf INDF ; test for state 00
bz fWindowS00
movlw 0x01
xorwf INDF,w ; test for state 01
bz fWindowS01
movlw 0x11
xorwf INDF,w ; test for state 11
bz fWindowS11
movlw 0x02
xorwf INDF,w ; test for state 02
bz fWindowS02
movlw 0x12
xorwf INDF,w ; test for state 12
bz fWindowS12
movlw 0x03
xorwf INDF,w ; test for state 03
bz fWindowS03
movlw 0x04
xorwf INDF,w ; test for state 04
bz fWindowS04
goto fWindowStop ; nothing matched; set state 00
fWindowS00 btfss rxInput,4 ; check for pressed key (positive edge)
goto dispatchCont
movlw 0x04 ; we use only the prescaler for this delay
movwf funcDelay
incf paramPtr2,w
pcall genDelay ; set up delay T1
movfw paramPtr2
movwf FSR
btfss funcUber,5 ; test if second input key (close) matched
goto fWindowS00a ; no, we are opening
movfw funcOutBits
pcall genBitmask ; generate bitmask open (lower nibble)
outputOff ; switch open off
swapf funcOutBits,w ; generate bitmask close (upper nibble)
pcall genBitmask
outputOn ; switch close on
movlw 0x01 ; next state S01
movwf INDF
goto dispatchCont
fWindowS00a movfw funcOutBits
pcall genBitmask ; generate bitmask open (lower nibble)
outputOn ; switch open on
swapf funcOutBits,w ; generate bitmask close (upper nibble)
pcall genBitmask
outputOff ; switch close off
movlw 0x11 ; next state S11
movwf INDF
goto dispatchCont
fWindowS01 btfsc rxInput,4 ; check for pressed key (positive edge)
goto fWindowStop
btfsc rxInput,5 ; check for released key (negative edge)
goto fWindowStop
incf paramPtr2,w
pcall compareTime ; check if delay T1 has elapsed
bc dispatchCont ; not yet
fWindowC movfw paramPtr2
movwf FSR
movlw 0x02 ; next state S02
movwf INDF
movfw funcOutBits ; generate bitmask open (lower nibble)
pcall genBitmask
outputOff ; switch open off
swapf funcOutBits,w ; generate bitmask close (upper nibble)
pcall genBitmask
outputOff ; switch close off
movlw 0x01 ; we use only the prescaler for this delay
movwf funcDelay
incf paramPtr2,w
pcall genDelay ; set up delay T2
goto dispatchCont
fWindowS11 btfsc rxInput,4 ; check for pressed key (positive edge)
goto fWindowStop
btfsc rxInput,5 ; check for released key (negative edge)
goto fWindowStop
incf paramPtr2,w
pcall compareTime ; check if delay T1 has elapsed
bc dispatchCont ; not yet
fWindowO movfw paramPtr2
movwf FSR
movlw 0x12 ; next state S12
movwf INDF
movfw funcOutBits ; generate bitmask open (lower nibble)
pcall genBitmask
outputOff ; switch open off
swapf funcOutBits,w ; generate bitmask close (upper nibble)
pcall genBitmask
outputOff ; switch close off