-
Notifications
You must be signed in to change notification settings - Fork 0
/
port_def.jal
1094 lines (925 loc) · 36.9 KB
/
port_def.jal
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
-----------------------------
-- Refer to "pic_pin_map.txt"
-----------------------------
--------- Target definition
; PIC16F18313
if (target_chip == PIC_16F18313) Then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = false;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = false;
const bit HAVE_POWER_OFF_MODE = false; under construction
const bit PIN8_MCU = true
;if you set false(mono mode), it must be used 8bit mono wav file.
const bit CH_MODE_STEREO = false ;
; fs=44.1KHz
const byte SAMPLING_FREQ = byte( ((target_clock>>2)/44100) - 1 ) ; PR2=180
-- Enable pull-ups
;OPTION_REG_WPUEN = 0 ; enable global Weak Pull-up
WPUA_WPUA3 = 1 ; enable pull-up: btn
WPUA_WPUA2 = 1 ; enable pull-up: SDI
-- Port Slew rate control
SLRCONA = 0 ; set max slew rate
-- PPS setting
include pps
-- in
SSP1DATPPS = PPS_RA2 ; RA2:SDI
-- out
RA0PPS = PPS_SDO1 ; RA0:SDO1
RA1PPS = PPS_SCK1 ; RA1:SCK1
RA5PPS = PPS_CCP1 ; RA5:CCP1
;RA4PPS_RA4PPS = 0x00 ; RA4:CS (LATA4)
-- SPI definition (SD card interface)
alias pin_sdo_direction is pin_A0_direction
alias pin_sdo is pin_A0
alias pin_sdi_direction is pin_A2_direction
alias pin_sdi is pin_A2
alias pin_sck_direction is pin_A1_direction
alias pin_sck is pin_A1
--
alias sd_chip_select is pin_A4
alias sd_chip_select_direction is pin_A4_direction
-- btn sw definition
alias btn_bit_now is pin_A3
;PIC16F18313
-- PWM definition (audio out)
const bit PWM_DUTY_REG_LEFT_TYPE2 = true
const bit PWM_DUTY_REG_RIGHT_TYPE2 = true
CCP1CON = 0b1000_1111 ; set PWM enable and PWM mode.
CCPR1H = 0 ; clear higher register of duty in advance.
alias pwm_l_port_tris_bit is pin_A5_direction
pwm_l_port_tris_bit = OUTPUT; // ccp1 PWM(R) out
alias pwm_l_duty_lower_bits is CCPR1L
alias pwm_l_duty_upper_bits is CCPR1H
; PIC12F1840
elsif (target_chip == PIC_12F1840) Then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = false;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = false;
const bit HAVE_POWER_OFF_MODE = false; under construction
const bit PIN8_MCU = true
;if you set false(mono mode), it must be used 8bit mono wav file.
const bit CH_MODE_STEREO = false ;
; fs=44.1KHz
const byte SAMPLING_FREQ = byte( ((target_clock>>2)/44100) - 1 ) ; PR2=180
-- Enable pull-ups
OPTION_REG_WPUEN = 0 ; enable global Weak Pull-up
WPUA_WPUA3 = 1 ; enable pull-up: btn
WPUA_WPUA2 = 1 ; enable pull-up: SDI
-- SPI definition (SD card interface)
alias pin_sdo_direction is pin_A0_direction
alias pin_sdo is pin_A0
--
alias sd_chip_select is pin_A4
alias sd_chip_select_direction is pin_A4_direction
-- btn sw definition
alias btn_bit_now is pin_A3
; PIC12F1840
-- PWM definition (audio out)
APFCON_CCP1SEL = 1; // ccp1 is RA5
CCP1CON = 0b0000_1100
alias pwm_l_port_tris_bit is pin_A5_direction
pwm_l_port_tris_bit = OUTPUT; // ccp1 PWM(R) out
alias pwm_l_duty_lower_bits is CCP1CON_DC1B
alias pwm_l_duty_upper_bits is CCPR1L
; PIC16F1455
elsif (target_chip == PIC_16F1454) | (target_chip == PIC_16F1455) | (target_chip == PIC_16F1459) then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = true;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = true;
const bit HAVE_POWER_OFF_MODE = false; under construction
-- test mode
const bit PIC16F1455_TEST_MODE = false
;if you set false(mono mode), it must be used 8bit mono wav file.
const bit CH_MODE_STEREO = true ;
; fs=44.1KHz
T2CON_T2CKPS =0b01 ; Timre2 prescaler is 1/4
const byte SAMPLING_FREQ = byte( ((target_clock>>4)/44100) - 1 ) ; = 67
-- Enable pull-ups
OPTION_REG_WPUEN = 0 ; enable global Weak Pull-up
WPUA_WPUA3 = 1 ; enable pull-up: btn
-- Port Slew rate control
CLKRCON_CLKRSLR = 0 ; set max slew rate
-- UART definition
const serial_hw_baudrate = 115200 -- set the baudrate
alias UART_RX_ENABLE is RCSTA_CREN
if target_chip == PIC_16F1459 then
alias pin_TX is pin_B7
alias pin_TX_direction is pin_B7_direction
alias pin_RX is pin_B5
alias pin_RX_direction is pin_B5_direction
else
alias pin_TX is pin_C4
alias pin_TX_direction is pin_C4_direction
alias pin_RX is pin_A1
if !defined(pin_A1_direction) then ; bug fix for jallib of pic16f1455 at 2019/11/10.
var volatile bit TRISA_TRISA1 at TRISA : 1
alias pin_A1_direction is TRISA_TRISA1
end if
alias pin_RX_direction is pin_A1_direction
end if
-- LED indicator definition
if target_chip == PIC_16F1459 then
alias led is pin_C4
alias led_direction is pin_C4_direction
else
alias led is pin_A5
alias led_direction is pin_A5_direction
end if
-- btn sw definition
alias btn_bit_now is pin_A3
-- SPI definition (SD card interface)
const bit SPI_CLOCK_MORE_SLOW = true
if target_chip == PIC_16F1459 then
alias sd_chip_select is pin_C3
alias sd_chip_select_direction is pin_C3_direction
else
alias pin_sdo_direction is pin_C2_direction
alias pin_sdo is pin_C2
--
alias sd_chip_select is pin_A4
alias sd_chip_select_direction is pin_A4_direction
end if
;PIC16F1455 etc
-- PWM definition (audio out)
if PIC16F1455_TEST_MODE == false then
PWM1CON = 0b1100_0000
alias pwm_l_port_tris_bit is pin_C5_direction
pwm_l_port_tris_bit = OUTPUT; // ccp1 PWM(R) out
alias pwm_l_duty_lower_bits is PWM1DCL_PWM1DCL
alias pwm_l_duty_upper_bits is PWM1DCH
end if
PWM2CON = 0b1100_0000
if target_chip == PIC_16F1459 then
alias pwm_r_port_tris_bit is pin_C6_direction
else
alias pwm_r_port_tris_bit is pin_C3_direction
end if
pwm_r_port_tris_bit = OUTPUT; // ccp2 PWM(L) out
alias pwm_r_duty_lower_bits is PWM2DCL_PWM2DCL
alias pwm_r_duty_upper_bits is PWM2DCH
-- TEST PORT definition
; PIC16F1619
elsif (target_chip == PIC_16F1619) Then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = true;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = true;
const bit HAVE_POWER_OFF_MODE = false; under construction
;if you set false(mono mode), it must be used 8bit mono wav file.
const bit CH_MODE_STEREO = true ;
; fs=44.1KHz
const byte SAMPLING_FREQ = byte( ((target_clock>>2)/44100) - 1 ) ; PR2=180
-- Enable pull-ups
OPTION_REG_WPUEN = 0 ; enable global Weak Pull-up
WPUA_WPUA3 = 1 ; enable pull-up: btn
WPUB_WPUB4 = 1 ; enable pull-up: SDI
WPUB_WPUB5 = 1 ; enable pull-up: UART RX
--
const bit USE_CCPX = true ; use CCP1,CCP2 for PWM
-- Port Slew rate control
SLRCONA = 0 ; set max slew rate
-- PPS setting
include pps
-- in
SSPDATPPS = PPS_RB4; RB4:SDI
-- out
RC7PPS = PPS_SDO; RC7:SDO
RB6PPS = PPS_SCK; RB6:SCK
if USE_CCPX then
RC5PPS = PPS_CCP1; RC5:CCP1
RC3PPS = PPS_CCP2; RC3:CCP2
else
RC5PPS = PPS_PWM3OUT; RC5:PWM3
RC3PPS = PPS_PWM4OUT; RC3:PWM4
end if
if UART_INFO then
RXPPS = PPS_RB5; RB5:UART RX
RB7PPS = PPS_TX ; RB7:UART TX
end if
;RC6PPS = 0x00; RC6:CS (LATC6)
-- UART definition
const serial_hw_baudrate = 115200 -- set the baudrate
alias UART_RX_ENABLE is RCSTA_CREN
alias pin_TX is pin_B7
alias pin_TX_direction is pin_B7_direction
alias pin_RX is pin_B5
alias pin_RX_direction is pin_B5_direction
-- LED indicator definition
alias led is pin_C4
alias led_direction is pin_C4_direction
-- btn sw definition
alias btn_bit_now is pin_A3
-- SPI definition (SD card interface)
const bit SPI_CLOCK_MORE_SLOW = true
alias pin_sdo_direction is pin_C7_direction
alias pin_sdo is pin_C7
alias pin_sdi_direction is pin_B4_direction
alias pin_sdi is pin_B4
alias pin_sck_direction is pin_B6_direction
alias pin_sck is pin_B6
--
alias sd_chip_select is pin_C6
alias sd_chip_select_direction is pin_C6_direction
; PIC16F1619
-- PWM definition (audio out)
T2CLKCON_CS = 0b0000 ; Use FOSC/4 for Period timer
if USE_CCPX then
const bit PWM_DUTY_REG_LEFT_TYPE2 = true
const bit PWM_DUTY_REG_RIGHT_TYPE2 = true
CCP1CON = 0b1000_1100
CCPR1H = 0
alias pwm_l_port_tris_bit is pin_C5_direction
pwm_l_port_tris_bit = OUTPUT; // CCP1 PWM(R) out
alias pwm_l_duty_lower_bits is CCPR1L
alias pwm_l_duty_upper_bits is CCPR1H
CCP2CON = 0b1000_1100
CCPR2H = 0
alias pwm_r_port_tris_bit is pin_C3_direction
pwm_r_port_tris_bit = OUTPUT; // CCP2 PWM(L) out
alias pwm_r_duty_lower_bits is CCPR2L
alias pwm_r_duty_upper_bits is CCPR2H
else
PWM3CON = 0b1000_0000
alias pwm_l_port_tris_bit is pin_C5_direction
pwm_l_port_tris_bit = OUTPUT; // PWM3 PWM(R) out
alias pwm_l_duty_lower_bits is PWM3DCL_DC
alias pwm_l_duty_upper_bits is PWM3DCH
PWM4CON = 0b1000_0000
alias pwm_r_port_tris_bit is pin_C3_direction
pwm_r_port_tris_bit = OUTPUT; // PWM4 PWM(L) out
alias pwm_r_duty_lower_bits is PWM4DCL_DC
alias pwm_r_duty_upper_bits is PWM4DCH
end if
-- TEST PORT definition
alias test_port is pin_C1
alias test_port_direction is pin_C1_direction
; PIC16F1705
elsif (target_chip == PIC_16F1705) Then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = true;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = true;
const bit HAVE_POWER_OFF_MODE = false; under construction
-- test mode
const bit PIC16F1705_TEST_MODE = false
;if you set false(mono mode), it must be used 8bit mono wav file.
const bit CH_MODE_STEREO = true ;
; fs=44.1KHz
const byte SAMPLING_FREQ = byte( ((target_clock>>2)/44100) - 1 ) ; PR2=180
-- Enable pull-ups
OPTION_REG_WPUEN = 0 ; enable global Weak Pull-up
WPUA_WPUA3 = 1 ; enable pull-up: btn
WPUC_WPUC1 = 1 ; enable pull-up: SDI
if PIC16F1705_TEST_MODE then
WPUC_WPUC5 = 1 ; enable pull-up: UART RX
end if
-- Port Slew rate control
SLRCONA = 0 ; set max slew rate
-- PPS setting
include pps
-- in
SSPDATPPS = PPS_RC1; RC1:SDI
-- out
RC2PPS = PPS_SDO ; RC2:SDO
RC0PPS = PPS_SCK ; RC0:SCK
RC5PPS = PPS_CCP1 ; RC5:CCP1
RC3PPS = PPS_CCP2 ; RC3:CCP2
;RA4PPS_RA4PPS = 0x00 ; RA4:CS (LATA4)
-- UART definition
const serial_hw_baudrate = 115200 -- set the baudrate
alias UART_RX_ENABLE is RCSTA_CREN
alias pin_TX is pin_C4
alias pin_TX_direction is pin_C4_direction
alias pin_RX is pin_C5
alias pin_RX_direction is pin_C5_direction
-- LED indicator definition
alias led is pin_A5
alias led_direction is pin_A5_direction
-- btn sw definition
alias btn_bit_now is pin_A3
-- SPI definition (SD card interface)
const bit SPI_CLOCK_MORE_SLOW = true
alias pin_sdo_direction is pin_C2_direction
alias pin_sdo is pin_C2
alias pin_sdi_direction is pin_C1_direction
alias pin_sdi is pin_C1
alias pin_sck_direction is pin_C0_direction
alias pin_sck is pin_C0
--
alias sd_chip_select is pin_A4
alias sd_chip_select_direction is pin_A4_direction
; PIC16F1705
-- PWM definition (audio out)
if PIC16F1705_TEST_MODE == false then
CCP1CON = 0b0000_1100
alias pwm_l_port_tris_bit is pin_C5_direction
pwm_l_port_tris_bit = OUTPUT; // ccp1 PWM(R) out
alias pwm_l_duty_lower_bits is CCP1CON_DC1B
alias pwm_l_duty_upper_bits is CCPR1L
end if
CCP2CON = 0b0000_1100
alias pwm_r_port_tris_bit is pin_C3_direction
pwm_r_port_tris_bit = OUTPUT; // ccp2 PWM(L) out
alias pwm_r_duty_lower_bits is CCP2CON_DC2B
alias pwm_r_duty_upper_bits is CCPR2L
-- TEST PORT definition
alias test_port is pin_A2
alias test_port_direction is pin_A2_direction
; PIC16F1709
elsif (target_chip == PIC_16F1709) Then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = true;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = true;
const bit HAVE_POWER_OFF_MODE = false; under construction
;if you set false(mono mode), it must be used 8bit mono wav file.
const bit CH_MODE_STEREO = true ;
; fs=44.1KHz
const byte SAMPLING_FREQ = byte( ((target_clock>>2)/44100) - 1 ) ; PR2=180
-- Enable pull-ups
OPTION_REG_WPUEN = 0 ; enable global Weak Pull-up
WPUA_WPUA3 = 1 ; enable pull-up: btn
WPUB_WPUB4 = 1 ; enable pull-up: SDI
WPUB_WPUB5 = 1 ; enable pull-up: UART RX
-- Port Slew rate control
SLRCONA = 0 ; set max slew rate
-- PPS setting
include pps
-- in
SSPDATPPS = PPS_RB4; RB4:SDI
-- out
RC7PPS = PPS_SDO ; RC7:SDO
RB6PPS = PPS_SCK ; RB6:SCK
RC5PPS = PPS_CCP1 ; RC5:CCP1
RC3PPS = PPS_CCP2 ; RC3:CCP2
;RC6PPS_RC6PPS = 0x00 ; RC6:CS (LATC6)
if UART_INFO then
RXPPS = PPS_RB5; RB5:UART RX
RB7PPS = PPS_TX ; RB7:UART TX
end if
-- UART definition
const serial_hw_baudrate = 115200 -- set the baudrate
alias UART_RX_ENABLE is RCSTA_CREN
alias pin_TX is pin_B7
alias pin_TX_direction is pin_B7_direction
alias pin_RX is pin_B5
alias pin_RX_direction is pin_B5_direction
-- LED indicator definition
alias led is pin_C4
alias led_direction is pin_C4_direction
-- btn sw definition
alias btn_bit_now is pin_A3
-- SPI definition (SD card interface)
const bit SPI_CLOCK_MORE_SLOW = true
alias pin_sdo_direction is pin_C7_direction
alias pin_sdo is pin_C7
alias pin_sdi_direction is pin_B4_direction
alias pin_sdi is pin_B4
alias pin_sck_direction is pin_B6_direction
alias pin_sck is pin_B6
--
alias sd_chip_select is pin_C6
alias sd_chip_select_direction is pin_C6_direction
; PIC16F1709
-- PWM definition (audio out)
CCP1CON = 0b0000_1100
alias pwm_l_port_tris_bit is pin_C5_direction
pwm_l_port_tris_bit = OUTPUT; // ccp1 PWM(R) out
alias pwm_l_duty_lower_bits is CCP1CON_DC1B
alias pwm_l_duty_upper_bits is CCPR1L
CCP2CON = 0b0000_1100
alias pwm_r_port_tris_bit is pin_C3_direction
pwm_r_port_tris_bit = OUTPUT; // ccp2 PWM(L) out
alias pwm_r_duty_lower_bits is CCP2CON_DC2B
alias pwm_r_duty_upper_bits is CCPR2L
-- TEST PORT definition
alias test_port is pin_C1
alias test_port_direction is pin_C1_direction
; PIC16F1764
elsif (target_chip == PIC_16F1764) Then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = true;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = true;
const bit HAVE_POWER_OFF_MODE = false; under construction
-- test mode
const bit PIC16F1764_TEST_MODE = false
;if you set false(mono mode), it must be used 8bit mono wav file.
const bit CH_MODE_STEREO = true ;
; fs=44.1KHz
const byte SAMPLING_FREQ = byte( ((target_clock>>2)/44100) - 1 ) ; PR2=180
-- Enable pull-ups
OPTION_REG_WPUEN = 0 ; enable global Weak Pull-up
WPUA_WPUA3 = 1 ; enable pull-up: btn
WPUC_WPUC1 = 1 ; enable pull-up: SDI
if PIC16F1764_TEST_MODE then
WPUC_WPUC5 = 1 ; enable pull-up: UART RX
end if
-- Port Slew rate control
SLRCONA = 0 ; set max slew rate
-- PPS setting
include pps
-- in
SSPDATPPS = PPS_RC1; RC1:SDI
-- out
RC2PPS = PPS_SDO ; RC2:SDO
RC0PPS = PPS_SCK ; RC0:SCK
RC5PPS = PPS_CCP1 ; RC5:CCP1
RC3PPS = PPS_PWM3OUT ; RC3:PWM3
if PIC16F1764_TEST_MODE then
RXPPS = PPS_RC5 ; RC5:UART RX
RC4PPS = PPS_TX ; RC4:UART TX
end if
-- UART definition
const serial_hw_baudrate = 115200 -- set the baudrate
alias UART_RX_ENABLE is RCSTA_CREN
alias pin_TX is pin_C4
alias pin_TX_direction is pin_C4_direction
alias pin_RX is pin_C5
alias pin_RX_direction is pin_C5_direction
-- LED indicator definition
alias led is pin_A5
alias led_direction is pin_A5_direction
-- btn sw definition
alias btn_bit_now is pin_A3
-- SPI definition (SD card interface)
const bit SPI_CLOCK_MORE_SLOW = true
alias pin_sdo_direction is pin_C2_direction
alias pin_sdo is pin_C2
alias pin_sdi_direction is pin_C1_direction
alias pin_sdi is pin_C1
alias pin_sck_direction is pin_C0_direction
alias pin_sck is pin_C0
--
alias sd_chip_select is pin_A4
alias sd_chip_select_direction is pin_A4_direction
; PIC16F1764
-- PWM definition (audio out)
T2CLKCON_CS = 0b0001 ; Use FOSC/4 for Period timer
if PIC16F1764_TEST_MODE == false then
const bit PWM_DUTY_REG_LEFT_TYPE2 = true
CCP1CON = 0b1000_1100
CCPR1H = 0 ; clear higher register of duty in advance.
alias pwm_l_port_tris_bit is pin_C5_direction
pwm_l_port_tris_bit = OUTPUT; // ccp1 PWM(L) out
alias pwm_l_duty_lower_bits is CCPR1L
alias pwm_l_duty_upper_bits is CCPR1H
end if
PWM3CON = 0b1000_0000
alias pwm_r_port_tris_bit is pin_C3_direction
pwm_r_port_tris_bit = OUTPUT; // PWM3 PWM(R) out
alias pwm_r_duty_lower_bits is PWM3DCL_DC
alias pwm_r_duty_upper_bits is PWM3DCH
-- TEST PORT definition
alias test_port is pin_A2
alias test_port_direction is pin_A2_direction
; PIC16F1825
elsif (target_chip == PIC_16F1825) Then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = true;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = true;
const bit HAVE_POWER_OFF_MODE = false; under construction
-- test mode
const bit PIC16F1825_TEST_MODE = false
;if you set false(mono mode), it must be used 8bit mono wav file.
const bit CH_MODE_STEREO = true ;
; fs=44.1KHz
const byte SAMPLING_FREQ = byte( ((target_clock>>2)/44100) - 1 ) ; PR2=180
-- Enable pull-ups
OPTION_REG_WPUEN = 0 ; enable global Weak Pull-up
WPUA_WPUA3 = 1 ; enable pull-up: btn
WPUC_WPUC1 = 1 ; enable pull-up: SDI
if PIC16F1825_TEST_MODE then
WPUC_WPUC5 = 1 ; enable pull-up: UART RX
end if
-- UART definition
const serial_hw_baudrate = 115200 -- set the baudrate
alias UART_RX_ENABLE is RCSTA_CREN
alias pin_TX is pin_TX_RC4
alias pin_TX_direction is pin_TX_RC4_direction
alias pin_RX is pin_RX_RC5
alias pin_RX_direction is pin_RX_RC5_direction
-- LED indicator definition
alias led is pin_A5
alias led_direction is pin_A5_direction
-- btn sw definition
alias btn_bit_now is pin_A3
-- SPI definition (SD card interface)
alias pin_sdo_direction is pin_C2_direction
alias pin_sdo is pin_C2
--
alias sd_chip_select is pin_A4
alias sd_chip_select_direction is pin_A4_direction
; PIC16F1825
-- PWM definition (audio out)
if PIC16F1825_TEST_MODE == false then
CCP1CON = 0b0000_1100
alias pwm_l_port_tris_bit is pin_C5_direction
pwm_l_port_tris_bit = OUTPUT; // ccp1 PWM(R) out
alias pwm_l_duty_lower_bits is CCP1CON_DC1B
alias pwm_l_duty_upper_bits is CCPR1L
end if
CCP2CON = 0b0000_1100
alias pwm_r_port_tris_bit is pin_C3_direction
pwm_r_port_tris_bit = OUTPUT; // ccp2 PWM(L) out
alias pwm_r_duty_lower_bits is CCP2CON_DC2B
alias pwm_r_duty_upper_bits is CCPR2L
-- TEST PORT definition
alias test_port is pin_A2
alias test_port_direction is pin_A2_direction
; PIC16F18325
elsif (target_chip == PIC_16F18325) Then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = true;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = true;
const bit HAVE_POWER_OFF_MODE = false; under construction
-- test mode
const bit PIC16F18325_TEST_MODE = false
;if you set false(mono mode), it must be used 8bit mono wav file.
const bit CH_MODE_STEREO = true ;
; fs=44.1KHz
const byte SAMPLING_FREQ = byte( ((target_clock>>2)/44100) - 1 ) ; PR2=180
-- Enable pull-ups
;OPTION_REG_WPUEN = 0 ; enable global Weak Pull-up
WPUA_WPUA3 = 1 ; enable pull-up: btn
WPUC_WPUC1 = 1 ; enable pull-up: SDI
if PIC16F18325_TEST_MODE then
WPUC_WPUC5 = 1 ; enable pull-up: UART RX
end if
-- UART definition
const serial_hw_baudrate = 115200 -- set the baudrate
alias UART_RX_ENABLE is RCSTA_CREN
alias pin_TX is pin_C4
alias pin_TX_direction is pin_C4_direction
alias pin_RX is pin_C5
alias pin_RX_direction is pin_C5_direction
-- LED indicator definition
alias led is pin_A5
alias led_direction is pin_A5_direction
-- Port Slew rate control
SLRCONA = 0 ; set max slew rate
-- PPS setting
include pps
-- in
SSP1DATPPS = PPS_RC1 ; RC1:SDI
-- out
RC2PPS = PPS_SDO1 ; RC2:SDO1
RC0PPS = PPS_SCK1 ; RC0:SCK1
RC5PPS = PPS_CCP1 ; RC5:CCP1
RC3PPS = PPS_CCP2 ; RC3:CCP2
if PIC16F18325_TEST_MODE then
RXPPS = PPS_RC5 ; RC5:UART RX
RC4PPS = PPS_TX ; RC4:UART TX
end if
-- SPI definition (SD card interface)
const bit SPI_CLOCK_MORE_SLOW = true
alias pin_sdo_direction is pin_C2_direction
alias pin_sdo is pin_C2
alias pin_sdi_direction is pin_C1_direction
alias pin_sdi is pin_C1
alias pin_sck_direction is pin_C0_direction
alias pin_sck is pin_C0
--
alias sd_chip_select is pin_A4
alias sd_chip_select_direction is pin_A4_direction
-- btn sw definition
alias btn_bit_now is pin_A3
; PIC16F18325
-- PWM definition (audio out)
const bit PWM_DUTY_REG_LEFT_TYPE2 = true
const bit PWM_DUTY_REG_RIGHT_TYPE2 = true
if PIC16F18325_TEST_MODE == false then
CCP1CON = 0b1000_1111 ; set PWM enable and PWM mode.
CCPR1H = 0 ; clear higher register of duty in advance.
alias pwm_l_port_tris_bit is pin_C5_direction
pwm_l_port_tris_bit = OUTPUT; // ccp1 PWM(R) out
alias pwm_l_duty_lower_bits is CCPR1L
alias pwm_l_duty_upper_bits is CCPR1H
end if
CCP2CON = 0b1000_1111 ; set PWM enable and PWM mode.
CCPR2H = 0 ; clear higher register of duty in advance.
alias pwm_r_port_tris_bit is pin_C3_direction
pwm_r_port_tris_bit = OUTPUT; // ccp2 PWM(L) out
alias pwm_r_duty_lower_bits is CCPR2L
alias pwm_r_duty_upper_bits is CCPR2H
-- TEST PORT definition
alias test_port is pin_A2
alias test_port_direction is pin_A2_direction
; PIC16F1827
elsif (target_chip == PIC_16F1827) Then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = true;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = true;
const bit HAVE_POWER_OFF_MODE = false; under construction
const bit CH_MODE_STEREO = true
; fs=44.1KHz
const byte SAMPLING_FREQ = byte( ((target_clock>>2)/44100) - 1 ) ; PR2=180
-- Enable pull-ups
OPTION_REG_WPUEN = 0 ; enable global Weak Pull-up
WPUA_WPUA5 = 1 ; enable pull-up: btn
WPUB_WPUB1 = 1 ; enable pull-up: SDI1
WPUB_WPUB2 = 1 ; enable pull-up: UART RX
-- UART definition
const serial_hw_baudrate = 115200 -- set the baudrate
alias UART_RX_ENABLE is RCSTA_CREN
WPUB_WPUB2 = 1; /* Weak pull-up enable */
APFCON0_RXDTSEL = 1; /* RX = RB2 , 8pin
APFCON1_TXCKSEL = 1; /* TX = RB5 , 11pin
alias pin_TX is pin_TX_RB5
alias pin_TX_direction is pin_TX_RB5_direction
alias pin_RX is pin_RX_RB2
alias pin_RX_direction is pin_RX_RB2_direction
-- LED indicator definition
alias led is pin_B0
alias led_direction is pin_B0_direction
-- btn sw definition
;var volatile bit pin_A5 at PORTA : 5 ; fix bug for jallib 1.2.0
alias btn_bit_now is pin_A5
-- SPI definition (SD card interface)
APFCON0_SDO1SEL = 1 ; select alternate pin
alias pin_sdo_direction is pin_A6_direction
alias pin_sdo is pin_A6
--
alias sd_chip_select is pin_B3
alias sd_chip_select_direction is pin_B3_direction
; PIC16F1827
-- PWM definition (audio out)
CCP3CON = 0b0000_1100
CCP4CON = 0b0000_1100
alias pwm_l_port_tris_bit is pin_A3_direction
alias pwm_r_port_tris_bit is pin_A4_direction
pwm_l_port_tris_bit = OUTPUT; // ccp3 PWM(L) out
pwm_r_port_tris_bit = OUTPUT; // ccp4 PWM(R) out
alias pwm_l_duty_lower_bits is CCP3CON_DC3B
alias pwm_l_duty_upper_bits is CCPR3L
alias pwm_r_duty_lower_bits is CCP4CON_DC4B
alias pwm_r_duty_upper_bits is CCPR4L
-- TEST PORT definition
alias test_port is pin_A2
alias test_port_direction is pin_A2_direction
; PIC16F1829
elsif (target_chip == PIC_16F1829) Then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = true;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = true;
const bit HAVE_POWER_OFF_MODE = false; under construction
;if you set false(mono mode), it must be used 8bit mono wav file.
const bit CH_MODE_STEREO = true ;
; fs=44.1KHz
const byte SAMPLING_FREQ = byte( ((target_clock>>2)/44100) - 1 ) ; PR2=180
-- Enable pull-ups
OPTION_REG_WPUEN = 0 ; enable global Weak Pull-up
WPUA_WPUA3 = 1 ; enable pull-up: btn
WPUC_WPUC1 = 1 ; enable pull-up: SDI
WPUB_WPUB5 = 1 ; enable pull-up: UART RX
-- UART definition
const serial_hw_baudrate = 115200 -- set the baudrate
alias UART_RX_ENABLE is RCSTA_CREN
alias pin_TX is pin_TX_RB7
alias pin_TX_direction is pin_TX_RB7_direction
alias pin_RX is pin_RX_RB5
alias pin_RX_direction is pin_RX_RB5_direction
-- LED indicator definition
alias led is pin_C4
alias led_direction is pin_C4_direction
-- btn sw definition
alias btn_bit_now is pin_A3
-- SPI definition (SD card interface)
alias sd_chip_select is pin_C6
alias sd_chip_select_direction is pin_C6_direction
; PIC16F1829
-- PWM definition (audio out)
CCP1CON = 0b0000_1100
alias pwm_l_port_tris_bit is pin_C5_direction
pwm_l_port_tris_bit = OUTPUT; // ccp1 PWM(R) out
alias pwm_l_duty_lower_bits is CCP1CON_DC1B
alias pwm_l_duty_upper_bits is CCPR1L
CCP2CON = 0b0000_1100
alias pwm_r_port_tris_bit is pin_C3_direction
pwm_r_port_tris_bit = OUTPUT; // ccp2 PWM(L) out
alias pwm_r_duty_lower_bits is CCP2CON_DC2B
alias pwm_r_duty_upper_bits is CCPR2L
-- TEST PORT definition
alias test_port is pin_C1
alias test_port_direction is pin_C1_direction
; PIC16F88
elsif (target_chip == PIC_16F88) Then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = true;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = true;
const bit HAVE_POWER_OFF_MODE = false; under construction
const bit CH_MODE_STEREO = false
-- fs=44.1KHz
const byte SAMPLING_FREQ = byte( ((target_clock>>2)/44100) - 1 ) ;
-- Enable pull-ups
OPTION_REG_NRBPU = 0 ; enable RB port Weak Pull-up
; auto pull-up each RBx, if it is set to input function
-- UART definition
const serial_hw_baudrate = 9600 -- set the baudrate
alias UART_RX_ENABLE is RCSTA_CREN
-- PWM period timer2 prescale setting
;T2CON_T2CKPS = 0b01; target_clock/4
-- LED indicator definition
alias led is pin_B0
alias led_direction is pin_B0_direction
-- btn sw definition
;var volatile bit pin_A5 at PORTA : 5 ; fix bug for jallib 1.20
alias btn_bit_now is pin_A5
-- SPI definition (SD card interface)
alias sd_chip_select is pin_A4
alias sd_chip_select_direction is pin_A4_direction
-- PWM definition
CCP1CON = 0b0000_1100
alias pwm_l_port_tris_bit is pin_B3_direction
pwm_l_port_tris_bit = OUTPUT; // ccp1 PWM out
alias pwm_l_duty_lower_bits is CCP1CON_DC1B
alias pwm_l_duty_upper_bits is CCPR1L
-- TEST PORT definition
alias test_port is pin_A2
alias test_port_direction is pin_A2_direction
; PIC16F1938
elsif (target_chip == PIC_16F1938) Then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = true;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = true;
const bit HAVE_POWER_OFF_MODE = false; under construction
const bit CH_MODE_STEREO = true
; fs=44.1KHz
const byte SAMPLING_FREQ = byte( ((target_clock>>2)/44100) - 1 ) ; PR2=180
-- Enable pull-ups
OPTION_REG_WPUEN = 0 ; global Weak Pull-up
WPUE_WPUE3 = 1 ; enable pull-up: btn sw
;WPUC_WPUC4 = 1 ; enable pull-up: SDI
;WPUC_WPUC7 = 1 ; enable pull-up: UART RX
-- UART definition
const serial_hw_baudrate = 115200 -- set the baudrate
alias UART_RX_ENABLE is RCSTA_CREN
-- LED indicator definition
alias led is pin_A0
alias led_direction is pin_A0_direction
-- btn sw definition
alias btn_bit_now is pin_E3
-- SPI definition (SD card interface)
alias sd_chip_select is pin_C1
alias sd_chip_select_direction is pin_C1_direction
-- PWM definition (audio out)
APFCON_CCP2SEL = 1; select CCP2 to RB3
CCP1CON = 0b0000_1100
CCP2CON = 0b0000_1100
alias pwm_l_port_tris_bit is pin_B3_direction
alias pwm_r_port_tris_bit is pin_C2_direction
pwm_l_port_tris_bit = OUTPUT; ccp2 // PWM(L) out
pwm_r_port_tris_bit = OUTPUT; ccp1 // PWM(R) out
alias pwm_l_duty_lower_bits is CCP2CON_DC2B
alias pwm_l_duty_upper_bits is CCPR2L
alias pwm_r_duty_lower_bits is CCP1CON_DC1B
alias pwm_r_duty_upper_bits is CCPR1L
-- TEST PORT definition
alias test_port is pin_A0
alias test_port_direction is pin_A0_direction
; PIC18F14K50
elsif (target_chip == PIC_18F14K50) | target_chip == PIC_18F13K50 Then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = true;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = true;
const bit HAVE_POWER_OFF_MODE = false; under construction
const bit CH_MODE_STEREO = false
; fs=44.1KHz
const byte SAMPLING_FREQ = byte( ((target_clock>>2)/44100) - 1 ) ; PR2=180
-- Enable pull-ups
INTCON2_RABPU = 0 ; enable global Weak Pull-up
WPUB_WPUB4 = 1 ; enable pull-up: SDI
WPUB_WPUB5 = 1 ; enable pull-up: UART RX
WPUA_WPUA3 = 1 ; enable pull-up: btn
-- UART definition
const serial_hw_baudrate = 115200 -- set the baudrate
alias UART_RX_ENABLE is RCSTA_CREN
-- LED indicator definition
alias led is pin_C4
alias led_direction is pin_C4_direction
-- btn sw definition
alias btn_bit_now is pin_A3
-- SPI definition (SD card interface)
alias sd_chip_select is pin_C6
alias sd_chip_select_direction is pin_C6_direction
-- PWM definition (audio out)
CCP1CON = 0b0000_1100
alias pwm_l_port_tris_bit is pin_C5_direction
pwm_l_port_tris_bit = OUTPUT; //ccp1 PWM(L) out
alias pwm_l_duty_lower_bits is CCP1CON_DC1B
alias pwm_l_duty_upper_bits is CCPR1L
-- TEST PORT definition
alias test_port is pin_C1
alias test_port_direction is pin_C1_direction
end if
; PIC18F26J50
if target_chip == PIC_18F26J50 then
const bit HAVE_BUTTON_SW = true; for 'Play','Pause','Power off'
const bit HAVE_LED_IND_PWM = true;
const bit HAVE_LED_IND_BLINK = false;
const bit HAVE_LED_PAUSE_INDICATOR = true;
const bit HAVE_POWER_OFF_MODE = false; under construction
const bit CH_MODE_STEREO = true
; fs=44.1KHz
T2CON_T2CKPS =0b01 ; Timre2 prescaler is 1/4
const byte SAMPLING_FREQ = byte( ((target_clock>>4)/44100) - 1 ) ; 67
-- Enable pull-ups
INTCON2_RBPU = 0 ; enable global Weak Pull-up
-- PPS
include pps
-- in
PPS_MAP_RX2DT2 = RP12 ;RP12; RC0 UART RX2
-- out
PPS_MAP_RP13 = PPS_CCP1 ;RP13: RC2: CPP1 PWM(L)
PPS_MAP_RP6 = PPS_CCP2 ;RP6: RB3: CPP2 PWM(R)
PPS_MAP_RP17 = PPS_TX2 ;RP17: RC6: UART TX2