-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassigment.asm
309 lines (300 loc) · 7.28 KB
/
assigment.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
;**********************************************************
; This program control a bottle labeling and packing machine.
; Photocell sensor is connected into RB0
; 7-Segments is connected to PORTB (We connect RB1 to a, RB2 to b ???.And RB7 to g)
; Digits selection of bottles number 7-Segments is connected to RA0
; Digits selection of cartoon number 7-Segments is connected to RA1
; Conveyor belt motor is connected to RA2 (Connect to LED1 on board)
; Label actuator is connected to RA3(Connect to LED2 on board)
; START pushbutton is connected to RA4
; The program uses a PIC16F84A running at crystal oscillator of frequency 4MHz.
;**********************************************************
include "p16f84A.inc"
;**********************************************************
DCounter1 EQU 0X0C
DCounter2 EQU 0X0D
DCounter3 EQU 0X0E
DCounter4 EQU 0X0F
DCounter10 EQU 0X20
DCounter20 EQU 0X21
DCounter30 EQU 0X22
DCounter40 EQU 0X23
HEATER EQU 0X24
COUNTER_HEATER EQU 0X25
DCounter100 EQU 0X26
DCounter200 EQU 0X27
DCounter300 EQU 0X28
DCounter400 EQU 0X29
DCounter1000 EQU 0X30
DCounter2000 EQU 0X31
DCounter3000 EQU 0X32
DCounter4000 EQU 0X33
DCounter11 EQU 0X34
DCounter22 EQU 0X35
DCounter33 EQU 0X36
DCounter44 EQU 0X37
; Macro definitions
push macro
movwf WTemp ; WTemp must be reserved in all banks
swapf STATUS,W ; store in W without affecting status bits
banksel StatusTemp ; select StatusTemp bank
movwf StatusTemp ; save STATUS
endm
pop macro
banksel StatusTemp ; point to StatusTemp bank
swapf StatusTemp,W ; unswap STATUS nibbles into W
movwf STATUS ; restore STATUS
swapf WTemp,F ; unswap W nibbles
swapf WTemp,W ; restore W without affecting STATUS
endm
;**********************************************************
; User-defined variables
cblock 0x0C ; bank 0 assignments
WTemp
StatusTemp
;???? Add all variables here.
endc
;**********************************************************
; Start of executable code
org 0x00 ;Reset vector
nop
goto Main
org 0x04 ;
goto INT_SVC
;;;;;;; Main program ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Main
call Initial ;Initialize everything
MainLoop
call Bottle_Number ;Check if the number of bottles reaches to nine
call Caroon_Number ;Check if the number of packing bottles reaches to nine.
goto MainLoop ;Do it again
;;;;;;; Initial subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This subroutine performs all initializations of variables and registers.
Initial
banksel TRISA
BSF TRISA,RA0 ; SET RA0 AS INPUT
BCF TRISA,RA1 ;SET RA1 AS OUTPUT
BSF TRISA,RA2 ;SET RA2 AS INPUT
BCF TRISA,RA3 ;SET RA3 AS OUTPUT_PUMPA
BCF TRISA,RA4 ;SER RA4 AS OUTPUT
BCF TRISA,RA5 ;SET RA5 AS OUTPUT_HEATER
BCF TRISA,RA6 ;SET RA6 AS OUTPUT_MIXER
BSF TRISB,RB0 ;SET RB0 AS INPUT
BSF TRISB,RB1 ;SET RB1 AS INPUT
MOVLW D'21'
MOVWF HEATER
Return
;;;;;;; Bottle_Number subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This subroutine Test if the number of bottles reaches to nine.
START_MACHINE
BTFSS,RA0
GOTO FINISH
GOTO LEDRUN
Return
;**********************************************************
;;;;;;; Caroon_Number subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This subroutine Test if the number of packing bottles reaches to nine.
LEDRUN
BANKSEL PORTA
BCF PORTA,RA1
CALL SELECTION
Return
;**********************************************************
SELECTION
BANKSEL PORTA
BTFSC PORTA,RA2
GOTO STATUSA
GOTO OUTHERWISE
RETURN
;**********************************************************
STATUS_A
BCF PORTA,RA3 ; SET AS HIGHT PUMP1
CALL DELAY_FLUIDA_1
BCF PORTA,RA4 ;SET AS HIGHT PUMP2
CALL DELLY_FLUID_2
MOVLW D'13'
MOVWF COUNTER_HEATER
BCF PORTA,RA5 ;SET HIGHT HEATER
BCF PORTA,RA6 ;SET HIGHT MIXER
CALL DELAY_HAETER
LOOP_HEATER
MOVLW D'3'
ADDWF HEATER
DECFSZ COUNTER_HEATER
GOTO LOOP_HEATER
GOTO FINIH
RETURN
;**********************************************************
OTHERWISE
BTFSC PORTB,RB0
GOTO STATUSB
GOTO STATUSC
;**********************************************************
STATUSB
BCF PORTA,RA3 ;SET HIGHT PUMPA
CALL DELAY_STATUSB_FLUIDA
MOVLW D'8'
MOVWF COUNTER_HEATER
BCF PORTA,RA5 ;SET HIGHT HEATER
BCF PORTA,RA6 ;SET HIGHT MIXER
CALL DELAY_HAETER
LOOP_HEATER1
MOVLW D'3'
ADDWF HEATER
DECFSZ COUNTER_HEATER
GOTO LOOP_HEATER1
GOTO FINIH
RETURN
;**********************************************************
STATUSC
BCF PORTA,RA3 ;SET HIGHT PUMPA
CALL DELLY_FLUID_2 ; 120 SECOUND
BCF PORTA,RA4 ;SET AS HIGHT PUMP2
CALL DELAY_80S
;****************INCREASE TO 45C
MOVLW D'8'
MOVWF COUNTER_HEATER
BCF PORTA,RA5 ;SET HIGHT HEATER
BCF PORTA,RA6 ;SET HIGHT MIXER
CALL DELAY_HAETER
LOOP_HEATER1
MOVLW D'3'
ADDWF HEATER
DECFSZ COUNTER_HEATER
GOTO LOOP_HEATER1
GOTO FINIH
RETURN
;;;;;;; Delay subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This subroutine to get a delay with 80 Sec.
DELAY_80S
MOVLW 0X99
MOVWF DCounter11
MOVLW 0X9a
MOVWF DCounter22
MOVLW 0Xf7
MOVWF DCounter33
MOVLW 0X04
MOVWF DCounter44
LOOP
DECFSZ DCounter11, 1
GOTO LOOP
DECFSZ DCounter22, 1
GOTO LOOP
DECFSZ DCounter33, 1
GOTO LOOP
DECFSZ DCounter44, 1
GOTO LOOP
RETURN
;;;;;;; Delay subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This subroutine to get a delay with 180 Sec.
DELAY_STATUSB_FLUIDA
MOVLW 0X9d
MOVWF DCounter1000
MOVLW 0Xda
MOVWF DCounter2000
MOVLW 0Xeb
MOVWF DCounter3000
MOVLW 0X09
MOVWF DCounter4000
LOOP
DECFSZ DCounter1000, 1
GOTO LOOP
DECFSZ DCounter2000, 1
GOTO LOOP
DECFSZ DCounter3000, 1
GOTO LOOP
DECFSZ DCounter4000, 1
GOTO LOOP
NOP
NOP
RETURN
;;;;;;; Delay subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This subroutine to get a delay with 45 Sec.
DELAY_HAETER
MOVLW 0X63
MOVWF DCounter100
MOVLW 0Xb7
MOVWF DCounter200
MOVLW 0X3b
MOVWF DCounter300
MOVLW 0X03
MOVWF DCounter400
LOOP3
DECFSZ DCounter100, 1
GOTO LOOP3
DECFSZ DCounter200, 1
GOTO LOOP3
DECFSZ DCounter300, 1
GOTO LOOP3
DECFSZ DCounter400, 1
GOTO LOOP3
NOP
NOP
RETURN
;;;;;;; Delay subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This subroutine to get a delay with 90 Sec.
DELAY_FLUIDA_1
MOVLW 0Xcc
MOVWF DCounter1
MOVLW 0X6d
MOVWF DCounter2
MOVLW 0X76
MOVWF DCounter3
MOVLW 0X05
MOVWF DCounter4
LOOP
DECFSZ DCounter1, 1
GOTO LOOP
DECFSZ DCounter2, 1
GOTO LOOP
DECFSZ DCounter3, 1
GOTO LOOP
DECFSZ DCounter4, 1
GOTO LOOP
NOP
Return
;;;;;;; Delay subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This subroutine to get a delay with 120 Sec.
DELLY_FLUID_2
MOVLW 0X67
MOVWF DCounter10
MOVLW 0Xe7
MOVWF DCounter20
MOVLW 0Xf2
MOVWF DCounter30
MOVLW 0X06
MOVWF DCounter40
LOOP2
DECFSZ DCounter10, 1
GOTO LOOP2
DECFSZ DCounter20, 1
GOTO LOOP2
DECFSZ DCounter30, 1
GOTO LOOP2
DECFSZ DCounter40, 1
GOTO LOOP2
NOP
NOP
RETURN
; ;;;;;;; Bottle_Labeling subroutine ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This subroutine start labeling and counts the number of labeled bottles
Bottle_Labeling
bcf INTCON, INTF ;Clear the External interrupt flag
; write the code here
goto POLL ;Check for another interrupt
;**********************************************************
INT_SVC
push
POLL
btfsc INTCON, INTF ; Check for an External Interrupt
goto Bottle_Labeling
; btfsc ... ; Check for another interrupt
; call ...
; btfsc ... ; Check for another interrupt
; call ...
pop
retfie
;**********************************************************
FINISH
NOP
End