-
Notifications
You must be signed in to change notification settings - Fork 0
/
AER201.asm
2107 lines (1818 loc) · 54.9 KB
/
AER201.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
list p=16f877 ; list directive to define processor
#include <p16f877.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _HS_OSC & _WRT_ENABLE_ON & _CPD_OFF & _LVP_OFF
#include <rtc_macros.inc>
cblock 0x20
COUNTH
COUNTM
COUNTL
Table_Counter
lcd_tmp
lcd_d1
lcd_d2
com
dat ; was in sample code
count ; used to convert optime to decimal for display
ones ; ones digit of the converted binary number
tens ; tens digit of the converted binary number
huns ; hundreds digit of the converted binary number (hopefully not used)
binary_num ; move optime to this variable to allow binary --> decimal for display
w_temp ; saves the value in the working register
status_temp ; saves the current state of the status register (for ISR)
barrel1:4
barrel2:4 ;41
barrel3:4 ;44
barrel4:4 ;47
barrel5:4 ;50
barrel6:4 ;53
barrel7:4 ;56
;1: Stores Tall/Short Barrel, Stores E/HF/F
;2: Location (stores distance < 256 cm)
;3: Location (if distance > 256 cm)
barrelnum ;current barrel number
barreltemp
option_temp
Delay1
Delay2
TIMCNT
voltage_IR
counter_IR
lastop_IR ;checks last operation of IR
IR_DETECT
Time_High
Time_Low
ad_store
dis_counter ;increments to 17 for the encoder
dis_counter4 ;increments to 4 before incrementing 17 times for the encoder
min:2 ;temporary registers for operation time
sec:2
initmin:2
initsec:2
finalmin:2
finalsec:2
armextend ;set to 1 when arm extended
Dis_Ones
Dis_Tens
Dis_Hunds
Dis_Thous
ultra_time
threshold_time
barrel_data
endc
cblock 0x70
COUNTH1 ;const used in delay
COUNTM1 ;const used in delay
COUNTL1 ;const used in delay
endc
;Declare constants for pin assignments (LCD on PORTD)
#define RS PORTD,2
#define E PORTD,3
;ANALOG PINS
#define IR1 PORTA,0
#define IR2 PORTA,1
#define IR3 PORTA,2
#define IR4 PORTA,3
#define IR5 PORTA,5
#define IR6 PORTE,0
#define IR7 PORTE,1
#define IR8 PORTE,2
;DIGITAL PINS
#define DCA1 PORTC,1 ;DC motor A1 PWM
#define DCA2 PORTC,0 ;DC motor A2
#define DCB1 PORTC,2 ;DC motor B1 PWM
#define DCB2 PORTD,5 ;DC motor B2 ;A7
#define DCC1 PORTD,6 ;DC motor C1
#define DCC2 PORTD,4 ;DC motor C2
#define US_TRIG PORTC,5 ;Ultrasonic TRIGGER
#define US_ECHO PORTC,6 ;Ultrasonic ECHO
#define LS PORTC,7 ;Laser Sensor Bottom - Digital
;#define LSH PORTD,1 ;Laser Sensor Top - Digital
#define ES PORTD,0 ;encoder sensor
ORG 0x0000 ;RESET vector must always be at 0x00
goto init ;Just jump to the main code section.
;DCB???
;***************************************
; Delay: ~160us macro
;***************************************
LCD_DELAY macro
movlw 0xFF
movwf lcd_d1
decfsz lcd_d1,f
goto $-1
endm
;***************************************
; Display macro
;***************************************
Display macro Message
local loop_
local end_
clrf Table_Counter
clrw
loop_ movf Table_Counter,W
call Message
xorlw B'00000000' ;check WORK reg to see if 0 is returned
btfsc STATUS,Z
goto end_
call WR_DATA
incf Table_Counter,F
goto loop_
end_
endm
bank0 macro
bcf STATUS, RP0
bcf STATUS, RP1
endm
bank1 macro
bcf STATUS, RP0
bsf STATUS, RP1
endm
bank2 macro
bsf STATUS, RP0
bcf STATUS, RP1
endm
bank3 macro
bsf STATUS, RP0
bcf STATUS, RP1
endm
binconv macro
movwf binary_num
call BIN2BCD
movf huns,W
call WR_DATA
movf tens,W
call WR_DATA
movf ones,W
call WR_DATA
endm
;***************************************
; Initialize LCD
;***************************************
init
clrf INTCON ; No interrupts
; bsf INTCON, GIE ; enable global interrupts
; bsf INTCON, 5 ; enable timer 0 interrupts
; bcf INTCON, 4 ; clear timer0 interrupt flag
; bcf INTCON, 2 ; disable internal interrupts (from Port B)
; bcf INTCON, 1 ; clear internal interrupt flag.
; NEED TO FIX THESE SETTINGS
bsf STATUS,RP0 ; select bank 1
movlw b'00101111' ; set RA4 as output
movlw b'11111011' ; Set required keypad inputs
movwf TRISB
clrf TRISC ; All port C is output
;Set SDA and SCL to high-Z first as required for I2C
bsf TRISC,4
bsf TRISC,3
bsf TRISC,7
bsf TRISC,6 ;US_ECHO
clrf TRISD
bsf TRISD,0 ;the encoder is an input
bsf TRISD,1
movlw b'00000111' ;set RE0-3 as input for IR sensors
movwf TRISE
bcf STATUS,RP0 ; select bank 0
clrf PORTA
clrf PORTB
clrf PORTC
clrf PORTD
clrf PORTE
;Set up I2C for communication
call i2c_common_setup
;rtc_resetAll
;Used to set up time in RTC, load to the PIC when RTC is used for the first time
call set_rtc_time
call InitLCD ;Initialize the LCD (code in lcd.asm; imported by lcd.inc)
; Set up Pulse Width Modulation (PWM)
bsf STATUS,RP0 ; Bank1
movlw b'11111001' ; Configure PR2 with 10 kHz
movwf PR2
bcf STATUS,RP0 ; Bank0
movlw b'00001111' ; Configure RC1 and RC2 as PWM outputs
movwf CCP2CON ; RC1
movwf CCP1CON
movlw b'00000100' ; Configure Timer2
movwf T2CON ; Set to prescaler 1:1, postscaler 1:1 , enabled
movwf T1CON
; Initialize motor variable
clrf CCPR2L ; Set RC1 to 0% duty cycle
clrf CCPR1L
;bcf PORTB,0
;bcf PORTC,0
;bcf PORTC,2
;bsf PORTC,5
;bcf PORTC,6
;***************************************
; Main code
;***************************************
Main
btfss PORTB, 1
goto $-1
Display Welcome_Msg1
btfsc PORTB, 1 ;check if cleared
goto $-1
btfss PORTB, 1
goto $-1
call Switch_Lines
Display Welcome_Msg2
test
btfss PORTB, 1 ;check for input from KEYPAD
goto $-1 ;if NOT, keep polling
swapf PORTB, W ;when input is detected, swamp nibbles
;PORTB <7-4> moved to <3-0> in w
andlw 0x0F
xorlw b'00001100' ;checks if 12th key is pressed *
btfss STATUS, Z ;if pressed, then Z=1
goto test ;if NOT, then keep checking until * is pressed
btfsc PORTB, 1 ;keep iterating until key is released
goto $-1
goto START
;***************************************
; Look up table
;***************************************
Welcome_Msg1
addwf PCL,F
dt "Welcome!", 0
Welcome_Msg2
addwf PCL,F
dt "Press * to Start", 0
Message1
addwf PCL,F
dt "T", 0
Message2
addwf PCL,F
dt " B:", 0
Message3
addwf PCL,F
dt "Press * to Reset", 0
Message4
addwf PCL,F
dt "Press # for Info", 0
Message5
addwf PCL,F
dt " TP:", 0
Message6
addwf PCL,F
dt "L:", 0
Message7
addwf PCL,F
dt "D:", 0
Message8
addwf PCL,F
dt " OT", 0
;***************************************
; OPERATION CODE
;***************************************
START
call Clear_Display
;initializing
;intialize barrel1/2/3/4/5/6/7
movlw b'01011000' ;ASCII X
movwf barrel1
movwf barrel2
movwf barrel3
movwf barrel4
movwf barrel5
movwf barrel6
movwf barrel7
;intialize barrel1/2/3/4/5/6/7 + 1
movlw b'00100011' ;#
movwf barrel1+1
movwf barrel2+1
movwf barrel3+1
movwf barrel4+1
movwf barrel5+1
movwf barrel6+1
movwf barrel7+1
movwf barrel1+2
movwf barrel2+2
movwf barrel3+2
movwf barrel4+2
movwf barrel5+2
movwf barrel6+2
movwf barrel7+2
movwf barrel1+3
movwf barrel2+3
movwf barrel3+3
movwf barrel4+3
movwf barrel5+3
movwf barrel6+3
movwf barrel7+3
movlw d'0'
movwf barrelnum
movwf barreltemp
movlw b'00110000'
movwf Dis_Ones
movlw b'00110000'
movwf Dis_Tens
movlw b'00110000'
movwf Dis_Hunds
movlw b'00110000'
movwf Dis_Thous
movlw d'0'
movwf IR_DETECT
movwf threshold_time
bsf STATUS, C ;preset C to 1
movlw b'0'
movwf Time_High
movlw b'0'
movwf Time_Low
movwf dis_counter
movwf dis_counter4
;check if ALl the IRs work
;TEST_IR
; call CHECK_IR1
; movfw IR_DETECT
; call CHECK_DETECT
;
; call CHECK_IR2
; movfw IR_DETECT
; call CHECK_DETECT
;
; call CHECK_IR3
; movfw IR_DETECT
; call CHECK_DETECT
;
; call CHECK_IR4
; movfw IR_DETECT
; call CHECK_DETECT
;
; call Clear_Display
; goto TEST_IR
;
;
;CHECK_DETECT
; xorlw b'1'
; btfss STATUS,Z
; goto SHOWLOW
; call SHOWHIGH
;CHECK_EXIT
; return
;
;SHOWHIGH
; movlw '1'
; call WR_DATA
; return
;
;
;SHOWLOW
; movlw '0'
; call WR_DATA
; goto CHECK_EXIT
;
OPERATION_ENCODER
movlw b'0' ;reset the counter
movwf dis_counter
;call Clear_Display
btfss ES ;check if ES gets a HIGH
goto OPERATION_ENCODER
;call DISTANCECALL17
;check if 4 divisions are counted
incf dis_counter4
movfw dis_counter4
xorlw d'4'
btfss STATUS, Z ;Z=1 when dis_counter4=4
goto OPERATION_ENCODER
call DISTANCECALL17
goto OPERATION_ENCODER
DISTANCECALL17
movlw b'0'
movwf dis_counter4
movfw dis_counter
xorlw d'17' ;Z=1 if dis_counter=17
btfsc STATUS,Z
return ;if Z=1, return
call Distance_Count
incf dis_counter
goto DISTANCECALL17
;
OPERATION_START
;call Realtime
;call CHECK_DISTANCE
;btfsc STATUS, C ;if not set, then continue
;goto END_OPERATION ;if set, then turn back
;btfss ES ;check if Encoder Sensor detects
;goto START1; if doesn't detect, continue
;call Distance_Count ;if so, increment the Distance
START1
;DISTANCE DISPLAY FOR DEBUGGING ONLY
;movlw " "
;call WR_DATA
;movfw Dis_Hunds
;call WR_DATA
;movfw Dis_Tens
;call WR_DATA
;movfw Dis_Ones
;call WR_DATA
;call Clear_Display
;DISTANCE DISPLAY FOR DEBUGGING ONLY
;movfw armextend
;xorlw b'0'
;btfss STATUS,Z
;goto RETRACT_ARM_BACK ;else, retract arm
;at this point, it is clear we have no obstructions, turn on the motors
;turn on the left motor, turn on the right motor
call MOTOR_ON_RC1
call MOTOR_ON_RC2
;*************TEST*
;call RETRACT_ARM_BACK ;just to see the arm rotate back and forth with delay of 1 second
;*************TEST*
;we continue to operate until any of the 8 IR sensors detects something and
;at the same time, we are detecting if there is a column w/ the ultrasonic sesnor
;this is effectively a VERY FAST poll that checks between the IR sensors and the ultrasonic sensors
CHECK_IRSENSORS
;checks all 8 IR sensors
call CHECK_IR1
movfw IR_DETECT
call CHECK_DETECT
call CHECK_IR2
movfw IR_DETECT
call CHECK_DETECT
call CHECK_IR3
movfw IR_DETECT
call CHECK_DETECT
call CHECK_IR4
movfw IR_DETECT
call CHECK_DETECT
call CHECK_IR5
movfw IR_DETECT
call CHECK_DETECT
call CHECK_IR6
movfw IR_DETECT
call CHECK_DETECT
call CHECK_IR7
movfw IR_DETECT
call CHECK_DETECT
call CHECK_IR8
movfw IR_DETECT
call CHECK_DETECT
;if none sensors detected, check US sensor
goto CHECK_US
CHECK_DETECT
xorlw b'1'
btfss STATUS,Z ;Z=1 if IR_DETECT = 1
return ; if Z=0, return and check the next sensor
goto DETECTED ;if detected, check US
;;PURPOSE: Checks the ultrasonic, if detects it, it will stop the motors, rotate the arm
;; ;and them come back and turn the motors back on so that it can
;; ;continue to check for barrels again
;; ;if does not detect, then it will jump to keeping the motors on and
;; ;continue to check for barrels again
CHECK_US
call ULTRASONIC
;C is set when Time_High > 3
movlw b'11' ;3
subwf Time_High,W
btfss STATUS, C
call RETRACT_ARM_BACK ;this means C<3, retract arm
call MOTOR_ON_RC1
call MOTOR_ON_RC2
goto CHECK_IRSENSORS ;this means C>3, go back to checking
DETECTED
;at this point, the LSL has been detected, so stop the motors
call MOTOR_BOTH_OFF
;now check if the LSH detects anything, if it does, it means it is a
;large barrel, if not, then it is a small barrel
btfss LS; if the laser detects AND the IR sensors detect, it is a large barrel
goto SHORTBARREL ;it is a short barrel
goto TALLBARRELL ;it is a large barel
;at this point, done recording and continue with operation
goto OPERATION_START
END_OPERATION
;turn back
call RETRACT_ARM
;reset the distance
movlw b'00110000'
movwf Dis_Ones
movlw b'00110000'
movwf Dis_Tens
movlw b'00110000'
movwf Dis_Hunds
END_LOOP ;add in to retrieve final operation time
bsf DCA ;turn on motos to travel back
bsf DCB
call CHECK_DISTANCE
btfss STATUS, C ;if set, then end
goto END_LOOP ;if not, keep going
bcf DCA ;turn off DC motors
bcf DCB
goto END_DISPLAY ;exit
END_DISPLAY
call Clear_Display
Display Message3
call Switch_Lines
Display Message4
CHECK_PRESS1
btfss PORTB, 1 ;check for input from KEYPAD
goto $-1 ;if NOT, keep polling
swapf PORTB, W ;When input is detected, read it in to W
andlw 0x0F
goto OPTION1
OPTION1 ;checks if * was pressed
movwf option_temp
xorlw b'00001100' ; Check to see if 12th key
btfss STATUS,Z ; If status Z goes to 0, it is the 13th key, skip
goto OPTION2 ; If not check if it's B
call Clear_Display
goto Main ; If it is, restart
OPTION2 ;checks if # was pressed
movf option_temp, W
xorlw b'00001110'
btfss STATUS,Z
goto CHECK_PRESS1 ;resume polling
call Clear_Display
btfsc PORTB, 1 ;keep iterating until key is released
goto $-1
goto POLL1
POLL1
btfss PORTB, 1 ;check for input from KEYPAD
goto Polltime1 ;if no input, poll INFO
swapf PORTB, W ;when input is detected, read it in to W
andlw 0x0F
btfsc PORTB, 1 ;keep iterating until key is released
goto $-1
goto CHECKPRESS1 ;check which key was pressed
Polltime1
movlw "T" ;displays T for Real Time
call WR_DATA
call Realtime ;displays Real Time
Display Message2 ;displays B:
movlw "1" ;displays barrel #
call WR_DATA
Display Message5
movfw barrel1 ;T/S/E/HF/F
call Check_Type
call Switch_Lines
Display Message6
movfw barrel1
call Check_Height
Display Message7
movfw barrel1+3 ;ten digit first, how is this stored? Leave as O's for now
call WR_DATA
movfw barrel1+2
call WR_DATA
movfw barrel1+1
call WR_DATA
Display Message8
call HalfS
call Clear_Display
goto POLL1
CHECKPRESS1
BACKWARD1 ;checks if 1 was pressed
movwf option_temp
xorlw b'00000000' ;checks to see if "1" was pressed
btfss STATUS,Z ;if status Z goes to 0, it is not "1"
goto FORWARD1 ;if not, check to see if "2" was pressed
call Clear_Display
goto POLL7
FORWARD1 ;checks if 2 was pressed
movf option_temp, W
xorlw b'00000001'
btfss STATUS,Z
goto POLL1 ;resume polling
call Clear_Display
goto POLL2
;***************************************
; BARREL2
;***************************************
POLL2
btfss PORTB, 1 ;check for input from KEYPAD
;goto $-1 ;if NOT, keep polling
goto Polltime2
swapf PORTB, W ;When input is detected, read it in to W
andlw 0x0F
btfsc PORTB, 1 ;keep iterating until key is released
goto $-1
goto CHECKPRESS2
Polltime2
movlw "T" ;displays T for Real Time
call WR_DATA
call Realtime ;displays Real Time
Display Message2 ;displays B:
movlw "2" ;displays barrel #
call WR_DATA
Display Message5
movfw barrel2 ;T/S/E/HF/F
call Check_Type
call Switch_Lines
Display Message6
movfw barrel2
call Check_Height
Display Message7
movfw barrel2+3 ;ten digit first, how is this stored? Leave as O's for now
call WR_DATA
movfw barrel2+2
call WR_DATA
movfw barrel2+1
call WR_DATA
Display Message8
call HalfS
call Clear_Display
goto POLL2
CHECKPRESS2
BACKWARD2 ;checks if 1 was pressed
movwf option_temp
xorlw b'00000000' ;checks to see if "1" was pressed
btfss STATUS,Z ;if status Z goes to 0, it is not "1"
goto FORWARD2 ;if not, check to see if "2" was pressed
call Clear_Display
goto POLL1
FORWARD2 ;checks if 2 was pressed
movf option_temp, W
xorlw b'00000001'
btfss STATUS,Z
goto POLL2 ;resume polling
call Clear_Display
goto POLL3
;***************************************
; BARREL3
;***************************************
POLL3
btfss PORTB, 1 ;check for input from KEYPAD
;goto $-1 ;if NOT, keep polling
goto Polltime3
swapf PORTB, W ;When input is detected, read it in to W
andlw 0x0F
btfsc PORTB, 1 ;keep iterating until key is released
goto $-1
goto CHECKPRESS3
Polltime3
movlw "T" ;displays T for Real Time
call WR_DATA
call Realtime ;displays Real Time
Display Message2 ;displays B:
movlw "3" ;displays barrel #
call WR_DATA
Display Message5
movfw barrel3 ;T/S/E/HF/F
call Check_Type
call Switch_Lines
Display Message6
movfw barrel3
call Check_Height
Display Message7
movfw barrel3+3 ;ten digit first, how is this stored? Leave as O's for now
call WR_DATA
movfw barrel3+2
call WR_DATA
movfw barrel3+1
call WR_DATA
Display Message8
call HalfS
call Clear_Display
goto POLL3
CHECKPRESS3
BACKWARD3 ;checks if 1 was pressed
movwf option_temp
xorlw b'00000000' ;checks to see if "1" was pressed
btfss STATUS,Z ;if status Z goes to 0, it is not "1"
goto FORWARD3 ;if not, check to see if "2" was pressed
call Clear_Display
goto POLL2
FORWARD3 ;checks if 2 was pressed
movf option_temp, W
xorlw b'00000001'
btfss STATUS,Z
goto POLL2 ;resume polling
call Clear_Display
goto POLL4
;***************************************
; BARREL4
;***************************************
POLL4
btfss PORTB, 1 ;check for input from KEYPAD
;goto $-1 ;if NOT, keep polling
goto Polltime4
swapf PORTB, W ;When input is detected, read it in to W
andlw 0x0F
btfsc PORTB, 1 ;keep iterating until key is released
goto $-1
goto CHECKPRESS4
Polltime4
movlw "T" ;displays T for Real Time
call WR_DATA
call Realtime ;displays Real Time
Display Message2 ;displays B:
movlw "4" ;displays barrel #
call WR_DATA
Display Message5
movfw barrel4 ;T/S/E/HF/F
call Check_Type
call Switch_Lines
Display Message6
movfw barrel4
call Check_Height
Display Message7
movfw barrel4+3 ;ten digit first, how is this stored? Leave as O's for now
call WR_DATA
movfw barrel4+2
call WR_DATA
movfw barrel4+1
call WR_DATA
Display Message8
call HalfS
call Clear_Display
goto POLL4
CHECKPRESS4
BACKWARD4 ;checks if 1 was pressed
movwf option_temp
xorlw b'00000000' ;checks to see if "1" was pressed
btfss STATUS,Z ;if status Z goes to 0, it is not "1"
goto FORWARD4 ;if not, check to see if "2" was pressed
call Clear_Display
goto POLL3
FORWARD4 ;checks if 2 was pressed
movf option_temp, W
xorlw b'00000001'
btfss STATUS,Z
goto POLL4 ;resume polling
call Clear_Display
goto POLL5
;***************************************
; BARREL5
;***************************************
POLL5
btfss PORTB, 1 ;check for input from KEYPAD
;goto $-1 ;if NOT, keep polling
goto Polltime5
swapf PORTB, W ;When input is detected, read it in to W
andlw 0x0F
btfsc PORTB, 1 ;keep iterating until key is released
goto $-1
goto CHECKPRESS5
Polltime5
movlw "T" ;displays T for Real Time
call WR_DATA
call Realtime ;displays Real Time
Display Message2 ;displays B:
movlw "5" ;displays barrel #
call WR_DATA
Display Message5
movfw barrel5 ;T/S/E/HF/F
call Check_Type
call Switch_Lines
Display Message6
movfw barrel5
call Check_Height
Display Message7
movfw barrel5+3 ;ten digit first, how is this stored? Leave as O's for now
call WR_DATA
movfw barrel5+2
call WR_DATA
movfw barrel5+1
call WR_DATA
Display Message8
call HalfS
call Clear_Display
goto POLL5
CHECKPRESS5
BACKWARD5 ;checks if 1 was pressed
movwf option_temp
xorlw b'00000000' ;checks to see if "1" was pressed
btfss STATUS,Z ;if status Z goes to 0, it is not "1"
goto FORWARD5 ;if not, check to see if "2" was pressed
call Clear_Display
goto POLL4
FORWARD5 ;checks if 2 was pressed
movf option_temp, W
xorlw b'00000001'
btfss STATUS,Z
goto POLL5 ;resume polling
call Clear_Display
goto POLL6
;***************************************
; BARREL6
;***************************************
POLL6
btfss PORTB, 1 ;check for input from KEYPAD
;goto $-1 ;if NOT, keep polling
goto Polltime6
swapf PORTB, W ;When input is detected, read it in to W
andlw 0x0F
btfsc PORTB, 1 ;keep iterating until key is released
goto $-1
goto CHECKPRESS6
Polltime6
movlw "T" ;displays T for Real Time
call WR_DATA
call Realtime ;displays Real Time
Display Message2 ;displays B:
movlw "6" ;displays barrel #
call WR_DATA
Display Message5
movfw barrel6 ;T/S/E/HF/F
call Check_Type
call Switch_Lines
Display Message6
movfw barrel6
call Check_Height
Display Message7
movfw barrel6+3 ;ten digit first, how is this stored? Leave as O's for now
call WR_DATA
movfw barrel6+2
call WR_DATA
movfw barrel6+1
call WR_DATA
Display Message8
call HalfS
call Clear_Display
goto POLL6
CHECKPRESS6
BACKWARD6 ;checks if 1 was pressed
movwf option_temp
xorlw b'00000000' ;checks to see if "1" was pressed
btfss STATUS,Z ;if status Z goes to 0, it is not "1"
goto FORWARD6 ;if not, check to see if "2" was pressed
call Clear_Display
goto POLL5
FORWARD6 ;checks if 2 was pressed
movf option_temp, W
xorlw b'00000001'
btfss STATUS,Z
goto POLL6 ;resume polling
call Clear_Display
goto POLL7
;***************************************
; BARREL7
;***************************************
POLL7
btfss PORTB, 1 ;check for input from KEYPAD
;goto $-1 ;if NOT, keep polling
goto Polltime7
swapf PORTB, W ;When input is detected, read it in to W
andlw 0x0F
btfsc PORTB, 1 ;keep iterating until key is released
goto $-1
goto CHECKPRESS7
Polltime7
movlw "T" ;displays T for Real Time
call WR_DATA
call Realtime ;displays Real Time
Display Message2 ;displays B:
movlw "7" ;displays barrel #
call WR_DATA
Display Message5
movfw barrel7 ;T/S/E/HF/F
call Check_Type
call Switch_Lines
Display Message6
movfw barrel7
call Check_Height
Display Message7
movfw barrel7+3 ;ten digit first, how is this stored? Leave as O's for now
call WR_DATA
movfw barrel7+2
call WR_DATA
movfw barrel7+1