-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.asm
1688 lines (1353 loc) · 24.8 KB
/
main.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;ELEC2117 Project by Matthew Notarangelo 17s1 z5116928
list p=16f886 ; list directive to define processor (PIC16F886)
#include <p16f886.inc> ;processor specific variable definitions
;Define port names to make them easier to use and read from LCD 16x01 segment display
#define COL0 PORTA, 0
#define COL1 PORTA, 1
#define COL2 PORTA, 2
#define COL3 PORTA, 3
#define ROW0 PORTA, 4
#define ROW1 PORTA, 5
#define ROW2 PORTA, 6
#define ROW3 PORTA, 7
#define LCD4 PORTB, 0
#define LCD5 PORTB, 1
#define LCD6 PORTB, 2
#define LCD7 PORTB, 3
#define LCD_RS PORTC, 0
#define LCD_RW PORTC, 1
#define LCD_EN PORTC, 2
#define SDIO PORTC, 4
#define SCLK PORTC, 3
#define RSTFM PORTC, 7
#define BAUD D'100' ; BAUD rate
#define FOSC D'4000' ; Oscillation frequnecy
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The labels following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
__CONFIG _CONFIG1, _LVP_OFF & _FCMEN_ON & _IESO_OFF & _BOR_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
__CONFIG _CONFIG2, _WRT_OFF & _BOR21V
cblock 0x020 ;Define variables
COUNTERL
COUNTERH
INDEX
d1
d2
d3
d4
d5
d6
counter
chanH
chanL
dummy
zerocol
onecol
twocol
threecol
threecolcheck
zerocolcopy
onecolcopy
twocolcopy
threecolcopy
SSPBUFbackup
volumeReg
muteReg
screenReg
endc
;***** 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
PC EQU 0x02
;***** PROCESSOR INIT *****
ORG 0x000 ; processor reset vector
nop
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
main
; Setup memory addressing
BANKSEL ANSEL
clrf ANSEL
BANKSEL ANSELH
clrf ANSELH
; Setup clock frequency and port IO directions
BANKSEL TRISA
movlw B'11110000'
movwf TRISA
BANKSEL TRISB
clrf TRISB
BANKSEL TRISC
clrf TRISC
BANKSEL PORTA
clrf PORTA
BANKSEL PORTB
clrf PORTB
BANKSEL PORTC
clrf PORTC
clrf dummy
movlw B'00000011' ;Preload volumeReg with default volume
movwf volumeReg
movlw B'11111111' ;Preload muteReg with 1 (mute off)
movwf muteReg
movwf screenReg ;Preload screenReg with 1 (screen on)
clrw
initialisationLCD
call delay128ms
bsf LCD4
bsf LCD5
bcf LCD6
bcf LCD7
call RunCommand
call delay5ms ; Initalise 8 bits
call RunCommand
call delay5ms ; Initalise 8 bits
call RunCommand
call delay5ms ; Initalise 8 bits
bcf LCD4
bsf LCD5
bcf LCD6
bcf LCD7 ; Initalise 4 bits
call RunCommand
call delay5ms
bcf LCD4
bsf LCD5
bcf LCD6 ;this part determines the Font, 1 or 2 lines, etc
bcf LCD7
call RunCommand
call CheckBF
bcf LCD4
bcf LCD5
bcf LCD6 ;;this part determines the Font, 1 or 2 lines, etc.
bcf LCD7;;;;
call RunCommand
call CheckBF
call RunCommand
call CheckBF
bcf LCD4
bcf LCD5
bsf LCD6
bsf LCD7 ; display, cursor, blink
call RunCommand
call CheckBF
bcf LCD4
bcf LCD5 ; set shift mode
bcf LCD6
bcf LCD7
call RunCommand
call CheckBF
bcf LCD7
bsf LCD6 ; set shift mode
bsf LCD5
bcf LCD4
call RunCommand
call CheckBF
bcf LCD7
bcf LCD6
bcf LCD5
bcf LCD4
call RunCommand
call CheckBF
bcf LCD7
bcf LCD6
bcf LCD5
bsf LCD4 ; clear display and return to home
call RunCommand
call CheckBF
I2CInitialisation
BANKSEL PORTC
bsf RSTFM
BANKSEL TRISC
bsf TRISC, 3
bsf TRISC, 4
call delay512ms
BANKSEL SSPCON
movlw B'00101000' ;set to i2c master mode
movwf SSPCON
BANKSEL SSPSTAT
movlw B'10000000' ;turn on i2c
movwf SSPSTAT
BANKSEL SSPADD
movlw (FOSC / (4 * BAUD)) - 1
movwf SSPADD
call delay512ms ;delay to let it initialise
I2CWrite
call SendControlStart ;start
movlw B'00000000' ;02H
call Transmit
movlw B'00000000' ;02L
call Transmit
movlw B'00000000' ;03H
call Transmit
movlw B'00000000' ;03L
call Transmit
movlw B'00000000' ;04H
call Transmit
movlw B'00000000' ;04L
call Transmit
movlw B'00000000' ;05H
call Transmit
movlw B'00000000' ;05L
call Transmit
movlw B'00000000' ;06H
call Transmit
movlw B'00000000' ;06L
call Transmit
movlw B'10000001' ;07H ;turn on crystal
call Transmit
movlw B'00000000' ;07L ;turn on crystal
call Transmit
call SendStop
call delay512ms ;let crystal stabilise
;start again
call SendControlStart
movlw B'11000000' ;02H
call Transmit
movlw B'00000001' ;02L ;turn on the chip
call Transmit
;stop
call SendStop
call delay128ms ;let it stabilise
;start again 2
call SendControlStart
movlw B'11000000' ;02H ;initialise registers with correct band/spacing
call Transmit
movlw B'00000001' ;02L
call Transmit
movlw B'00000000' ;03H
call Transmit
movlw B'00000000' ;03L
call Transmit
movlw B'00011000' ;04H
call Transmit
movlw B'00000000' ;04L
call Transmit
movlw B'00000000' ;05H
call Transmit
movlw B'00000011' ;05L
call Transmit
call SendStop
call delay512ms
call OnePress ;goes to the first preset
goto check_keypad ;goes to check keypad loop
delay128ms
BANKSEL PORTB
movlw 0xFE
movwf d1
movlw 0x64
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
goto $+1
nop
return
delay5ms
BANKSEL PORTB
movlw 0xE6
movwf d1
movlw 0x04
movwf d2
Delay_1
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_1 ;3 cycles
goto $+1
nop ;4 cycles (including call)
return
delay512ms
call delay128ms
call delay128ms
call delay128ms
call delay128ms
return
CheckBF
call delay5ms
return
RunCommand
BANKSEL PORTB
bsf LCD_EN
bcf LCD_EN
return
check_keypad
BANKSEL PORTB
bsf COL0
btfsc ROW0 ; has the 1 key been pressed?
call OnePress
btfsc ROW1 ; has the 4 key been pressed?
call FourPress
btfsc ROW2 ; has the 7 key been pressed?
call SevenPress
btfsc ROW3 ; has the * key been pressed?
call AsteriskPress
bcf COL0 ;
bsf COL1
btfsc ROW0 ; has the 2 key been pressed?
call TwoPress
btfsc ROW1 ; has the 5 key been pressed?
call FivePress
btfsc ROW2 ; has the 8 key been pressed?
call EightPress
btfsc ROW3 ; has the 0 key been pressed?
Call ZeroPress
bcf COL1 ;
bsf COL2 ;
btfsc ROW0 ; has the 3 key been pressed?
call ThreePress ;
btfsc ROW1 ; has the 6 key been pressed?
call SixPress ;.
btfsc ROW2 ; has the 9 key been pressed?
call NinePress ;
btfsc ROW3 ; has the # key been pressed?
call HashPress ;
bcf COL2
;
bsf COL3 ;
btfsc ROW0 ; has the A key been pressed?
call APressThatIsntReset
btfsc ROW1 ; has the B key been pressed?
call BPress
btfsc ROW2 ; has the C key been pressed?
call CPress ;
btfsc ROW3 ; has the D key been pressed?
call DPress
bcf COL3 ;
call delay128ms ;this delay acts as a debounce
goto check_keypad
APressThatIsntReset ;turn screen on/off - toggles. Uses screenReg, 0 for off, 1 if it's on
btfss ROW0 ;makes sure that A was actually pressed
return
bcf LCD_RS
bcf LCD4
bcf LCD5
bcf LCD6
bcf LCD7
call RunCommand
call CheckBF
bcf LCD4
bcf LCD5
btfsc screenReg, 0 ;turns off if it is on
bcf LCD6
btfss screenReg, 0 ;turns on if it is off
bsf LCD6
bsf LCD7
call RunCommand
call CheckBF
comf screenReg ;complement screenReg to signal on/off
call delay128ms
return
ZeroPress ;no operation function;
return
OnePress ;station 1 96.9
BANKSEL PORTB
btfss muteReg, 0
return
call SendControlStart
movlw B'11000000' ;02H
call Transmit
movlw B'00000001' ;02L
call Transmit
movlw B'10000000' ;03H
call Transmit
movlw B'00101111' ;03L
call Transmit
call SendStop
call waitFunction
call I2CRead
return
TwoPress ;station 2 smoooooooooooth 95.3
BANKSEL PORTB
btfss muteReg, 0
return
call SendControlStart
movlw B'11000000' ;02H
call Transmit
movlw B'00000001' ;02L
call Transmit
movlw B'10000000' ;03H
call Transmit
movlw B'00100111' ;03L
call Transmit
call SendStop
call waitFunction
call I2CRead
return
ThreePress ;station 3 104.1
BANKSEL PORTB
btfss muteReg, 0
return
call SendControlStart
movlw B'11000000' ;02H
call Transmit
movlw B'00000001' ;02L
call Transmit
movlw B'10000000' ;03H
call Transmit
movlw B'01010011' ;03L
call Transmit
call SendStop
call waitFunction
call I2CRead
return
FourPress ;station 4 101.7
BANKSEL PORTB
btfss muteReg, 0
return
call SendControlStart
movlw B'11000000' ;02H
call Transmit
movlw B'00000001' ;02L
call Transmit
movlw B'10000000' ;03H
call Transmit
movlw B'01000111' ;03L
call Transmit
call SendStop
call waitFunction
call I2CRead
return
FivePress ;station 5 106.5
BANKSEL PORTB
btfss muteReg, 0
return
call SendControlStart
movlw B'11000000' ;02H
call Transmit
movlw B'00000001' ;02L
call Transmit
movlw B'10000000' ;03H
call Transmit
movlw B'01011111' ;03L
call Transmit
call SendStop
call waitFunction
call I2CRead
return
SixPress ;station 6 104.9
BANKSEL PORTB
btfss muteReg, 0
return
call SendControlStart
movlw B'11000000' ;02H
call Transmit
movlw B'00000001' ;02L
call Transmit
movlw B'10000000' ;03H
call Transmit
movlw B'01010111' ;03L
call Transmit
call SendStop
call waitFunction
call I2CRead
return
SevenPress ;station 7 96.1
BANKSEL PORTB
btfss muteReg, 0
return
call SendControlStart
movlw B'11000000' ;02H
call Transmit
movlw B'00000001' ;02L
call Transmit
movlw B'10000000' ;03H
call Transmit
movlw B'00101011' ;03L
call Transmit
call SendStop
call waitFunction
call I2CRead
return
EightPress ;FBi 94.5
BANKSEL PORTB
btfss muteReg, 0
return
call SendControlStart
movlw B'11000000' ;02H
call Transmit
movlw B'00000001' ;02L
call Transmit
movlw B'10000000' ;03H
call Transmit
movlw B'00100011' ;03L
call Transmit
call SendStop
call waitFunction
call I2CRead
return
NinePress ; ABC Classic FM 92.9
BANKSEL PORTB
btfss muteReg, 0
return
call SendControlStart
movlw B'11000000' ;02H
call Transmit
movlw B'00000001' ;02L
call Transmit
movlw B'10000000' ;03H
call Transmit
movlw B'00011011' ;03L
call Transmit
call SendStop
call waitFunction
call I2CRead
return
AsteriskPress ;Seek Down
BANKSEL PORTB
btfss muteReg, 0
return
call SendControlStart
movlw B'11000001' ;02H
call Transmit
movlw B'00000001' ;02L
call Transmit
call SendStop
call waitFunction
call I2CRead
return
HashPress ;Seek Up
BANKSEL PORTB
btfss muteReg, 0
return
call SendControlStart
movlw B'11000011' ;02H
call Transmit
movlw B'00000001' ;02L
call Transmit
call SendStop
call waitFunction
call I2CRead
return
DPress
;mute/unmute
;0 in muteReg means mute is on (no sound is coming out), 1 mute is off (so sound is being outputted)
BANKSEL PORTB
btfss muteReg, 0
goto turnMuteOff
goto turnMuteOn
turnMuteOff
call SendControlStart
movlw B'11000000' ;02H
goto EndMuteFunction
turnMuteOn
call SendControlStart
movlw B'10000000' ;02H
EndMuteFunction
call Transmit
call SendStop
BANKSEL PORTB
comf muteReg, 1
call APress
btfsc muteReg, 0
call I2CRead
btfss muteReg, 0
call displayMute
return
CPress ;decrement the volume
BANKSEL PORTB
btfss muteReg, 0
return
decf volumeReg, 1
btfsc volumeReg, 4 ;checks for overflow
goto VolumeAlreadyAtMin
call SendControlStart
movlw B'11000000' ;02H
call Transmit
movlw B'00000001' ;02L
call Transmit
movlw B'00000000' ;03H
call Transmit
movlw B'00000000' ;03L
call Transmit
movlw B'00011000' ;04H
call Transmit
movlw B'00000000' ;04L
call Transmit
movlw B'00000000' ;05H
call Transmit
BANKSEL PORTB
movf volumeReg, 0 ;05L
call Transmit
call SendStop
call displayVolumeDown
endOfDownVolFunction ; no operation
return
VolumeAlreadyAtMin
incf volumeReg, 1
call displayVolumeAtMin
goto endOfDownVolFunction
return
BPress ;increment the volume
BANKSEL PORTB
btfss muteReg, 0
return
incf volumeReg, 1
btfsc volumeReg, 4 ;checks for overflow
goto VolumeAlreadyAtMax
call SendControlStart
movlw B'11000000' ;02H
call Transmit
movlw B'00000001' ;02L
call Transmit
movlw B'00000000' ;03H
call Transmit
movlw B'00000000' ;03L
call Transmit
movlw B'00011000' ;04H
call Transmit
movlw B'00000000' ;04L
call Transmit
movlw B'00000000' ;05H
call Transmit
BANKSEL PORTB
movf volumeReg, 0 ;05L
call Transmit
call SendStop
call displayVolumeUp
endOfUpVolFunction ; no operation
return
VolumeAlreadyAtMax
decf volumeReg, 1
call displayVolumeAtMax
goto endOfUpVolFunction
return
APress ;;;RESET;;;CLEAR AND MOVE TO HOME;;;;
;This button resets the display
bcf LCD_RS
bcf LCD4
bcf LCD5
bcf LCD6
bcf LCD7
call RunCommand
call CheckBF
bsf LCD4
bcf LCD5
bcf LCD6
bcf LCD7
call RunCommand
call CheckBF
return
I2CFail ;error handling
BANKSEL SSPCON2
bsf SSPCON2, PEN
call WaitMSSP
goto $
return
Send_I2C_Byte
BANKSEL SSPBUF
movwf SSPBUF
retlw 0
WaitMSSP
BANKSEL PIR1
btfss PIR1, SSPIF ;SSPIF checks whether an I2c operation is in progress
goto $-1
bcf PIR1, SSPIF
BANKSEL PORTB
clrw
return
waitFunction
call delay128ms
call SendControlStart
movlw B'11000000' ;02H
call Transmit
movlw B'00000001' ;02L
call Transmit
movlw B'00000000' ;03H ;clears seek/tune bit by overwriting with 0
call Transmit
movlw B'00000000' ;03L
call Transmit
call SendStop
call delay128ms
return
SendControlStart
BANKSEL SSPCON2
bsf SSPCON2, SEN
call WaitMSSP
movlw B'00100000' ;start ;address of si4703
call Transmit
return
SendStop
BANKSEL SSPCON2
bsf SSPCON2,PEN
call WaitMSSP
return
Transmit ; Send via I2C
BANKSEL PORTB
movwf SSPBUFbackup
retryBF1
BANKSEL PORTB
movf SSPBUFbackup ,0
BANKSEL SSPCON
bcf SSPCON, 7
BANKSEL SSPSTAT
btfsc SSPSTAT, 0 ;SSPSTAT, 0 is the busy flag
goto retryBF1
call Send_I2C_Byte
call WaitMSSP
BANKSEL SSPCON
btfsc SSPCON, 7 ;SSPCON, 7 is the write collision bit
goto retryBF1
BANKSEL SSPCON2
btfsc SSPCON2,ACKSTAT
goto I2CFail
return
I2CRead
BANKSEL SSPBUF
clrf SSPBUF
BANKSEL PORTB
clrw
clrf chanH ;clear all variables
clrf chanL
clrf dummy
clrf counter
clrf onecol
clrf twocol
clrf threecol
clrf zerocol
clrf threecolcheck
clrf zerocolcopy
clrf onecolcopy
clrf twocolcopy
clrf threecolcopy
BANKSEL SSPCON2
bsf SSPCON2,SEN ; Generate start Condition
call WaitMSSP ; Wait for I2C operation to start
movlw B'00100001' ; Load CONTROL BYTE (output) The 0010000 part tells to write to the fm chip, while the 0/1 on the end says read/write
call Transmit ;send it
BANKSEL SSPBUF
movf SSPBUF, 0
movwf dummy ;You have to read from SSPBUF after each read otherwise it can't write anymore
call CheckProg
BANKSEL SSPCON2
bsf SSPCON2,RCEN ; Enable Receive Mode (I2C) ;Enabling Recieve mode tells the fm chip that the pic is ready to receive info
call WaitMSSP ;wait for it to complete
call CheckProg
BANKSEL SSPCON2
bcf SSPCON2,ACKDT ; ACK DATA to send is 0 ;0Ah ;this line loads an acknowledge to send to the fm chip
bsf SSPCON2,ACKEN ; Send ACK DATA now. ;this line sends the ack
BANKSEL SSPBUF
movf SSPBUF, 0
movwf dummy ;again read from the buffer
call CheckProg
BANKSEL SSPCON2
bsf SSPCON2,RCEN ; Enable Receive Mode (I2C) ;The receive mode turns off after each cycle
call WaitMSSP
call CheckProg
BANKSEL SSPCON2
bcf SSPCON2,ACKDT ; ACK DATA to send is 0 ;0Al
bsf SSPCON2,ACKEN ; Send ACK DATA now.
BANKSEL SSPBUF
movf SSPBUF, 0
movwf dummy
call CheckProg
BANKSEL SSPCON2
bsf SSPCON2,RCEN ; Enable Receive Mode (I2C