-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClock.asm
More file actions
920 lines (766 loc) · 34.4 KB
/
Copy pathClock.asm
File metadata and controls
920 lines (766 loc) · 34.4 KB
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
;(c) Copyright 2003. Joe DiMeglio. All rights reserved.
;(c) Copyright 2005. Includes PAUSE button.
include p16f84a.inc
list p=16f84a
__config 0x3ff1 ;cp=off, pwrt=on, wdt=off, osc=xt
; RAM Definition
; __MAXRAM H'CF'
; __BADRAM H'07', H'50'-H'7F', H'87'
;Descriptions of the ports
; PORTA bit 0 4bit address to drive 7 seg display encodes
; bit 1
; bit 2
; bit 3
; PORTB bit 0 IRQ - program push button (prg) (input)
; bit 1 seconds push button (set/PAUSE) (input)
; bit 2 na (input)
; bit 3 select T1 or T2 to program (input)
; bit 4 output buzzer (output)
; bit 5-7 used to select which 7 segment to encode (outputs)
; 4.000 000 Mhz gives 500,000 tmr0 cycles per second
; 500,000 decimal = 0x07a120 hex
; for my oscillator = 0x07a0e4 hex (499,940 Hz)
;RAM starts at 0x0c -----------------------------------------
sec1 equ 0x20 ;time variables that are displayed
sec10 equ 0x21
min1 equ 0x22
t0_sec1_save equ 0x23
t0_sec10_save equ 0x24
t0_min1_save equ 0x25
t1_sec1_save equ 0x26
t1_sec10_save equ 0x27
t1_min1_save equ 0x28
tmode equ 0x29 ;if 0 use t0 pre-set variables else use t1 (toogler)
digit equ 0x2A ;which digit are programming
timerselect equ 0x2b ;which timer are we programming
onesec equ 0x2c
buzzertoggole equ 0x2d ;
buzzertimer equ 0x2e
tconst1 equ 0x30 ;trm0 variables
tconst0 equ 0x31
tcount1 equ 0x32
tcount0 equ 0x33
tconsta1 equ 0x34 ;trm0 variables for 0.4
tconsta0 equ 0x35
tcounta1 equ 0x36
tcounta0 equ 0x37
tconstb1 equ 0x38 ;trm0 variables for 0.6
tconstb0 equ 0x39
tcountb1 equ 0x3a
tcountb0 equ 0x3b
e_adr equ 0x3c ;EEPROM data adr
e_check equ 0x3d ;EEPROM end check cnt adr
e_size equ d'06' ;EEPROM data size
;alarmcount equ 0x3f ;count down for alarm time..
temp equ 0x40
LSD equ 0x41
MSD equ 0x42
;-------------------------------
;EEPROM Address (64bytes in total)
ee_sec1_t0 equ 0x00
ee_sec10_t0 equ 0x01
ee_min1_t0 equ 0x02
ee_sec1_t1 equ 0x03
ee_sec10_t1 equ 0x04
ee_min1_t1 equ 0x05
;fraction equ 0x34
org h'2100'
de d'00'
de d'00'
de d'03'
de d'00'
de d'03'
de d'00'
;-------------------------------------------------------------
; goto start
; org 04
;
;Interupts----------------------------------------------------
; bcf INTCN,1 ;Clear Int flag
;
;
;
; RETFIE
;-------------------------------------------------------------
org 0
call INITPORTS
call INITRTCC
call READEEPROM
;movlw 0x03 ;start with 3:00 minute for t0
;movwf t0_min1_save
;clrf t0_sec1_save
;clrf t0_sec10_save
;movlw 0x02
;movwf t1_sec10_save ;start with 0:29 seonds for t1
;clrf t1_min1_save
;movlw 0x09
;movwf t1_sec1_save
clrf onesec ;clear toggle
RESTART clrf tmode ;start with t0 pre-saved
;call LOAD_T0 ;load t0 constants
movf t0_min1_save,0
movwf min1
movf t0_sec10_save,0
movwf sec10
movf t0_sec1_save,0
movwf sec1
clrf tmode ;start with t0
;movlw 0x01
;xorwf tmode,1
;-------MAIN LOOP HERE-----------------------------------
loop clrw ;clear regiser W
btfsc onesec,1 ;see if one has elapsed
goto inc_tick ;yes then dec counter..
call WAIT ;else wait some more and
btfss PORTB,0 ;check to see if prg pressed
goto CHGDIGIT ;yes it was pressed else
btfss PORTB,1 ;check pause button
goto PAUSE ;yes it was pressed else
goto loop ;goto to start
inc_tick bcf onesec,1 ;reset onesec flag to zero.
call PRINTALL ;output to the screen
call TICK ; - adjust time
; movf alarmcount,1
; btfss STATUS,Z
; goto alarmcountrol
goto loop
;alarmcountrol clrw
; decf alarmcount
; movfw alarmcount
; sublw 01
; btfsc STATUS,Z
; call BUZZER_OFF
; goto loop
;--------------------------------------------------------------------------
debounce ; Are any of PORTB's inputs active?
movf PORTB, W ;
andlw 0x3 ; Keep only the 3 switch values
DEB movwf temp ;
movlw 0x10 ; This is the debounce delay
movf MSD, F ;
clrf LSD ;
KB_D_LP1 decfsz LSD, F ;
goto KB_D_LP1 ;
decfsz MSD, F ;
goto KB_D_LP1 ;
END_DELAY movf PORTB, W
andlw 0x03 ; Keep only the 3 switch values
subwf temp, F ;
btfss STATUS, Z ; Is the Zero bit set?
; (switches were the same on 2 reads)
goto DEB ; NO, Try another read
KEY_MATCH
movwf temp ; YES, need to see which is depressed.
return
;--------------------------------------------------------------------------
;this routine will check to see if the timer IRQ has been set.
;must be called
WAITASEC bcf onesec,1 ; reset onesec flag
waitloop2 btfsc onesec,1 ; check if set no then carry on
return
call WAIT
goto waitloop2
;--------------------------------------------------------------------------
WAITA4SEC bcf onesec,1
waitloop3 btfsc onesec,1
return
call WAIT4
goto waitloop3
;--------------------------------------------------------------------------
WAITA3SEC bcf onesec,1
waitloop4 btfsc onesec,1
return
call WAIT3
goto waitloop4
;-------------------------------------------------------------------------
WAIT btfss INTCON,T0IF ;check to see if T0 IRQ occur
return ;nope
bcf INTCON,T0IF ;yep then clear the IRQ flag
decfsz tcount0,f ;decrement tcount0, if zero
return
decfsz tcount1,f ;decrement tcount1,
return
movf tconst0,w ;if zero reset tcount0
movwf tcount0
movf tconst1,w ;reset tcount1
movwf tcount1 ;then add one to seconds
bsf onesec,1 ;flag that a second has occured
; movf fraction,w ;
; subwf TMR0,f ; put tmr0 back a fraction of a cycle
; btfss STATUS,C ; if c is clear tmr0 < fraction
; incf tcount0,f ; so add 1 to tcount0 to ensure delay
return
;----------------------------------------------------------------------------------------
WAIT4 btfss INTCON,T0IF ;check to see if T0 IRQ occur (1/4 of a second)
return ;nope
bcf INTCON,T0IF ;yep then clear the IRQ flag
decfsz tcounta0,f ;decrement tcount0, if zero
return
decfsz tcounta1,f ;decrement tcount1,
return
movf tconsta0,w ;if zero reset tcount0
movwf tcounta0
movf tconsta1,w ;reset tcount1
movwf tcounta1 ;then add one to seconds
bsf onesec,1 ;flag that a second has occured
return
;----------------------------------------------------------------------------------------
WAIT3 btfss INTCON,T0IF ;check to see if T0 IRQ occur (3/5 of a second)
return ;nope
bcf INTCON,T0IF ;yep then clear the IRQ flag
decfsz tcountb0,f ;decrement tcount0, if zero
return
decfsz tcountb1,f ;decrement tcount1,
return
movf tconstb0,w ;if zero reset tcount0
movwf tcountb0
movf tconstb1,w ;reset tcount1
movwf tcountb1 ;then add one to seconds
bsf onesec,1 ;flag that a second has occured
return
;routine library ---------------------------------------------
;Increment seconds by one
INCSEC incf sec1,1
movlw 0x0a
xorwf sec1,0
btfsc STATUS,Z ;jump if not equal
goto subinc1
return
subinc1 clrf sec1
incf sec10,1
movlw 0x06
xorwf sec10,0 ;only sixty second
btfsc STATUS,Z
goto subinc2
return
subinc2 clrf sec10
incf min1,1
movlw 0x0a
xorwf min1,0 ;only upto 9:59 minutes
btfsc STATUS,Z
clrf min1
subinc3 return
;------------------------------------------------------------
;Decrement seconds by one
DECSEC_t0 decf sec1,1
btfsc sec1,7 ;if number is negative
goto subdec1_t0
return
subdec1_t0 movlw 0x09 ;return to 9
movwf sec1
decf sec10,1
btfsc sec10,7
goto subdec2_t0
return
subdec2_t0 movlw 0x05
movwf sec10
decf min1,1
btfsc min1,7
;btfsc STATUS,Z
goto LOAD_T1
return
;------------------------------------------------------------
;loads the preset variables for t0
LOAD_T0 movf t0_min1_save,W
movwf min1
movf t0_sec10_save,W
movwf sec10
movf t0_sec1_save,W
movwf sec1
movlw 0x01
xorwf tmode,1
call BUZZER
return
;------------------------------------------------------------
;Decrement seconds by one
DECSEC_t1 decf sec1,1
btfsc sec1,7 ;if number is negative
goto subdec1_t1 ;yes then jump
return
subdec1_t1 movlw 0x09 ;then load 9 seconds
movwf sec1
decf sec10,1
btfsc sec10,7 ;is tens of seconds zero
goto subdec2_t1
return
subdec2_t1 movlw 0x05 ;then load 5
movwf sec10
decf min1,1
btfsc min1,7 ;is minutes negative
goto LOAD_T0 ;yes then change timers
return
;------------------------------------------------------------
;loads the preset variables for t0
LOAD_T1 movf t1_min1_save,W
movwf min1
movf t1_sec10_save,W
movwf sec10
movf t1_sec1_save,W
movwf sec1
movlw 0x01
xorwf tmode,1
call BUZZER
return
;------------------------------------------------------------
;determines if t0 or t1 and then decrements the time
TICK movf tmode,1 ;increments the time
btfsc STATUS,Z
goto run_t0
call DECSEC_t1
return
run_t0 call DECSEC_t0
return
;------------------------------------------------------------
;change the seconds digit only
PRINTSEC1
movlw B'10000000' ;select the external 4511 chip that drives the seconds
movwf PORTB ;the LE only latches when low.
movf sec1,0
xorlw B'11111111'
movwf PORTA
clrw
movwf PORTB ;store value
return
;------------------------------------------------------------
;change the 10's of second digit only
PRINTSEC10
movlw B'01000000'
movwf PORTB
movf sec10,0
xorlw B'11111111'
movwf PORTA
clrw ;latch the output
movwf PORTB
return
;------------------------------------------------------------
;change the minute only
PRINTMIN1
movlw B'00100000'
movwf PORTB
movf min1,0
xorlw B'11111111'
movwf PORTA
clrw ;latch the output
movwf PORTB
return
;------------------------------------------------------------
;SET_PORTB movwf temp ;save value
; movf alarmcount,1 ;check to see if zero
; btfss STATUS,Z
; goto set_speaker
; movfw temp
; return
;
;set_speaker movfw temp
; iorlw B'00010000'
; return
;------------------------------------------------------------
PRINTALL bcf STATUS,RP0
movlw B'00100000' ;select second
movwf PORTB
movf min1,0
movwf 1
btfsc STATUS,Z ;check if min is zero
goto leadingZero ;if zero make invalid hence blank
xorlw B'11111111'
movwf PORTA
movlw B'00000000'
movwf PORTB ;store value
movlw B'01000000' ;select second
movwf PORTB
movf sec10,0
xorlw B'11111111'
movwf PORTA
movlw B'00000000'
movwf PORTB ;store value
goto second
leadingZero clrw
movwf PORTA
movlw B'01000000' ;select second
movwf PORTB
movf sec10,0
movwf 1 ;test W register for zero
btfsc STATUS,Z ;
movlw B'11111111'
xorlw B'11111111'
movwf PORTA
movlw B'00000000'
movwf PORTB ;store value
second movlw B'10000000' ;select second
movwf PORTB
movf sec1,0
xorlw B'11111111'
movwf PORTA
movlw B'00000000'
movwf PORTB ;store value
return
;------------------------------------------------------------
;sets the appropriate ports to input and outputs
INITPORTS bsf STATUS,RP0 ;select bank 1
movlw B'11110000'
movwf TRISA ;Set port A to outputs
movlw B'00001111'
movwf TRISB
bcf STATUS,RP0
return
;------------------------------------------------------------
;timings for a 4MHz gives 500,000 cycles per second = 0x07a120 hex
;for my program (fine tuned it) 0x07a0ee
INITRTCC movlw 0x07
movwf tconst1
incf tconst1,w
movwf tconst1
movwf tcount1
movlw 0xa1
movwf tconst0
movwf tcount0
; movlw 0x20
; movwf fraction
movlw 0x03
movwf tconsta1
incf tconsta1,w
movwf tconsta1
movwf tcounta1
movlw 0x0d
movwf tconsta0
movwf tcounta0
movlw 0x04
movwf tconstb1
incf tconstb1,w
movwf tconstb1
movwf tcountb1
movlw 0x93
movwf tconstb0
movwf tcountb0
bsf STATUS,RP0 ;select bank 1
movlw 0x50 ;set option_reg to TOCS=0 (internal),PSA=0 (tmr0),
movwf OPTION_REG ;tmr0 prescaler = 1 in 2, port b pullups on
bcf STATUS,RP0 ;the rule will be to always leave in bank0
return
;------------------------------------------------------------
;routine to play sound here
BUZZER ; movlw 3
; movwf alarmcount
movlw B'00010000' ;turn on relay for sound
movwf PORTB
; return
call WAITASEC
call WAITASEC
call WAITASEC
movlw B'00000000' ;turn off relay for sound
movwf PORTB
return
;BUZZER_OFF movlw B'00000000' ;turn off relay for sound
; movwf PORTB
; return
;------------------------------------------------------------
CHGDIGIT ;call WAITASEC ;debounce the switch
;call WAITASEC
call debounce
;goto RESTART
;call LOAD_T0 ;start with Timer0
movf t0_min1_save,0
movwf min1
movf t0_sec10_save,0
movwf sec10
movf t0_sec1_save,0
movwf sec1
call PRINTSEC1
call PRINTSEC10
call PRINTMIN1
;call PRINTALL ;display all the digits
movlw 01 ;start from first digit
movwf digit
clrf tmode ;also used to toggle flashing
clrf timerselect ;start with timer0
chkbutloop btfss PORTB,0 ;check to see if prg pressed
goto nextdigit
btfsc onesec,1
goto inc_time
call WAIT4
btfss PORTB,1 ;inc button
call INC_DIGIT
goto chkbutloop
inc_time bcf onesec,1
call FLASHDIGIT
goto chkbutloop
;--------------------------------------------------------------
;increment the specific digit by one
INC_DIGIT
;call WAITA4SEC
bcf onesec,1
btfsc digit,0 ;is seconds
goto incsec
btfsc digit,1
goto incsec10
incmin1 incf min1,1
movlw 0x0a
xorwf min1,0
btfsc STATUS,Z ;jump if not equal
clrf min1
goto displaytme
incsec incf sec1,1
movlw 0x0a
xorwf sec1,0
btfsc STATUS,Z ;jump if not equal
clrf sec1
goto displaytme
incsec10 incf sec10,1
movlw 0x06
xorwf sec10,0
btfsc STATUS,Z ;jump if not equal
clrf sec10
displaytme call PRINTSEC1
call PRINTSEC10
call PRINTMIN1
call WAITA3SEC
;call WAITA4SEC
return
;--------------------------------------------------------------
nextdigit clrf tmode ;ensure back to the right toggle mode
;call PRINTALL ;display all digits
call PRINTSEC1
call PRINTSEC10
call PRINTMIN1
call debounce
;call WAITA4SEC
;call WAITA4SEC
;call WAITASEC
bcf STATUS,C ;ensure the carry flag is cleared
rlf digit,1 ;rotate left
btfss digit,3 ;all finished this timer
goto chkbutloop
;check which timer
btfss timerselect,0 ;is that the second timer
goto secondtimer
goto progend
secondtimer movlw 01 ;start from first digit
movwf digit
movwf timerselect ;second timer
clrf tmode ;also used to toggle flashing
movf min1,0 ;store values for timer0
movwf t0_min1_save
movf sec10,0
movwf t0_sec10_save
movf sec1,0
movwf t0_sec1_save
;call LOAD_T1
movf t1_min1_save,0
movwf min1
movf t1_sec10_save,0
movwf sec10
movf t1_sec1_save,0
movwf sec1
movlw 0x01
xorwf tmode,1
call PRINTSEC1
call PRINTSEC10
call PRINTMIN1
;call WAITASEC
;call WAITASEC
goto chkbutloop ;continue with second timer
progend movf min1,0 ;store values for timer0
movwf t1_min1_save
movf sec10,0
movwf t1_sec10_save
movf sec1,0
movwf t1_sec1_save
call SAVEEEPROM ;
goto RESTART
;------------------------------------------------------------------
FLASHALL movlw 0x01 ;toggle flash
xorwf tmode,1
movf tmode,1
movlw 01 ;start from first digit
movwf digit
call flash_start ;also toggle counter
bcf STATUS,C ;ensure the carry flag is cleared
rlf digit,1 ;rotate left
call flash_start
bcf STATUS,C ;ensure the carry flag is cleared
rlf digit,1 ;rotate left
call flash_start
return
;------------------------------------------------------------------
FLASHDIGIT movlw 0x01
xorwf tmode,1
movf tmode,1 ;increments the toogle
flash_start btfsc STATUS,Z
goto digiton ;digits are off on this run
digitoff btfsc digit,0 ;is it seconds?
goto sec1_off
btfsc digit,1 ;is it 10's of seconds
goto sec10_off
goto min1_off
digiton btfsc digit,0
goto PRINTSEC1
btfsc digit,1
goto PRINTSEC10
goto PRINTMIN1
sec1_off movlw B'10000000' ;select the external 4511 chip that drives the seconds
movwf PORTB ;the LE only latches when low.
;movlw B'11111111' ;blank display
clrw
movwf PORTA
movwf PORTB ;store value
return
sec10_off movlw B'01000000' ;select the external 4511 chip that drives the seconds
movwf PORTB ;the LE only latches when low.
;movlw B'11111111'
clrw
movwf PORTA
movwf PORTB ;store value
return
min1_off movlw B'00100000' ;select the external 4511 chip that drives the seconds
movwf PORTB ;the LE only latches when low.
;movlw B'11111111'
clrw
movwf PORTA
movwf PORTB ;store value
return
;-------------------------------------------------------------------------------
READEEPROM
bcf STATUS, RP0 ;bank 0
movlw 00 ;load eeprom address
movwf EEADR ;set eeprom address
bsf STATUS,RP0 ;bank 1
bsf EECON1,RD ;start eeprom readings
bcf STATUS,RP0 ;bank 0
movf EEDATA,W ;read the eeprom data
andlw B'00001111'
movwf t0_sec1_save
;return
bcf STATUS, RP0
movlw ee_sec10_t0
movwf EEADR
bsf STATUS,RP0
bsf EECON1,RD
bcf STATUS,RP0
movf EEDATA,W
andlw B'00001111'
movwf t0_sec10_save
bcf STATUS, RP0
movlw ee_min1_t0
movwf EEADR
bsf STATUS,RP0
bsf EECON1,RD
bcf STATUS,RP0
movf EEDATA,W
andlw B'00001111'
movwf t0_min1_save
movlw ee_sec1_t1
movwf EEADR
bsf STATUS,RP0
bsf EECON1,RD
bcf STATUS,RP0
movf EEDATA,W
andlw B'00001111'
movwf t1_sec1_save
bcf STATUS, RP0
movlw ee_sec10_t1
movwf EEADR
bsf STATUS,RP0
bsf EECON1,RD
bcf STATUS,RP0
movf EEDATA,W
andlw B'00001111'
movwf t1_sec10_save
bcf STATUS, RP0
movlw ee_min1_t1
movwf EEADR
bsf STATUS,RP0
bsf EECON1,RD
bcf STATUS,RP0
movf EEDATA,W
andlw B'00001111'
movwf t1_min1_save
bcf STATUS,RP0 ;the rule will be to always leave in bank0
return
WRITEEEPROM bsf STATUS,RP0 ;bank 1
bcf INTCON,GIE ;disable IRQs
bsf EECON1, WREN
movlw 0x55
movwf EECON2
movlw 0xaa
movwf EECON2
bsf EECON1, WR
nop
wait_ee btfss EECON1,4
goto wait_ee
bcf EECON1,4
return
;-------------------------------------------------------------------------------
SAVEEEPROM
;seconds timer 0
bcf STATUS,RP0 ;bank 0
movlw ee_sec1_t0 ;select saved sec1
movwf EEADR
movf t0_sec1_save,w
movwf EEDATA
call WRITEEEPROM
;tens of seconds timer 0
bsf INTCON,GIE ;enable irq
bcf STATUS,RP0 ;bank 0
; bcf INTCON,GIE ;disable IRQs
movlw ee_sec10_t0 ;select saved sec1
movwf EEADR
movf t0_sec10_save,w
movwf EEDATA
call WRITEEEPROM
;minutes timer 0
bcf STATUS,RP0 ;bank 0
movlw ee_min1_t0 ;select saved sec1
movwf EEADR
movf t0_min1_save,w
movwf EEDATA
call WRITEEEPROM
;seconds timer 1
bcf STATUS,RP0 ;bank 0
movlw ee_sec1_t1 ;select saved sec1
movwf EEADR
movf t1_sec1_save,w
movwf EEDATA
call WRITEEEPROM
;tens of seconds timer 1
bcf STATUS,RP0 ;bank 0
movlw ee_sec10_t1 ;select saved sec1
movwf EEADR
movf t1_sec10_save,w
movwf EEDATA
call WRITEEEPROM
;minutes timer 1
bcf STATUS,RP0 ;bank 0
movlw ee_min1_t1 ;select saved sec1
movwf EEADR
movf t1_min1_save,w
movwf EEDATA
call WRITEEEPROM
bcf STATUS,RP0 ;the rule will be to always leave in bank0
return
;-------------------------------------------------------------------------------
PAUSE bcf STATUS,RP0 ;set bank zero
clrf tmode ;also used to toggle flashing
;call WAITASEC ;debounce the switch
;call WAITASEC
call debounce ;debounce the switch
looppause btfss PORTB,0 ;check to see if prg pressed
goto exit_pause ;yes goto main loop
btfss PORTB,1 ;else check pause button
goto exit_pause ;yes goto main loop
; btfsc onesec,1
; goto debounce
; call WAIT4 ;wait 1/4 second
goto looppause ;keep waiting until keypressed.
exit_pause call debounce
call INITRTCC
goto inc_tick
;-----
;inc_flash bcf onesec,1
; ;CALL FLASHALL
;
; goto looppause
;
;debounce call WAITASEC ;debounce the switch
; call WAITASEC
; goto inc_flash
END