-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path60LED_CLOCK1.ASM
More file actions
3192 lines (2758 loc) · 83.8 KB
/
60LED_CLOCK1.ASM
File metadata and controls
3192 lines (2758 loc) · 83.8 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
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
;_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
;
; 60LED_CLOCK1.ASM
;
;
;--------------------------------------------------------------------------------
;
; KD6VKF WWVB time data Decoder
;
; (c)2012 Steve Botts
; Based on wwvb162.asm by , Mike Berg aka N0QBH 4/11/11
; Modified: 10/22/12 for WWVB RTC Receiver project
;--------------------------------------------------------------------------------
;PURPOSE:
;
;
; Decodes WWVB time data and sisplays on 7-SEG and 60 LEDs
; This is for the "PIC Clock 360" Hardware.
; http://www.pictronicsonline.com/Clock360WWVB/Description.htm
;
; i2c = DS1307 (PFC8583p - IC2)
; SPI = LED 7-SEG DECODER CHIP (MAX7219 - IC8)
; SPI = LED OUTPUT PORTS (MCP23S17SP x4 IC$, IC5, IC6 and IC7)
; INPUT = WWVB RTC Module CMRR-6P TIME CODE OUT (SV3- TCO)
; OUTPUTS(2) = BUZZER and RELAY Outputs
; Temp sensor is a DS
;
; LCD LAYOUT #1:
;_______________________________________
; POS = 0 1 2 3 4 5 6 7 8 9 A B C D E F
; LINE1 H H : m m : s s _ + T Z d _ _ *
; LINE2 D D / M M / Y Y _ _ S 9 ! _ 0 0
; LINE2 1 2 3 4 5 6 7 8 9 0 S 9 # P C C
;_______________________________________
;
; LCD LAYOUT #1a:
;_______________________________________
; POS = 0 1 2 3 4 5 6 7 8 9 A B C D E F
; LINE1 H H : m m : s s + Z U T C ! d *
; LINE2 D D / M M / Y Y _ _ S 9 9 _ 0 0
; LINE2 1 2 3 4 5 6 7 8 9 0 S 9 9 P C C
;_______________________________________
;
;
; Revision History:
;
;
;
;_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
LIST P=16F886
ERRORLEVEL -302 ;Ignore Message [302] : Register in operand not in bank 0. Ensure that bank bits are correct.
ERRORLEVEL -202 ;Ignore Warning [202]: Argument out of range. Least significant bits used.
ERRORLEVEL -305 ;Ignore Warning [305]: Using default destination of 1 (file).
; radix hex
include <P16F886.INC> ;PIC Chip Include File
;Program Configuration Register 1
__CONFIG _CONFIG1, _INTOSCIO & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOR_OFF & _IESO_OFF & _FCMEN_OFF & _DEBUG_OFF & _LVP_OFF
;Note, Watch Dog timer can be turned on later in program with SWDTEN bit in WDTCON register
;Program Configuration Register 2
__CONFIG _CONFIG2, _BOR21V & _WRT_OFF
;============================== VECTORS ===============================
;CODE START VECTOR
ORG 0 ; start of main loop code
nop
goto main
;INTERRUPT VECTOR
ORG 4 ;Interrupt routine code
goto int_service
;============================== VARIABLE DEFINITIONS ===============================
w_temp EQU 0x7D ; variable used for context saving
status_temp EQU 0x7E ; variable used for context saving
pclath_temp EQU 0x7F ; variable used for context saving
;------------------------------------------------------------
cblock 0x20 ;(ADD)
;------------------------------------------------------------
; Misc
temp ;(20h) General Temp storage
count ;(21h) General counter
; PW Discriminator
mS ;(22h)
pw_mS ;(23h)
sort_temp ;(24h)
p_count ;(25h)
buffer ;(26h)
; WWVB FRAMES
frame_0 ;(27h)
frame_1 ;(28h)
frame_2 ;(29h)
frame_3 ;(2Ah)
frame_4 ;(2Bh)
frame_5 ;(2Ch)
; WWVB RESULTS
data_byte0 ;(2D)results
data_byte1 ;(2E)
data_byte2 ;(2F)
data_byte3 ;(30h)
data_byte4 ;(31)
data_byte5 ;(32)
; 100 per second counter
hund_per_sec ;(33)
; Time Zone
offset_tz ;(34) timezone
TimeZone ;(35) LCD DISPLAY TZ INDEX
; SIGNAL QUALITY
; Signal Strength = 0 -> 99
signal ;(36)
; Sync Counter
s_count ;(37)
; LCD DISPLAY
lcd_data ;(38) LCD display data
lcd_count ;(39)
; DELAY COUNTERS
delay_count ; (3A)delay routines
bit_count ; (3B)
; TIMEKEEPING STRORAGE
seconds ; (3C)
old_seconds ; (3D)
minutes ; (3E)
old_minutes ; (3F)
hours ; (40h)
old_hours ;(41)
day ;(42)
month ;(43)
wwvb_minutes ;(44)
wwvb_hours ;(45)
wwvb_days_hi ;(46)
wwvb_days_lo ;(47)
wwvb_year ;(48)
;Hex-decimal conversion HEX
hex_hi ; (49h) H
hex_lo ; (4a) L
;Hex-decimal conversion DEC
thousands ; (4b) DEC 1000's
hundreds ; (4c) DEC 100's
tens ; (4d DEC 10's
ones ; (4e) 1's
;stores/reads EE timezone offset
ee_addr ; (4f)
ee_data ; (50h)
;program FLAGS
FLAGS ; (51)
FLAGS2 ; (52)
;Interrupt Register storage
ampm ; (53) int routine
temp_S ; (54h)
;I2C storage Registers
BitCount ;bit index (55h)
OutByte ;(56H) Data to be transmitted should be put in this register before Transmit is called
InByte ;(57h) Data received is left in this register following the Receive call
;DS1307 Temp Storage
Day10 ;(58h)
Day1 ;(59)
Hour10 ;(5A)
Hour1 ;(5B)
Min10 ;(5C)
Min1 ;(5D)
Month10 ;(5E)
Month1 ;(5F)
Year10 ;(60)
Year1 ;(61)
DoW ;(62) Day of week
;SPI Temp Storage
spi_data ;(63) SPI DATA
spi_count ;(64) SPI CLOCK
;LED STORAGE
SecADD ;(65)
SecPORT ;(66)
SecDATA ;(67)
DATA2B ;(68)
DATA3A ;(69)
DATA3B ;(6A)
LED_bits ;(6B)
ShiftCNT ;(6C)
COMAND ;(6D)
COUNT1 ;(6E)
DATCOM ;(6F)
endc
;
;============================== CONSTANTS ===============================
;
;LCD
LINE_1 equ 0x80 ;LCD LINE #1 START address
LINE_2 equ 0xC0 ;LCD LINE #2 START address
;DELAY LOOP COUNTERS
US_60 equ .195 ;60 uS
US_125 equ .130 ;125 uS
MS_5 equ .20 ;5 mS
MS_15 equ .60 ;15 mS
MS_60 equ .240 ;60 mS
;TIMING
HUNDTH_SEC equ .5000 ;(2uS per count)+70(tweak)
ONESEC equ .100 ;1 second
HALFSEC equ .50 ;500mS
;ASCII CHARS
CR equ 0x0d ;carriage return
LF equ 0x0a ;linefeed
REQ_CHAR equ CR ;
; WWVB DISCRIMINATOR PULSE WIDTHS
PULSE_0 equ .20 ;0
PULSE_1 equ .50 ;1
PULSE_P equ .80 ;P
LAST_P equ .60 ;end of p count
;=================== MAX7219CNG =====================
;
; 7 SEG DISPLAY CHIP CONSTANTS
;
;====================================================
;7219 REGISTER ADDRESSES
;15 14 13 12 11 10 09 08
DIG0 equ 0x01 ;x x x x 0 0 0 1
DIG1 equ 0x02 ;x x x x 0 0 1 0
DIG2 equ 0x03 ;x x x x 0 0 1 1
DIG3 equ 0x04 ;x x x x 0 1 0 0
DIG7 equ 0x08 ;x x x x 1 0 0 0
DEC_MODE equ 0x09 ;x x x x 1 0 0 1
INTENSITY equ 0x0A ;x x x x 1 0 1 0
SCAN_LIMT equ 0x0B ;x x x x 1 0 1 1
SHUTDOWN equ 0x0C ;x x x x 1 1 0 0 (BIT1 = 0 FOR NORMAL OP)
DISP_TST equ 0x0F ;x x x x 1 1 1 1
;7219 REGISTER DATA
;D7 D6 D5 D4 D3 D2 D1 D0
ALL_CODE_B equ 0x0FF ;1 1 1 1 1 1 1 1 (ALL BITS ARE SEVEN SEG DECODES)
MIN_INTEN equ 0x01 ;x x x x 0 0 0 1 (PWM = 3/32 or 2/16)
MAX_INTEN equ 0x0F ;x x x x 1 1 1 1 (PWM = 31/32 or 15/16)
SCAN3 equ 0x03 ;x x x x 0 0 1 1 (SCANS DIGITS 0, 1, 2, 3 ONLY)
;CODE-B TABLE
;
; REGISTER DATA= 7-SEGMENT CHARACTER=
; =============== ==================
;
; *7 6 5 4 3 2 1 0 DP* A B C D E F G (ON SEGMENTS = 1)
; -- - - - - - - - -- - - - - - - -
;0 *x X X X 0 0 0 0 X 1 1 1 1 1 1 0
;1 *x X X X 0 0 0 1 X 0 1 1 0 0 0 0
;2 *x X X X 0 0 1 0 X 1 1 0 1 1 0 1
;3 *x X X X 0 0 1 1 X 1 1 1 1 0 0 1
;4 *x X X X 0 1 0 0 X 0 1 1 0 0 1 1
;5 *x X X X 0 1 0 1 X 1 0 1 1 0 1 1
;6 *x X X X 0 1 1 0 X 1 0 1 1 1 1 1
;7 *x X X X 0 1 1 1 X 1 1 1 0 0 0 0
;8 *x X X X 1 0 0 0 X 1 1 1 1 1 1 1
;9 *x X X X 1 0 0 1 X 1 1 1 1 0 1 1
;— *x X X X 1 0 1 0 X 0 0 0 0 0 0 1 (dash)
;E *x X X X 1 0 1 1 X 1 0 0 1 1 1 1
;H *x X X X 1 1 0 0 X 0 1 1 0 1 1 1
;L *x X X X 1 1 0 1 X 0 0 0 1 1 1 0
;P *x X X X 1 1 1 0 X 1 1 0 0 1 1 1
;_ *x X X X 1 1 1 1 X 0 0 0 0 0 0 0 (blank)
;
;D7* = DP
;
;=================== MCP23S17SP =====================
;
; LED 60 SECOND & STATUS LED DISPLAYS
;
;====================================================
;
;ACCEESS: BANK=1 BANK=0**
;IODIRA 0X00 0X00
;IODIRB 0X10 0X01
;IOCON1 0X05 0X0A
;IOCON2 0X15 0X0B
;GPIOA 0X09 0X12
;GPIOB 0X19 0X13
;OLATA 0X15 0X14
;OLATB 0X1A 0X15
; ** USED IN 360CLOCK
LED_IC4 equ 0x40 ;IC4 (LED3 - LED19)= 1SEC -> 15SEC
LED_IC5 equ 0x42 ;IC5 (LED20 - LED35)= 16SEC -> 31SEC
LED_IC6 equ 0x44 ;IC6 (LED36 - LED51)= 32SEC -> 47SEC
LED_IC7 equ 0x46 ;IC7 (LED52 - LED63) = 48SEC -> 59SEC
LED_66 equ 0x46 ;IC7 LED66 = 0SEC GPB6 (01000000)
;============================== MACROS ===============================
;Macros to select the register bank
;Many bank changes can be optimized when only one STATUS bit changes
Bank0 MACRO ;macro to select register bank 0
bcf STATUS,RP0
bcf STATUS,RP1
ENDM
Bank1 MACRO ;macro to select register bank 1
bsf STATUS,RP0
bcf STATUS,RP1
ENDM
Bank2 MACRO ;macro to select register bank 2
bcf STATUS,RP0
bsf STATUS,RP1
ENDM
Bank3 MACRO ;macro to select register bank 3
bsf STATUS,RP0
bsf STATUS,RP1
ENDM
;============================== HARDWARE ===============================
;
; Notes: These are all changed on the latest board for the LED Chip.
; (RA0 - RA5 were the old LED CATHODE SEGMENTS Not connected in this version)
; LCD is wired to these unused pins for testing...
;
;==========================PORT A=======================================
; REG - (Pin) [LABEL] (pin) |I/O
;=================================================================
; RA0 - (2)[LCD_DB4] (11) |output
; RA1 - (3)[LCD_DB5] (12) |output
; RA2 - (4)[LCD_DB6] (13) |output
; RA3 - (5)[LCD_DB7] (14) |output
; RA4 - (6)[LCD_E] (6) |output
; RA5 - (7)[LCD_RS] (4) |output
; RA6 - (10)[CS_] 23S17(9) |output
; RA7 - (9)[CLKI] (n.c.) |output N.C.
#define LCD_DB4 PORTA,0 ;LCD DAT |0
#define LCD_DB5 PORTA,1 ;LCD DAT |0
#define LCD_DB6 PORTA,2 ;LCD DAT |0
#define LCD_DB7 PORTA,3 ;LCD DAT |0
#define E_LINE PORTA,4 ;LCD E |0
#define RS_LINE PORTA,5 ;LCD RS |0
#define CS_ PORTA,6 ;P23S17SP(9)|0
#define pin9 PORTA,7 ;N.C. CLKI |0
; PORTA=b'0000 0000'
;==========================PORT B=======================================
; REG - (Pin) [LABEL] SIGNAL |I/O
;=================================================================
; RB0 - (21) [SCL] I2C Clock |output
; RB1 - (22) [SDA] I2C Data |in/out
; RB2 - (23) [TEMP] DS18B20 |1-Wire?
; RB3 - (24) [TCO] WWVB TIME CODE |input
; RB4 - (25) [SEL_SW] Switch(S5) |input
; RB5 - (26) [LAP_SW] Switch(S4) |input
; RB6 - (27) [STA_SW] Switch(S3) |input
; RB7 - (28) [MOD_SW] Switch(S2) |input
;PORTB =b'1111 1100'
#define I2CSCL PORTB,0 ;I2C Clock |1 = hi Z
#define I2CSDA PORTB,1 ;I2C Data |1 = hi Z
#define DS1820 PORTB,2 ;TEMP INPUT |1
#define DATA_IN PORTB,3 ;WWVB CODE |1
#define SEL_SW PORTB,4 ;Switch(S5) |1
#define LAP_SW PORTB,5 ;Switch(S4) |1
#define STA_SW PORTB,6 ;Switch(S3) |1
#define MOD_SW PORTB,7 ;Switch(S3) |1
;
;==========================PORT C=======================================
; REG - (Pin) [LABEL] SIGNAL |I/O
;=================================================================
; RC0 - (11) [MCS-] CHIP SELECT (LOAD PIN 12) for MAX7219 |output
; RC1 - (12) [MSI ] DATA IN (DIN pin 1) for MAX7219 |output
; RC2 - (13) [BUZZER] |output
; RC3 - (14) [N/A] ?VUSB? |N.C.
; RC4 - (15) [MSCK] CLOCK IN (DIN pin 13) for MAX7219 |output
; RC5 - (16) [SCK] SPI Clock MCP23S17SP |output
; RC6 - (17) [RLY] Relay control bit |output
; RC7 - (18) [SI] SPI data for MCP23S17SP |output
; =b'00000000'
#define MCS PORTC,0 ;CHIP SELECT for 7219 7-SEG
#define MSI PORTC,1 ;DATA IN for 7219 7-SEG
#define BUZZER PORTC,2 ;BUZZER
#define pin14 PORTC,3 ;N.C. VUSB
#define MSCK PORTC,4 ;SPI CLOCK for 7219 7-SEG
#define SCK PORTC,5 ;SPI CLOCK for MCP23S17
#define RLY PORTC,6 ;RELAY CONTROL
#define SI PORTC,7 ;SPI DATA for MCP23S17
;=============================OLD HARDWARE PINS:====================================
;
;#define SCL PORTA,4 ;I2C SCL
;#define SDA PORTA,5 ;I2C SDA
;#define CONFIG_SW PORTA,4 ;switch input
;#define Y_LED PORTB,0 ;LED YELLOW (6)
;#define RS_LINE PORTB,3 ;LCD RS
;============================== PROGRAM FLAGS: ===============================
;
#define BIT_FLAG FLAGS,0 ;data bit buffer
#define P_FLAG FLAGS,1 ;rxd P bit
#define D_FLAG FLAGS,2 ;good data set
#define ACT_FLAG FLAGS,3 ;pulse status
#define NEW_DATA FLAGS,4 ;new data available
#define SEC_FLAG FLAGS2,0 ;LCD update
#define SRX_FLAG FLAGS2,1 ;input change
#define LEAP_YR FLAGS2,2 ;leap year indicator
#define SIGN_FLAG FLAGS2,3 ;timezone +/-
#define G_LED FLAGS2,5 ;GREEN LED State
#define DST_WARN FLAGS2,6 ;1 = DST STARTS IN 24H, 0 = DST ENDS IN 24H
#define DST_NOW FLAGS2,7 ;1 = use DST
;============================== TIME FLAGS ==============================
;#define DST_NOW offset_tz,7 ;1 = use DST
;#define DST_WARN offset_tz,6 ;1 = DST STARTS IN 24H, 0 = DST ENDS IN 24H
#define tz_sign offset_tz,4 ;+/- sign flag
;
;============================== ASCII STRINGS ===============================
;
header_0
addwf PCL,F
dt " WWVB",0 ;5 char long
;---------------------------------------------------------------------------------------
;Daylight saving time (DST) and standard time (ST)
;information is transmitted at seconds57 and 58
;When ST is in effect, bits 57 and 58 are set to 0.
;When DST is in effect, bits 57 and 58 are set to 1.
;On the day of a change from ST to DST bit 57 changes from 0 to 1
;at 0000 UTC, and bit 58 changes from 0 to 1 exactly 24 hours later.
;
DST_
addwf PCL,F
dt " DST",0 ;4 char long
DST_START
;On the day of a change from ST to DST bit 57 changes from 0 to 1
;at 0000 UTC, and bit 58 changes from 0 to 1 exactly 24 hours later.
;
addwf PCL,F
dt " TONITE!",0 ;8 char long
DST_END
;On the day of a change from DST back to ST bit 57 changes from 1 to 0
;at 0000 UTC, and bit 58 changes from 1 to 0 exactly 24 hours later.
;
addwf PCL,F
dt " ENDING!",0 ;8 char long
;
LY
;A leap year indicator is transmitted at second 55. If it is set to 1, the current year is a
;leap year. The bit is set to 1 during each leap year after January 1 but before February 29.
;It is set back to 0 on January 1 of the year following the leap year.
addwf PCL,F
dt " LY = ",0 ;6 char long
;
LS
;A leap second indicator is transmitted at second 56. If this bit is high, it indicates that
;a leap second will be added to UTC at the end of the current month. The bit is set to
;1 near the start of the month in which a leap second is added. It is set to 0 immediately
;after the leap second insertion.
addwf PCL,F
dt " LS = ",0 ;6 char long
;
char_TRUE
addwf PCL,F
dt "TRUE ",0 ;5 char long
;
char_FALSE
addwf PCL,F
dt "FALSE",0 ;5 char long
;TIME ZONES
header_tz
addwf PCL,F
dt "ZONE= ",0 ;6 char long
UTC
addwf PCL,F
dt " UTC",0 ;4 char long
EST
addwf PCL,F
dt " EST",0 ;4 char long
CST
addwf PCL,F
dt " CST",0 ;4 char long
MST
addwf PCL,F
dt " MST",0 ;4 char long
PST
addwf PCL,F
dt " PST",0 ;4 char long
;
;========================== TABLES ===============================
;
monthly
addwf PCL,F
dt 0,.31,.28,.31,.30,.31,.30 ;
dt .31,.31,.30,.31,.30,.31 ;
;
frame_check
addwf PCL,F
dt 2,2,0,0,0,1,0,0,0,0 ; P0
dt 2,0,0,0,0,1,0,0,0,0 ; P1
dt 2,0,0,0,0,1,0,0,0,0 ; P2
dt 2,0,0,0,0,1,0,0,0,0 ; P3
dt 2,0,0,0,0,1,0,0,0,0 ; P4
dt 2,0,0,0,0,1,0,0,0,0 ; P5
;
;======================= MAIN CODE ===================================
main
;------------------------------------------------------------
; Microcontroller initialization
;------------------------------------------------------------
banksel OSCCON
;------------------------------------------------------------
;NOTE:
; This may not be needed - if using the default clock speed
;
; movlw b'01110000' ;8MHZ
; movlw b'01100001' ;4MHZ (default)+ SCS = 61
; movwf OSCCON
bsf OSCCON,SCS ;switch on internal clock
nop
nop
clock_start
btfss OSCCON,HTS ;HFINTOSC stable?
goto main ;no, try again
;------------------------------------------------------------
;Set System Clock speed
;CONFIG1 Set:
;101 = INTOSC oscillator: CLKOUT function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
;100 = INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN
;The HFINTOSC is enabled by selecting any frequency
;between 8 MHz and 125 kHz by setting the IRCF<2:0>
;bits of the OSCCON register ? 000.
;Then, set the ;System Clock Source (SCS) bit of the OSCCON register to ‘1’
;The HF Internal Oscillator (HTS) bit of the OSCCON
;register indicates whether the HFINTOSC is stable or not.
;------------------------------------------------------------
; Bank0 ;Config Ports in Bank 0
;------------------------------------------------------------
; I/O Port Set-up
;------------------------------------------------------------
banksel ANSELH ; select correct bank
clrf ANSELH ; all PORTB pins digital, not analogue
banksel ANSEL ; select correct bank
clrf ANSEL ;set PORT A for digital I/O
banksel OPTION_REG
bcf OPTION_REG,NOT_RBPU
;
; banksel PORTB ; select correct bank
; clrf PORTB ; all PORTB outputs low (if set output)
banksel PORTC ; select correct bank
clrf PORTC
banksel PORTA ; select bank 0 as default bank
clrf PORTA
; Bank1 ;Now config bank 1 regs
; bsf STATUS,RP0 ;switch to bank 1
;------------------------------------------------------------
; BIT 7 6 5 4 3 2 1 0
; DIR OUT OUT OUT IN 0UT OUT OUT OUT
; PORTA 0 0 0 1 0 0 0 0
;------------------------------------------------------------
movlw b'00000000' ;port A in/outputs
banksel TRISA ; select correct bank
movwf TRISA
;------------------------------------------------------------
; BIT 7 6 5 4 3 2 1 0
; DIR OUT OUT OUT OUT IN SW SW SW
; PORTB 0 0 0 0 1 1 1 1
;------------------------------------------------------------
movlw b'11111111' ;port B ALL intputs
banksel TRISB ; select correct bank
movwf TRISB
banksel WPUB ;enable weak pullups on PORTB
movlw b'11111111' ;port B 1= enabled 0= disabled
movwf WPUB ;just in case
;------------------------------------------------------------
; BIT 7 6 5 4 3 2 1 0
; DIR OUT OUT OUT OUT 0UT OUT OUT OUT
; PORTC 0 0 0 0 0 0 0 0
;------------------------------------------------------------
movlw b'00000000' ;port C in/outputs
banksel TRISC ; select correct bank
movwf TRISC
;Make sure to turn off interrupts for the rest of the config
banksel INTCON ; select correct bank
bcf INTCON,GIE ;global ints off
btfsc INTCON,GIE
goto $-2 ;wait for it...
;TMR1 INT
;To enable the interrupt on rollover, you must set
;these bits:
; Timer1 interrupt enable bit of the PIE1 register
; PEIE bit of the INTCON register
; GIE bit of the INTCON register
;The interrupt is cleared by clearing the TMR1IF bit in
;the Interrupt Service Routine
;PIR1 Timer perif interrupt
;bit 0 TMR1IF: Timer1 Overflow Interrupt Flag bit
;1 = The TMR1 register overflowed (must be cleared in software)
;0 = The TMR1 register did not overflow
clrf PIR1 ;reset perif interrups
movlw b'00000100' ;post/1, pre/1, on
movwf T2CON ;timer 2
;TIMER1 CONTROL REGISTER
; T1CON:
; bit 7 = T1GINV: 0
; bit6 = TMR1GE: 0
; bit 5-4 T1CKPS<1:0>: Timer1 Input Clock Prescale Select bits
; 11 = 1:8 Prescale Value
; 10 = 1:4 Prescale Value
; 01 = 1:2 Prescale Value *USE*?
; 00 = 1:1 Prescale Value
; bit 3 = T1OSCEN: 0
; bit2 T1SYNC:0 (bit is ignored if TMR1CS = 0)
; bit1 TMR1ON: Timer1 On bit (1 = 0n 0 = off)
;TMR1CS = 0 (fosc/4)
;TMR1ON = 1 T1 Gate should be disabled -> TMR1GE = 0
;TMR1IF = 1 when TMR1H TMR1L overflow
banksel T1CON
movlw b'00010000' ;T1/2
movwf T1CON ;timer 1 setup
;
;INTCON ( FOR TMR1)
; BIT7 GIE = 1 TO ENABLE GLOBAL INTERRUPTS
; BIT6 PEIE = 1 PERIF INTERRUPT ENABLE
;Timer PEIE on we can do this later (BIT 6 = 1)
banksel INTCON
movlw b'01000000' ;PEIE on
movwf INTCON
;silence the buzzer
Bank0 ;Now - back to page 0
bsf BUZZER ;make sure the buzzer is OFF!
call clear_regs ;clear out the c-block F registers
;let the LCD settle form power up a little before init
call Delay100
call LCD_Init ;set up LCD display
call Delay255
;===================== LCD TEST ==============================
goto start1
movlw 6 ;test line 2 + Col in W
call LCD_Line2W
call Delay100
movlw 'H' ;
call LCD_Char
movlw 'e' ;
call LCD_Char
movlw 'l' ;
call LCD_Char
movlw 'p' ;
call LCD_Char
call LCD_Line1
movlw 'S' ;
call LCD_Char
; call Delay255
movlw 'e' ;
call LCD_Char
; call Delay255
movlw 'n' ;
call LCD_Char
; call Delay255
movlw 'd' ;
call LCD_Char
;===================== LCD TEST MESSAGES ==============================
start1 ;jump here to skip
;===================TESTING 7 SEGMENT DISPLAY CHIP=====================
call INIT_SEGMENTS ;sets up 7219
movlw 0x0A ;Set the LED INTENSITY
call SET_INTENSITY
; call I2CInit
;============TEST STUFF 'HELP'=======================================
movlw 0x0C ;H *x X X X 1 1 0 0 X 0 1 1 0 1 1 1
movwf Hour10 ;TENS
movlw 0x0B ;E *x X X X 1 0 1 1 X 1 0 0 1 1 1 1
movwf Hour1 ;ONES
movlw 0x0D ;L *x X X X 1 1 0 1 X 0 0 0 1 1 1 0
movwf Min10 ;TENS
movlw 0x0E ;P *x X X X 1 1 1 0 X 1 1 0 0 1 1 1
movwf Min1 ;ONES
;============TEST STUFF 'HELP'=======================================
movlw 0x59 ; set up the minutes registers;
movwf Min1
movlw 0x23 ; set up the hours registers
movwf Hour1
; call GetRTC_TIME ;DS1307 +I2C test
; movfw wwvb_minutes ;(44)
; movwf Min1
; movfw wwvb_hours ;(45)
; movwf Hour1
movfw Min1
andlw b'01110000' ; get raw - mask 10's digit
movwf Min10 ; put it in 10's digit register
swapf Min10, F ; swap nibbles
movlw b'00001111' ; mask raw for 1's digit
andwf Min1
movfw Hour1
andlw b'00110000' ; get raw - mask 10's digit
movwf Hour10 ; put it in 10's digit register
swapf Hour10, F ; swap nibbles
movlw b'00001111' ; mask raw for 1's digit
andwf Hour1
; call GetRTC_TIME
; call SEGMENT_TIME ;tests it now as 23:59
; goto $-1
;The LEDs were wired active low set the bits hi for off..
; bsf R_LED ;turn off RED LED
; bsf Y_LED ;turn off YELLOW LED
; bsf G_LED ;turn off GREEN LED
; call clear_regs
Bank0
;pre-load counters
movlw .100
movwf old_seconds
movwf old_minutes
movwf old_hours ;insure immediate update
movlw ONESEC
movwf hund_per_sec ;preload .01 sec counter
clrf signal ;reset signal counter to S0
;some tests we can put here for now...and delete later
; call do_rx_indicate ;TEST Show RSSI (0-99)
; call GetRTC_TIME ;TEST update the display
; call SEGMENT_TIME ;TEST 7-SEGMENT displays
;turn on interrupts
; PEIE bit of the INTCON register
; GIE bit of the INTCON register
banksel INTCON
bsf INTCON,GIE ;General ints on
bsf INTCON,PEIE ;ints on
banksel PIE1
bsf PIE1,TMR1IE ;timer1 int on
;turn on timer1
banksel T1CON
bsf T1CON,TMR1ON ;timer1 on
;=====================CLEAR LEDS ===================================
call MCP23S17Init ;initialize the LED PORTS
call CLEAR_LEDS ;make sure all second LEDs are off
bsf G_LED ;Set to turn off GREEN LED
; goto load_tz_default ; Skip switch test for now
;
;======================= TIME ZONE SET ================================
;
; Set up to configure TZ or run normally?
; btfss CONFIG_SW ;test power up button pushed
;if switch is closed do configure
; goto load_tz_default ; Skip switch test for now
; goto tz_config ;do configure
;
;========================== CONFIGURE TZ WITH THE NV ================================
;
;else get the stored TZ values from EE ROM...
;
; clrf ee_addr ;get stored value
; call ee_read ;
; movfw ee_data ;
; andlw b'00001111' ;lower nibble
; sublw .12 ;
; bnc load_tz_default ;Default will be UTC (Z)
; movfw ee_data ;
; andlw b'00011111' ;
; movwf offset_tz ;load value
;
;============================= DONE TZ FROM NV ======================================
;
; goto wait_new_pulse ; All done! Go to main loop and let the ISR do the rest
;
;====================== CONFIGURE TZ WITH THE DEFAULT ===============================
;
;Unless we skipped it... then we use UTC for DEFAULT w/ no offsets
load_tz_default
Bank0
clrf offset_tz ; default = UTC -0
movlw 8
movwf TimeZone
movwf offset_tz
bcf DST_NOW ;Use (ST)
bcf DST_WARN ;Clear DST change bit
goto wait_new_pulse ; Finally...DONE. go to main loop.
;
;======================= TZ CONFIG CODE ===================================
;
; This ia all going to change... WWVB is not even avalible outside US
; Unless UTC is used no reason for 23 other timesones!!!
; Loop will be UTC -> EST -> CST -> MST -> PST
; two other parameter will be also configured:
; 1. Use DST? = TRUE/FALSE
; So if selected and DST is in effect
; then, the displayed "S" will be repaced by "D"
; UTC does not use DST so it defaults to FALSE.
; 2. Day of Week (DOW)setting SUN, MON, TUE, WED, THU, FRI, SAT
;--------------------------------------------------------------------------
;tz_config
; clrf lcd_count ;clear pointer
; movlw LINE_1 ;1st position
; call LCD_CONT ;
;tz_loop0
; movfw lcd_count
; call header_tz ;display "Offset"
; movwf lcd_data
; movfw lcd_data ;test for zero
; bz tz_loop2 ;leave if 0 is returned
; call LCD_DAT
; incf lcd_count,F
; goto tz_loop0
;tz_loop2
; movlw LINE_1 +8 ;2nd 1/2
; call LCD_CONT ;display
; clrf lcd_count ;will be counter
; bcf SEC_FLAG
;get_syncd
; btfss SEC_FLAG
; goto get_syncd ;wait for edge
; bcf SEC_FLAG
;
;tz_loop1
; movlw LINE_1 +8 ;2nd 1/2
; call LCD_CONT ;display
; movlw "+"
; btfss lcd_count,4 ;
; movlw "-"
; movwf lcd_data
; call LCD_DAT ;send sign
; movfw lcd_count
; andlw b'00001111' ;mask hi nibble
; movwf hex_lo
; clrf hex_hi
; call hd_convert ;display current
;
; movlw " "
; movwf lcd_data
; movfw tens
; xorlw "0" ;
; bz loop1_ones ;if 0, skip next
; movfw tens
; movwf lcd_data
;loop1_ones
; call LCD_DAT ;10's
; movfw ones
; movwf lcd_data
; call LCD_DAT ;1's
;input_scan
; btfsc CONFIG_SW ;toggle still low?
; goto store_current_value ;no
; btfss SEC_FLAG ;yes, sec flag hi yet?
; goto input_scan ;no
; bcf SEC_FLAG ;yes, clear
;
; incf lcd_count,W
; andlw b'00001111' ;
; xorlw .13
; bz swap_sign
; incf lcd_count,F
; goto tz_loop1 ;display new value
;
;swap_sign
; movlw .16
; addwf lcd_count,F ;inc hi nibble
; movlw b'00010000' ;mask all but bit 4
; andwf lcd_count,F
; goto tz_loop1 ;display new value
;
;store_current_value
; movfw lcd_count
; movwf offset_tz ;store in working reg
; clrf ee_addr
; movfw offset_tz
; movwf ee_data
; call ee_write ;store value & sign
;