-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrafficButtons.asm
153 lines (138 loc) · 2.99 KB
/
trafficButtons.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
QTI Sensor
title "trafficButtons"
;
; A program that uses a QTI sensor to sense whether or not Santa's sleigh is approaching.
; Lights flash if QTI senses something
;
; Hardware Notes:
; PIC16F684 running at 4 MHz
; Inputs:
; RA5 - QTI sensor
;
; Outputs:
; RC0, RC1, RC2, RC3, RC4 connected to LED's through 1K resistors
;
; Kevin Tu
; 12/10/2019
;--------------------------------------------------------------------------
; Setup
LIST R=DEC
INCLUDE "p16f684.inc"
INCLUDE "asmDelay.inc"
__CONFIG _FCMEN_OFF & _IESO_OFF & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTOSCIO
; Variables
CBLOCK 0x020
ENDC
;--------------------------------------------------------------------------
PAGE
; Mainline of "TrafficLightsVTwo"
org 0
movlw 7 ;turn off Comparators
movwf CMCON0
bsf STATUS, RP0 ;going into Bank 1
clrf ANSEL ^ 0x080 ;making all PORTS are Digital
clrf TRISC ^ 0x080 ;teach all of PORTC to be outputs
movlw b'00011000' ;leaving RA3 and RA4 as inputs, teaching everything else in PORTA to be outputs
movwf TRISA ^ 0x080 ;moving binary value into TRISA to correspond with RA values
bcf STATUS, RP0 ;going back into Bank 0
loop:
nop
btfss PORTA, 4
call button
btfsc PORTA, 4
call noButton
goto loop
;--------------------------------------------------------------------------
PAGE
;Subroutines
noButton:
clrf PORTC
return
button:
Dlay 1000000 ;delay 1 second
movlw b'00000001' ;turning on first LED
movwf PORTC
Dlay 2000000 ;delay 2 seconds
movlw b'00000011' ;turning on second LED
movwf PORTC
Dlay 2000000 ;delay 2 seconds
movlw b'00000111' ;turning on third LED
movwf PORTC
Dlay 2000000 ;delay 2 seconds
movlw b'00001111' ;turning on fourth LED
movwf PORTC
Dlay 2000000 ;delay 2 seconds
movlw b'00011111' ;turning on fifth LED
movwf PORTC
Dlay 1000000 ;delay 1 second
movlw b'00011111'
movwf PORTC
nop
Dlay 1000000 ;turn off (essentially flashing on and off with intervals of 1 second)
clrf PORTC
nop
Dlay 1000000
movlw b'00011111'
movwf PORTC
nop
Dlay 1000000
clrf PORTC
nop
Dlay 1000000
movlw b'00011111'
movwf PORTC
nop
Dlay 1000000
clrf PORTC
nop
Dlay 1000000
movlw b'00011111'
movwf PORTC
nop
Dlay 1000000
clrf PORTC
nop
Dlay 1000000
movlw b'00011111'
movwf PORTC
nop
Dlay 1000000
clrf PORTC
nop
Dlay 100000 ;flashing on and off with intervals of 0.1 seconds
movlw b'00011111'
movwf PORTC
nop
Dlay 100000
clrf PORTC
nop
Dlay 100000
movlw b'00011111'
movwf PORTC
nop
Dlay 100000
clrf PORTC
nop
Dlay 100000
movlw b'00011111'
movwf PORTC
nop
Dlay 100000
clrf PORTC
nop
Dlay 100000
movlw b'00011111'
movwf PORTC
nop
Dlay 100000
clrf PORTC
nop
Dlay 100000
movlw b'00011111'
movwf PORTC
nop
Dlay 100000
clrf PORTC
nop
return
end