-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasmLine.asm
More file actions
103 lines (84 loc) · 2.76 KB
/
Copy pathasmLine.asm
File metadata and controls
103 lines (84 loc) · 2.76 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
title "asmLine.asm - Assembly Language Line Follower Program"
;
; A program which allows the robot to follow a black line
; using two reflective sensors which detect black or white surfaces
;
; Hardware Notes:
; PIC16F684 running at 4 MHz
; Motors:
; -2 DC motors of 143:1 used, through a LM293D IC Driver
; -left motor is controlled by RC0 and RC1
; -right motor is controlled by RC2 and RC3
;
; Sensors:
; -both sensors are wired through a L293 dual comparator
; -LEDs are tied to output of comparators:
; -LED turns OFF when it senses the line
; -LED turns ON when it doesn't sense the line
; -Vref from a 10k pot is set about 2.5V
; -left sensor is let to RA5
; -right sensor is set to RA4
; -LEDs turn on when
;
; Directions:
; to go forward: PORTC<3:0>=1010=10
; to go backwards: PORTC<3:0>=0101=5
; to spin left: PORTC<3:0>=1001=9
; to spin right: PORTC<3:0>=0110=6
;
; Kevin
; 11/18/2019
; -------------------------------------------------------------------------------------------------------------------
; Setup
LIST R=DEC
INCLUDE "p16f684.inc"
INCLUDE "asmDelay.inc"
__CONFIG _FCMEN_OFF & _IESO_OFF & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_ON & _PWRTE_ON & _WDT_OFF & _INTOSCIO ; put this all one ONE line
; Variables
CBLOCK 0x20
ENDC
; ----------------------------------------------------------------------------------------------------------------------
PAGE
; Configuring SFRs (Special Function Register)
org 0
movlw 7 ; turn off Comparators
movwf CMCON0
bsf STATUS, RP0 ; all PORTS are Digital
clrf ANSEL ^ 0X080
clrf TRISC ^ 0X080 ; teach all of PORT C to be outputs
movlw b'111000' ; teach RA4, RA5 to be digital inputs
movwf TRISA^0X080 ; and the rest as outputs
bcf STATUS, RP0 ; (RA3 must always be an input)
;-----------------------------------------------------------------------------------------------------
PAGE
; main loop
loop:
movlw 10 ;Move forward
movwf PORTC ;until hits black line, move accordingly
Dlay 100000
nop
clrf PORTC ;stop momentarily to get a
Dlay 30000 ;more accurate reading from sensors
btfss PORTA, 5 ;if left sensor hits black line,
call turn_left ;turn left
btfss PORTA, 4 ;if right sensor hits black line,
call turn_right ;turn right
goto loop
; -------------------------------------------------------------------------------------------------------------------------------
; subroutine
turn_left: ;turn robot left
movlw 9
movwf PORTC
nop
Dlay 60000
clrf PORTC
Dlay 30000
return ;return back to main program loop
turn_right: ;turn robot right
movlw 6
movwf PORTC
nop
Dlay 60000
clrf PORTC
Dlay 30000
return ;return back to main program loop