[Menu]>[Guide to use the PIC]>[Circuits Gallery]>[Digital Clock]


Source code file of Digital Clock

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
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
;********************************************************
;
;                       Digital Clock
;
;                                 Device : PIC16F873
;                                 Author : Seiichi Inoue
;********************************************************

        list            p=pic16f873
        include         p16f873.inc
       __config _hs_osc & _wdt_off & _pwrte_on & _lvp_off

;****************  Label Definition  ********************
        cblock  h'20'
count                           ;Clock counter
disp_p                          ;Disply position
disp_pw                         ;Disply position work
disp_data                       ;Disply data save area
disp_h10w                       ;Tens of hour work
disp_h10                        ;Tens of hour
disp_h1                         ;Units of hour
disp_m10                        ;Tens of minute
disp_m1                         ;Units of minute
disp_s10                        ;Tens of second
disp_s1                         ;Units of second
mode                            ;Mode (0:Adjust 1:Clock)
rb6ll                           ;0 sec adjust Last look
rb7ll                           ;Time adjust Last look
rb7count                        ;Time adj guard counter
digit_posi                      ;Adj digit position data
digit_posiw                     ;Adj digit position work
digit_save                      ;Previous adj data save
digit_blink                     ;Digit blink counter
blink_cont                      ;Blink (0:ON 1:OFF)
change_st                       ;Digit change status
change_wk                       ;Digit change work

seg7_ha                         ;7 segLED table head adr
seg70                           ;Pattern 0 set adr
seg71                           ;Pattern 1 set adr
seg72                           ;Pattern 2 set adr
seg73                           ;Pattern 3 set adr
seg74                           ;Pattern 4 set adr
seg75                           ;Pattern 5 set adr
seg76                           ;Pattern 6 set adr
seg77                           ;Pattern 7 set adr
seg78                           ;Pattern 8 set adr
seg79                           ;Pattern 9 set adr
seg7a                           ;Pattern A set adr
seg7b                           ;Pattern B set adr
        endc

ra1     equ     h'01'           ;RA1 port designation
ra2     equ     h'02'           ;RA2 port designation
ra3     equ     h'03'           ;RA3 port designation
rb1     equ     h'01'           ;RB1 port designation
rb4     equ     h'04'           ;RB4 port designation
rb5     equ     h'05'           ;RB5 port designation
rb6     equ     h'06'           ;RB6 port designation
rb7     equ     h'07'           ;RB7 port designation

seg7_0  equ     b'01000000'     ;-gfedcba Pattern 0
seg7_1  equ     b'01111001'     ;         Pattern 1
seg7_2  equ     b'00100100'     ;         Pattern 2
seg7_3  equ     b'00110000'     ;         Pattern 3
seg7_4  equ     b'00011001'     ;         Pattern 4
seg7_5  equ     b'00010010'     ;         Pattern 5
seg7_6  equ     b'00000010'     ;         Pattern 6
seg7_7  equ     b'01111000'     ;         Pattern 7
seg7_8  equ     b'00000000'     ;         Pattern 8
seg7_9  equ     b'00010000'     ;         Pattern 9
seg7_a  equ     b'01111111'     ;         LED off
seg7_b  equ     b'00100011'     ;         Illegal int

;****************  Program Start  ***********************
        org     0               ;Reset Vector
        goto    init
        org     4               ;Interrupt Vector
        goto    int

;****************  Initial Process  *********************
init

;*** Port mode initializing
        bsf     status,rp0      ;Change to Bank1
        movlw   b'00000110'     ;RA port to digital mode
        movwf   adcon1          ;Set ADCON1 register
        movlw   b'00000000'     ;RA port to output mode
        movwf   trisa           ;Set TRISA register
        movlw   b'11111101'     ;RB1:output,OTHER:input
        movwf   trisb           ;Set TRISB register
        movlw   b'00000000'     ;RC port to output mode
        movwf   trisc           ;Set TRISC register

;*** LED disply interval initializing (Timer0)
        movlw   b'00000010'     ;PBPU=on,PSA=0,PS=1:8
        movwf   option_reg      ;Set OPTION_REG register
        bcf     status,rp0      ;Change to Bank0
        movlw   d'131'          ;(256-131)x8=1000usec
        movwf   tmr0            ;Set TMR0 register

;*** Port initializing
        clrf    porta           ;Clear PORTA
        clrf    portb           ;Clear PORTB
        movlw   b'11111111'     ;Set LED off data
        movwf   portc           ;Set PORTC

;*** Work area initializing
        clrf    count           ;Clear Clock counter
        movlw   d'6'            ;Disply position = 6
        movwf   disp_p          ;Set disply position
        clrf    disp_h10        ;Clear Tens of hour
        clrf    disp_h1         ;Clear Units of hour
        clrf    disp_m10        ;Clear Tens of minute
        clrf    disp_m1         ;Clear Units of minute
        clrf    disp_s10        ;Clear Tens of second
        clrf    disp_s1         ;Clear Units of second
        clrf    mode            ;Set Adjust mode
        clrf    rb6ll           ;Clear 0 sec Last look
        clrf    rb7ll           ;Clear Time adj Last look
        clrf    rb7count        ;Clear Time adj guard
        clrf    digit_posi      ;Clear Adj digit position
        clrf    digit_blink     ;Clear Digit blink count
        clrf    blink_cont      ;Set Blink on
        clrf    change_st       ;Clear Change status

        movlw   seg70           ;Set 7seg head address
        movwf   seg7_ha         ;Save 7seg head address
        movlw   seg7_0          ;Set 7segment pattern 0
        movwf   seg70           ;Save pattern 0
        movlw   seg7_1          ;Set 7segment pattern 1
        movwf   seg71           ;Save pattern 1
        movlw   seg7_2          ;Set 7segment pattern 2
        movwf   seg72           ;Save pattern 2
        movlw   seg7_3          ;Set 7segment pattern 3
        movwf   seg73           ;Save pattern 3
        movlw   seg7_4          ;Set 7segment pattern 4
        movwf   seg74           ;Save pattern 4
        movlw   seg7_5          ;Set 7segment pattern 5
        movwf   seg75           ;Save pattern 5
        movlw   seg7_6          ;Set 7segment pattern 6
        movwf   seg76           ;Save pattern 6
        movlw   seg7_7          ;Set 7segment pattern 7
        movwf   seg77           ;Save pattern 7
        movlw   seg7_8          ;Set 7segment pattern 8
        movwf   seg78           ;Save pattern 8
        movlw   seg7_9          ;Set 7segment pattern 9
        movwf   seg79           ;Save pattern 9
        movlw   seg7_a          ;Set 7segment pattern A
        movwf   seg7a           ;Save pattern A
        movlw   seg7_b          ;Set 7segment pattern B
        movwf   seg7b           ;Save pattern B

;*** Interruption control
        movlw   b'10111000'     ;GIE&T0IE&INTE&RBIE=ON
        movwf   intcon          ;Set INTCON register

wait
        goto    $               ;Interruption wait

;***************  Interruption Process  *****************
int
        movf    intcon,w        ;Read INTCON register
        btfsc   intcon,intf     ;RB0/INT interrupt ?
        goto    clock           ;Yes. "Clock"
        btfsc   intcon,t0if     ;TMR0 overflow ?
        goto    led_disp        ;Yes. "LED disply"
        btfsc   intcon,rbif     ;RB Port Change ?
        goto    digit_change    ;Yes. "Digit change"

;***************  Illegal interruption  *****************
illegal
        movlw   h'0b'           ;Set Illegal disp digit
        addwf   seg7_ha,w       ;Seg7 H.Adr + digit
        movwf   fsr             ;Set FSR register
        movf    indf,w          ;Read seg7 data
        movwf   portc           ;Set LED data
        movlw   b'00000101'     ;Set sec1 select data
        movwf   porta           ;Write digit select data
        goto    $               ;Stop

;************  END of Interruption Process **************
int_end
        retfie

;*********  LED disply Process (1msec interval) *********
led_disp
        bcf     intcon,t0if     ;Clear T0IF
        movlw   d'131'          ;Set Time value (1msec)
        movwf   tmr0            ;Write TMR0 register
        movlw   b'11111111'     ;LED off data
        movwf   portc           ;Clear disply
        movf    disp_p,w        ;Read disply position
        movwf   disp_pw         ;Save position data
        decfsz  disp_pw,f       ;Units of second ?
        goto    led_disp0       ;No. Next

;*** Control UNITS of SECOND
        movlw   b'00000101'     ;Set units of second
        movwf   porta           ;Write PORTA register
        movf    disp_s1,w       ;Read units of sec data
        movwf   disp_data       ;Save data
        goto    led_disp8       ;Jump to LED control
led_disp0
        decfsz  disp_pw,f       ;Tens of second ?
        goto    led_disp1       ;No. Next

;*** Control TENS of SECOND
        movlw   b'00000100'     ;Set tens of second
        movwf   porta           ;Write PORTA register
        movf    disp_s10,w      ;Read tens of sec data
        movwf   disp_data       ;Save data
        goto    led_disp8       ;Jump to LED control
led_disp1
        decfsz  disp_pw,f       ;Units of minute ?
        goto    led_disp2       ;No. Next

;*** Control UNITS of MINUTE
        movlw   b'00000011'     ;Set units of minute
        movwf   porta           ;Write PORTA register
        movf    disp_m1,w       ;Read units of min data
        movwf   disp_data       ;Save data
        goto    led_disp8       ;Jump to LED control
led_disp2
        decfsz  disp_pw,f       ;Tens of minute ?
        goto    led_disp3       ;No. Next

;*** Control TENS of MINUTE
        movlw   b'00000010'     ;Set tens of minute
        movwf   porta           ;Write PORTA register
        movf    disp_m10,w      ;Read tens of min data
        movwf   disp_data       ;Save data
        goto    led_disp8       ;Jump to LED control
led_disp3
        decfsz  disp_pw,f       ;Units of hour ?
        goto    led_disp4       ;No. Next

;*** Control UNITS of HOUR
        movlw   b'00000001'     ;Set units of hour
        movwf   porta           ;Write PORTA register
        movf    disp_h1,w       ;Read units of hour data
        movwf   disp_data       ;Save data
        goto    led_disp8       ;Jump to LED control

;*** Control TENS of HOUR
led_disp4
        movlw   b'00000000'     ;Set tens of hour
        movwf   porta           ;Write PORTA register
        movlw   h'0a'           ;Set off data
        movwf   disp_data       ;Save data
        subwf   disp_h10,w      ;H10 - off data
        btfsc   status,z        ;H10 = off data ?
        goto    led_disp8       ;Jump to LED control
        movf    disp_h10,w      ;Read tens of hour data
        movwf   disp_h10w       ;Save tens of hour data
        btfss   status,z        ;AM 0x o'clock ?
        goto    led_disp5       ;No. Next
        movlw   b'11111110'     ;PM=off,Tens=off,AM=on
        goto    led_disp9       ;Jump to PORTC write
led_disp5
        decfsz  disp_h10w,f     ;AM 1x o'clock ?
        goto    led_disp6       ;No. Next
        movlw   b'11111000'     ;PM=off,Tens=1,AM=on
        goto    led_disp9       ;Jump to PORTC write
led_disp6
        decfsz  disp_h10w,f     ;PM 0x o'clock ?
        goto    led_disp7       ;No. Next
        movlw   b'11110111'     ;PM=on,Tens=off,AM=off
        goto    led_disp9       ;Jump to PORTC write
led_disp7
        movlw   b'11110001'     ;PM=on,Tens=1,AM=off
        goto    led_disp9       ;Jump to PORTC write

led_disp8
        movf    disp_data,w     ;Read disply digit data
        addwf   seg7_ha,w       ;Seg7 H.Adr + digit
        movwf   fsr             ;Set FSR register
        movf    indf,w          ;Read seg7 data
led_disp9
        movwf   portc           ;Write LED data

led_dispe
        decfsz  disp_p,f        ;End of cycle ?
        goto    int_end         ;Jump to END of interrupt
        movlw   d'6'            ;Set initial value
        movwf   disp_p          ;Write disply position
        goto    int_end         ;Jump to END of interrupt


;******  Clock count up Process (20msec interval) *******
clock
        bcf     intcon,intf     ;Clear INTF

;*** Time adjust mode check
        movf    mode,w          ;Read time adj mode data
        btfsc   status,z        ;Time adjust mode ?
        goto    adjust          ;Yes. Jump to Adjust Proc

;*** 0 second adjust check
        btfss   portb,rb6       ;0 sec adjust ?
        goto    check1          ;No.
        movf    rb6ll,w         ;Yes. Read RB6 last look
        btfss   status,z        ;Last look = 0 ?
        goto    check2          ;No. Last look = 1
        incf    rb6ll,f         ;Yes. Set last look
        clrf    disp_s1         ;Clear units of second
        clrf    disp_s10        ;Clear tens of second
        clrf    count           ;Clear clock counter
        goto    check2          ;Jump to time adj check
check1
        clrf    rb6ll           ;Clear RB6 last look

;*** Time adjust demand check
check2
        btfss   portb,rb7       ;Time adjust ?
        goto    check4          ;No.
        movlw   d'100'          ;Set guard (2sec)
        subwf   rb7count,w      ;Counter - Guard
        btfss   status,c        ;Counter >= Guard ?
        goto    check3          ;No. Counter < Guard
        clrf    digit_posi      ;Set position to H10
        movf    disp_h10,w      ;Read tens of hour
        movwf   digit_save      ;Save previous adj data
        clrf    disp_s1         ;Clear units of second
        clrf    disp_s10        ;Clear tens of second
        clrf    count           ;Clear clock counter
        incf    rb7ll,f         ;Set RB7 last look
        bsf     intcon,rbie     ;Set RBIE bit
        clrf    mode            ;Set time adjust mode
        goto    adjust          ;Jump to Adjust process
check3
        incf    rb7count,f      ;Counter + 1
        goto    clock1          ;Jump to clock count up
check4
        clrf    rb7count        ;Clear counter
        clrf    rb7ll           ;Clear RB7 last look

;*** Timer count up
clock1
        movlw   d'49'           ;Set 1 sec data
        subwf   count,w         ;Counter - 1 sec
        btfsc   status,c        ;Counter >= 1 sec ?
        goto    clock_1sec      ;Yes. Counter >= 1 sec
        incf    count,f         ;No. Counter + 1
        goto    int_end         ;Jump to END of interrupt

clock_1sec
        clrf    count           ;Clear 1 second counter
        movlw   d'9'            ;Set check data
        subwf   disp_s1,w       ;S1 - 9
        btfsc   status,c        ;S1 >= 9 sec ?
        goto    clock_10sec     ;Yes. S1 >= 9 sec
        incf    disp_s1,f       ;No. S1 + 1
        bcf     portb,rb1       ;Clear time signal
        goto    int_end         ;Jump to END of interrupt

clock_10sec
        clrf    disp_s1         ;Set xx:xx:x0
        movlw   d'5'            ;Set check data
        subwf   disp_s10,w      ;S10 - 5
        btfsc   status,c        ;S10 >= 5x sec ?
        goto    clock_1min      ;Yes. S10 >= 5x sec
        incf    disp_s10,f      ;No. S10 + 1
        goto    int_end         ;Jump to END of interrupt

clock_1min
        clrf    disp_s10        ;Set xx:xx:0x
        movlw   d'9'            ;Set check data
        subwf   disp_m1,w       ;M1 - 9
        btfsc   status,c        ;M1 >= 9 min ?
        goto    clock_10min     ;Yes. M1 >= 9 min
        incf    disp_m1,f       ;No. M1 + 1
        goto    int_end         ;Jump to END of interrupt

clock_10min
        clrf    disp_m1         ;Set xx:x0:xx
        movlw   d'5'            ;Set check data
        subwf   disp_m10,w      ;M10 - 5
        btfsc   status,c        ;M10 >= 5x min ?
        goto    clock_1hour     ;Yes. M10 >= 5x min
        incf    disp_m10,f      ;No. M10 + 1
        goto    int_end         ;Jump to END of interrupt

clock_1hour
        clrf    disp_m10        ;Set xx:0x:xx
        movf    disp_h10,w      ;Read tens of hour data
        movwf   disp_h10w       ;Save tens of hour data
        btfss   status,z        ;AM 0x o'clock ?
        goto    hour1           ;No. Next

;*** AM 0x
        movlw   d'9'            ;Set check data
        subwf   disp_h1,w       ;H1 - 9
        btfsc   status,c        ;H1 >= 9 hour ?
        goto    am09            ;Yes. H1 >= 9 hour
        incf    disp_h1,f       ;No. H1 + 1
        goto    time_check      ;Jump to Time Check
am09    clrf    disp_h1         ;Set x0:xx:xx
        incf    disp_h10,f      ;Set AM10:00:00
        goto    time_check      ;Jump to Time Check
hour1
        decfsz  disp_h10w,f     ;AM 1x o'clock ?
        goto    hour2           ;No. Next

;*** AM 1x
        decfsz  disp_h1,w       ;AM 11 o'clock ?
        goto    am10            ;No.  AM 10 o'clock
        goto    am11            ;Yes. AM 11 o'clock
am10    incf    disp_h1,f       ;H1 + 1
        goto    time_check      ;Jump to Time Check
am11    incf    disp_h1,f       ;Set x2:xx:xx
        movlw   d'3'            ;Set PM 1x
        movwf   disp_h10        ;Set PM12:00:00
        goto    time_check      ;Jump to Time Check
hour2
        decfsz  disp_h10w,f     ;PM 0x o'clock ?
        goto    hour3           ;No. Next

;*** PM 0x
        movlw   d'9'            ;Set check data
        subwf   disp_h1,w       ;H1 - 9
        btfsc   status,c        ;H1 >= 9 hour ?
        goto    pm09            ;Yes. H1 >= 9 hour
        incf    disp_h1,f       ;No. H1 + 1
        goto    time_check      ;Jump to Time Check
pm09    clrf    disp_h1         ;Set x0:xx:xx
        incf    disp_h10,f      ;Set PM10:00:00
        goto    time_check      ;Jump to Time Check

;*** PM 1x
hour3
        movlw   d'1'            ;Set check data
        subwf   disp_h1,w       ;H1 - 1
        btfsc   status,z        ;H1 = 1 hour ?
        goto    pm11            ;Yes. PM 11 o'clock
        movlw   d'2'            ;Set check data
        subwf   disp_h1,w       ;H1 - 2
        btfsc   status,c        ;H1 >= 2 hour ?
        goto    pm12            ;Yes. PM 12 o'clock
        incf    disp_h1,f       ;No. H1 + 1
        goto    time_check      ;Jump to Time Check
pm11    clrf    disp_h1         ;Set 0 o'clock
        clrf    disp_h10        ;Set AM00:00:00
        goto    time_check      ;Jump to Time Check
pm12    movlw   d'1'            ;Set data
        movwf   disp_h1         ;Set 1 o'clock
        movlw   d'2'            ;Set data
        movwf   disp_h10        ;Set PM01:00:00
        goto    time_check      ;Jump to Time Check

;*** Time signal check
time_check
        btfsc   disp_h10,1      ;AM ?
        goto    tck4            ;No. PM
        movlw   d'7'            ;Set AM 7:00 data
        subwf   disp_h1,w       ;H1 - check data
        btfss   status,z        ;AM 7:00 ?
        goto    tck1            ;No. Next
        goto    time_signal     ;Yes. Jump to time signal
tck1    movlw   d'8'            ;Set AM 8:00 data
        subwf   disp_h1,w       ;H1 - check data
        btfss   status,z        ;AM 8:00 ?
        goto    tck2            ;No. Next
        goto    time_signal     ;Yes. Jump to time signal
tck2    movlw   d'9'            ;Set AM 9:00 data
        subwf   disp_h1,w       ;H1 - check data
        btfss   status,z        ;AM 9:00 ?
        goto    tck3            ;No. Next
        goto    time_signal     ;Yes. Jump to time signal
tck3    btfss   disp_h10,0      ;AM 1x ?
        goto    no_signal       ;No. End of signal check
        movf    disp_h1,w       ;Read H1
        btfss   status,z        ;AM 10:00 ?
        goto    no_signal       ;No. End of signal check
        goto    time_signal     ;Yes. Jump to time signal

tck4    movlw   d'6'            ;Set PM 6:00 data
        subwf   disp_h1,w       ;H1 - check data
        btfss   status,z        ;PM 6:00 ?
        goto    tck5            ;No. Next
        goto    time_signal     ;Yes. Jump to time signal
tck5    movlw   d'7'            ;Set PM 7:00 data
        subwf   disp_h1,w       ;H1 - check data
        btfss   status,z        ;PM 7:00 ?
        goto    tck6            ;No. Next
        goto    time_signal     ;Yes. Jump to time signal
tck6    movlw   d'8'            ;Set PM 8:00 data
        subwf   disp_h1,w       ;H1 - check data
        btfss   status,z        ;PM 8:00 ?
        goto    tck7            ;No. Next
        goto    time_signal     ;Yes. Jump to time signal
tck7    movlw   d'9'            ;Set PM 9:00 data
        subwf   disp_h1,w       ;H1 - check data
        btfss   status,z        ;PM 9:00 ?
        goto    no_signal       ;No. End of signal check
        goto    time_signal     ;Yes. Jump to time signal

time_signal
        bsf     portb,rb1       ;Time signal ON
no_signal
        goto    int_end         ;Jump to END of interrupt

;****** Time adjust mode Process (20msec interval) ******
adjust
;*** Adjust end check
        btfss   portb,rb6       ;0 sec adjust SW = ON ?
        goto    adjust1         ;No. Next process
        movf    digit_posi,w    ;Yes. Read digit position
        movwf   digit_posiw     ;Save digit position
        btfss   status,z        ;Position = H10 ?
        goto    adj_end1        ;No. Next
        movf    digit_save,w    ;Yes. Read saved digit
        movwf   disp_h10        ;Recover digit
        goto    adj_end4        ;Jump to adj mode end
adj_end1
        decfsz  digit_posiw,f   ;Position = H1 ?
        goto    adj_end2        ;No. Next
        movf    digit_save,w    ;Yes. Read saved digit
        movwf   disp_h1         ;Recover digit
        goto    adj_end4        ;Jump to adj mode end
adj_end2
        decfsz  digit_posiw,f   ;Position = M10 ?
        goto    adj_end3        ;No. Next
        movf    digit_save,w    ;Yes. Read saved digit
        movwf   disp_m10        ;Recover digit
        goto    adj_end4        ;Jump to adj mode end
adj_end3
        movf    digit_save,w    ;Read saved digit
        movwf   disp_m1         ;Recover digit
adj_end4
        incf    rb6ll,f         ;Set last look ON
        bcf     intcon,rbie     ;Clear RBIE bit
        incf    mode,f          ;Set clock mode
        goto    int_end         ;Jump to END of interrupt

;*** Adjust position check
adjust1
        btfss   portb,rb7       ;Position SW = ON ?
        goto    adj_posi10      ;No. SW = OFF
        movf    rb7ll,w         ;Yes. Read RB7 last look
        btfss   status,z        ;Last look = 0 ?
        goto    adjust2         ;No. Last look = 1
        incf    rb7ll,f         ;Yes. Set last look
        incf    digit_posi,f    ;Change position
        movlw   d'4'            ;Set check data
        subwf   digit_posi,w    ;Position data - 4
        btfss   status,c        ;Position over ?
        goto    adj_posi1       ;No. digit proc
        clrf    digit_posi      ;Set position to H10
adj_posi1
        movf    digit_posi,w    ;Read digit position
        movwf   digit_posiw     ;Save digit position
        btfss   status,z        ;Position = H10 ?
        goto    adj_posi3       ;No. Next
        movf    blink_cont,w    ;Read blink control
        btfsc   status,z        ;LED OFF ?
        goto    adj_posi2       ;No. LED ON
        movf    digit_save,w    ;Yes. Read saved digit
        movwf   disp_m1         ;Set M1 digit
adj_posi2
        movf    disp_h10,w      ;Read digit
        goto    adj_posi9       ;Jump to digit save
adj_posi3
        decfsz  digit_posiw,f   ;Position = H1 ?
        goto    adj_posi5       ;No. Next
        movf    blink_cont,w    ;Read blink control
        btfsc   status,z        ;LED OFF ?
        goto    adj_posi4       ;No. LED ON
        movf    digit_save,w    ;Yes. Read saved digit
        movwf   disp_h10        ;Set H10 digit
adj_posi4
        movf    disp_h1,w       ;Read digit
        goto    adj_posi9       ;Jump to digit save
adj_posi5
        decfsz  digit_posiw,f   ;Position = M10 ?
        goto    adj_posi7       ;No. Next
        movf    blink_cont,w    ;Read blink control
        btfsc   status,z        ;LED OFF ?
        goto    adj_posi6       ;No. LED ON
        movf    digit_save,w    ;Yes. Read saved digit
        movwf   disp_h1         ;Set H1 digit
adj_posi6
        movf    disp_m10,w      ;Yes. Read digit
        goto    adj_posi9       ;Jump to digit save
adj_posi7
        movf    blink_cont,w    ;Read blink control
        btfsc   status,z        ;LED OFF ?
        goto    adj_posi8       ;No. LED ON
        movf    digit_save,w    ;Yes. Read saved digit
        movwf   disp_m10        ;Set M10 digit
adj_posi8
        movf    disp_m1,w       ;Read digit
adj_posi9
        movwf   digit_save      ;Save digit
        goto    adjust2
adj_posi10
        clrf    rb7ll           ;Clear RB7 last look

;*** Adjust digit blink process
adjust2
        movlw   d'10'           ;Set 200 msec data
        subwf   digit_blink,w   ;Counter - 200 msec
        btfsc   status,c        ;Counter >= 200 msec ?
        goto    adj_blk1        ;Yes. Counter >= 200 msec
        incf    digit_blink,f   ;No. Counter + 1
        goto    int_end         ;Jump to END of interrupt
adj_blk1
        clrf    digit_blink     ;Clear Blink counter
        btfsc   blink_cont,0    ;Blink ON ?
        goto    adj_blk5        ;No. Jump to ON process

;*** LED OFF process
        incf    blink_cont,f    ;Set Blink OFF data
        movf    digit_posi,w    ;Read digit position
        movwf   digit_posiw     ;Save digit position
        btfss   status,z        ;Position = H10 ?
        goto    adj_blk2        ;No. Next
        movlw   h'0a'           ;Yes. Set LED off digit
        movwf   disp_h10        ;LED off
        goto    adj_blke        ;Jump to blink end
adj_blk2
        decfsz  digit_posiw,f   ;Position = H1 ?
        goto    adj_blk3        ;No. Next
        movlw   h'0a'           ;Yes. Set LED off digit
        movwf   disp_h1         ;LED off
        goto    adj_blke        ;Jump to blink end
adj_blk3
        decfsz  digit_posiw,f   ;Position = M10 ?
        goto    adj_blk4        ;No. Next
        movlw   h'0a'           ;Yes. Set LED off digit
        movwf   disp_m10        ;LED off
        goto    adj_blke        ;Jump to blink end
adj_blk4
        movlw   h'0a'           ;Yes. Set LED off digit
        movwf   disp_m1         ;LED off
        goto    adj_blke        ;Jump to blink end

;*** LED ON process
adj_blk5
        clrf    blink_cont      ;Set Blink ON data
        movf    digit_posi,w    ;Read digit position
        movwf   digit_posiw     ;Save digit position
        btfss   status,z        ;Position = H10 ?
        goto    adj_blk6        ;No. Next
        movf    digit_save,w    ;Read saved digit
        movwf   disp_h10        ;Set H10 digit
        goto    adj_blke        ;Jump to blink end
adj_blk6
        decfsz  digit_posiw,f   ;Position = H1 ?
        goto    adj_blk7        ;No. Next
        movf    digit_save,w    ;Read saved digit
        movwf   disp_h1         ;Set H1 digit
        goto    adj_blke        ;Jump to blink end
adj_blk7
        decfsz  digit_posiw,f   ;Position = M10 ?
        goto    adj_blk8        ;No. Next
        movf    digit_save,w    ;Read saved digit
        movwf   disp_m10        ;Set M10 digit
        goto    adj_blke        ;Jump to blink end
adj_blk8
        movf    digit_save,w    ;Read saved digit
        movwf   disp_m1         ;Set M1 digit
adj_blke
        goto    int_end         ;Jump to END of interrupt

;**************** Digit change process ******************
digit_change
        bcf     intcon,rbif     ;Clear RBIF

        movf    portb,w         ;Read PORTB
        andlw   b'00110000'     ;Pick up RB4 and RB5
        movwf   change_wk       ;Save RB4/RB5 condition
        movf    change_st,w     ;Read Digit change status
        btfss   status,z        ;Status = "0" ?
        goto    change2         ;No. Next
        movf    change_wk,w     ;Read RB4/RB5 condition
        xorlw   b'00100000'     ;Check RB4/RB5 condition
        btfss   status,z        ;RB5(B)=1 RB4(A)=0 ?
        goto    change1         ;No. next
        movlw   d'1'            ;Set status to "1"
        movwf   change_st       ;Write status
        goto    int_end         ;Jump to END of interrupt
change1
        movf    change_wk,w     ;Read RB4/RB5 condition
        xorlw   b'00110000'     ;Check RB4/RB5 condition
        btfss   status,z        ;RB5(B)=1 RB4(A)=1 ?
        goto    int_end         ;Jump to END of interrupt

;*** Count up process
        movlw   d'2'            ;Set status to "2"
        movwf   change_st       ;Write status
        movf    digit_posi,w    ;Read digit position
        movwf   digit_posiw     ;Save digit position
        btfss   status,z        ;Position = H10 ?
        goto    count_up2       ;No. Next

        movlw   d'3'            ;Set check data
        subwf   digit_save,w    ;H10 - check data
        btfss   status,z        ;H10 = 3 ?
        goto    count_up1       ;No.
        clrf    digit_save      ;Set H10 = 0
        goto    count_h10       ;Jump to save check
count_up1
        incf    digit_save,f    ;H10 + 1
        goto    count_h10       ;Jump to save check

count_up2
        decfsz  digit_posiw,f   ;Position = H1 ?
        goto    count_up8       ;No. Next

        movf    disp_h10,w      ;Read H10 digit
        andlw   b'00000001'     ;Pick up 0x/1x
        btfss   status,z        ;H10 = AM 0x or PM 0x ?
        goto    count_up4       ;No. AM 1x or PM 1x
        movlw   d'9'            ;Set check data
        subwf   digit_save,w    ;H1 - check data
        btfss   status,z        ;H1 = 9 ?
        goto    count_up3       ;No.
        clrf    digit_save      ;Set H1 = 0
        goto    count_h1        ;Jump to save check
count_up3
        incf    digit_save,f    ;H1 + 1
        goto    count_h1        ;Jump to save check
count_up4
        movf    disp_h10,w      ;Read H10 digit
        andlw   b'00000010'     ;Pick up AM/PM
        btfss   status,z        ;H10 = AM ?
        goto    count_up6       ;No. PM
        movf    digit_save,w    ;Read H1 digit
        btfss   status,z        ;H1 = 0 ?
        goto    count_up5       ;No. H1 > 1
        incf    digit_save,f    ;H1 = 1
        goto    count_h1        ;Jump to save check
count_up5
        clrf    digit_save      ;H1 = 0
        goto    count_h1        ;Jump to save check
count_up6
        movlw   d'2'            ;Set check data
        subwf   digit_save,w    ;H1 - check data
        btfss   status,c        ;H1 >= 2 ?
        goto    count_up7       ;No.
        clrf    digit_save      ;Set H1 = 0
        goto    count_h1        ;Jump to save check
count_up7
        incf    digit_save,f    ;H1 + 1
        goto    count_h1        ;Jump to save check

count_up8
        decfsz  digit_posiw,f   ;Position = M10 ?
        goto    count_up10      ;No. Next

        movlw   d'5'            ;Set check data
        subwf   digit_save,w    ;M10 - check data
        btfss   status,z        ;M10 = 5 ?
        goto    count_up9       ;No.
        clrf    digit_save      ;Set M10 = 0
        goto    count_m10       ;Jump to save check
count_up9
        incf    digit_save,f    ;M10 + 1
        goto    count_m10       ;Jump to save check

count_up10
        movlw   d'9'            ;Set check data
        subwf   digit_save,w    ;M1 - check data
        btfss   status,z        ;M1 = 9 ?
        goto    count_up11      ;No.
        clrf    digit_save      ;Set M1 = 0
        goto    count_m1        ;Jump to save check
count_up11
        incf    digit_save,f    ;M1 + 1
        goto    count_m1        ;Jump to save check

change2
        movlw   d'1'            ;Set check data
        subwf   change_st,w     ;Status - check data
        btfss   status,z        ;Status = "1" ?
        goto    change4         ;No. Next
        movf    change_wk,w     ;Read RB4/RB5 condition
        xorlw   b'00010000'     ;Check RB4/RB5 condition
        btfss   status,z        ;RB5(B)=0 RB4(A)=1 ?
        goto    change3         ;No. next
        clrf    change_st       ;Set status to "0"
        goto    int_end         ;Jump to END of interrupt
change3
        movf    change_wk,w     ;Read RB4/RB5 condition
        xorlw   b'00110000'     ;Check RB4/RB5 condition
        btfss   status,z        ;RB5(B)=1 RB4(A)=1 ?
        goto    int_end         ;Jump to END of interrupt

;*** Count down process
        movlw   d'2'            ;Set status to "2"
        movwf   change_st       ;Write status
        movf    digit_posi,w    ;Read digit position
        movwf   digit_posiw     ;Save digit position
        btfss   status,z        ;Position = H10 ?
        goto    count_down2     ;No. Next

        movf    digit_save,w    ;Read H10
        btfss   status,z        ;H10 = 0 ?
        goto    count_down1     ;No.
        movlw   d'3'            ;Set data
        movwf   digit_save      ;Set H10 = 3
        goto    count_h10       ;Jump to save check
count_down1
        decf    digit_save,f    ;H10 - 1
        goto    count_h10       ;Jump to save check

count_down2
        decfsz  digit_posiw,f   ;Position = H1 ?
        goto    count_down9     ;No. Next

        movf    disp_h10,w      ;Read H10 digit
        andlw   b'00000001'     ;Pick up 0x/1x
        btfss   status,z        ;H10 = AM 0x or PM 0x ?
        goto    count_down4     ;No. AM 1x or PM 1x
        movf    digit_save,w    ;Read H1
        btfss   status,z        ;H1 = 0 ?
        goto    count_down3     ;No.
        movlw   d'9'            ;Set data
        movwf   digit_save      ;Set H1 = 9
        goto    count_h1        ;Jump to save check
count_down3
        decf    digit_save,f    ;H1 - 1
        goto    count_h1        ;Jump to save check
count_down4
        movf    disp_h10,w      ;Read H10 digit
        andlw   b'00000010'     ;Pick up AM/PM
        btfss   status,z        ;H10 = AM ?
        goto    count_down6     ;No. PM
        movf    digit_save,w    ;Read H1 digit
        btfss   status,z        ;H1 = 0 ?
        goto    count_down5     ;No. H1 = 1
        incf    digit_save,f    ;H1 = 1
        goto    count_h1        ;Jump to save check
count_down5
        clrf    digit_save      ;H1 = 0
        goto    count_h1        ;Jump to save check
count_down6
        movlw   d'3'            ;Set check data
        subwf   digit_save,w    ;H1 - check data
        btfsc   status,c        ;H1 >= 3 ?
        goto    count_down7     ;Yes.
        movf    digit_save,w    ;read H1
        btfss   status,z        ;H1 = 0 ?
        goto    count_down8     ;No.
count_down7
        movlw   d'2'            ;Set data
        movwf   digit_save      ;Set H1 = 2
        goto    count_h1        ;Jump to save check
count_down8
        decf    digit_save,f    ;H1 - 1
        goto    count_h1        ;Jump to save check

count_down9
        decfsz  digit_posiw,f   ;Position = M10 ?
        goto    count_down11    ;No. Next

        movf    digit_save,w    ;Read M10
        btfss   status,z        ;M10 = 0 ?
        goto    count_down10    ;No.
        movlw   d'5'            ;Set data
        movwf   digit_save      ;Set M10 = 5
        goto    count_m10       ;Jump to save check
count_down10
        decf    digit_save,f    ;M10 - 1
        goto    count_m10       ;Jump to save check

count_down11
        movf    digit_save,w    ;Read M1
        btfss   status,z        ;M1 = 0 ?
        goto    count_down12    ;No.
        movlw   d'9'            ;Set data
        movwf   digit_save      ;Set M1 = 9
        goto    count_m1        ;Jump to save check
count_down12
        decf    digit_save,f    ;M1 - 1
        goto    count_m1        ;Jump to save check

count_h10
        movf    blink_cont,w    ;Read blink control data
        btfss   status,z        ;Blink ON ?
        goto    int_end         ;Jump to END of interrupt
        movf    digit_save,w    ;Yes. Read H10 data
        movwf   disp_h10        ;Set H10 data
        goto    int_end         ;Jump to END of interrupt

count_h1
        movf    blink_cont,w    ;Read blink control data
        btfss   status,z        ;Blink ON ?
        goto    int_end         ;Jump to END of interrupt
        movf    digit_save,w    ;Yes. Read H1 data
        movwf   disp_h1         ;Set H1 data
        goto    int_end         ;Jump to END of interrupt

count_m10
        movf    blink_cont,w    ;Read blink control data
        btfss   status,z        ;Blink ON ?
        goto    int_end         ;Jump to END of interrupt
        movf    digit_save,w    ;Yes. Read M10 data
        movwf   disp_m10        ;Set M10 data
        goto    int_end         ;Jump to END of interrupt

count_m1
        movf    blink_cont,w    ;Read blink control data
        btfss   status,z        ;Blink ON ?
        goto    int_end         ;Jump to END of interrupt
        movf    digit_save,w    ;Yes. Read M1 data
        movwf   disp_m1         ;Set M1 data
        goto    int_end         ;Jump to END of interrupt

change4
        movf    change_wk,w     ;Read RB4/RB5 condition
        xorlw   b'00000000'     ;Check RB4/RB5 condition
        btfss   status,z        ;RB5(B)=0 RB4(A)=0 ?
        goto    int_end         ;No. END of interrupt
        clrf    change_st       ;Yes. Set status to "0"
        goto    int_end         ;Jump to END of interrupt

;********************************************************
;                 END of Digital Clock
;********************************************************

        end

clock_source.zip
clock_hex.zip