-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseven_seg.asm
388 lines (324 loc) · 7.76 KB
/
seven_seg.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
;**********************************************************************
; This file is a basic code template for assembly code generation *
; on the PIC16F54. This file contains the basic code *
; building blocks to build upon. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: seven_seg.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files Required: P16F54.INC *
; *
;**********************************************************************
; *
; Notes: *
; *
;**********************************************************************
list p=16F54 ; list directive to define processor
#include <p16f5x.inc>
; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _RC_OSC
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
porta equ PORTA
portb equ PORTB
; FSR equ 0x04
general EQU 0x07 ;example variable definition
counter EQU 0x08 ;example variable definition
state EQU 0x09
config_reg EQU 0x0A
digit0 Equ 0x0B
digit1 Equ 0x0C
digit2 Equ 0x0D
loop_cnt EQU 0x0E
bit_count EQU 0x0F
char_count EQU 0x10
character0 EQU 0x11
character1 EQU 0x12
character2 EQU 0x13
fsr_bck EQU 0x14
crc_reg EQU 0x15
crc_data EQU 0x16
crc_sum EQU 0x17
#define WAIT_CONST 0x0F
#define IDLE 0x00
#define WAIT_DATA 0x01
#define WAIT_FALLING_EDGE 0x02
#define WAIT_HIGH_PULS 0x03
#define EXTRACT_BYTE 0x04
;**********************************************************************
ORG 0x1FF ; processor reset vector
goto start
ORG 0x000
init
clrf PORTA
clrf PORTB
movlw 0x00
tris PORTB
movlw 0xf8
tris PORTA
clrf char_count
clrf crc_reg
clrf state
clrf loop_cnt
clrf config_reg
movlw WAIT_CONST
movwf counter
movlw 0x0B
movwf FSR
clrf INDF
movlw 0x01
movwf digit0
movlw 0x30
movwf digit1
movlw 0x7
movwf digit2
retlw 0
init0
movlw 0x00
tris PORTB
movlw 0xf8
tris PORTA
clrf char_count
clrf crc_reg
clrf state
bcf config_reg, 7
movlw 0x0B
movwf FSR
retlw 0
start
btfsc STATUS, 3
call init
btfss STATUS, 3
call init0
main
btfsc config_reg, 7
sleep
btfsc config_reg, 6
goto clear_display
decfsz counter
goto clear_display
movlw 0x3F
andwf config_reg, w
movwf counter
incf counter
decfsz general
goto small_display
display
movlw 0x03
movwf general
movlw 0x0D
movwf FSR
small_display
movlw 0xf8
movwf porta
movfw INDF
movwf portb
decf FSR
movlw 0x01
subwf general,w
call power_2
movwf porta
goto read_io
end_read_io
goto main
clear_display
clrf portb
read_io
movlw IDLE
subwf state, w
btfsc STATUS, Z
goto IDLE_STATE
movlw WAIT_FALLING_EDGE
subwf state, w
btfsc STATUS, Z
goto wait_falling_edge_state
movlw WAIT_DATA
subwf state, w
btfsc STATUS, Z
goto WAIT_DATA_STATE
movlw WAIT_HIGH_PULS
subwf state, w
btfsc STATUS, Z
goto WAIT_HIGH_PULS_STATE
movlw EXTRACT_BYTE
subwf state, w
btfsc STATUS, Z
goto EXTRACT_BYTE_STATE
goto end_read_io
IDLE_STATE
btfsc porta, 0x03
goto byte_timeout
movlw 0x0A
movwf loop_cnt
movlw 0x07
movwf bit_count
clrf character0
movlw WAIT_DATA
movwf state
byte_timeout
decfsz loop_cnt
goto end_read_io
clrf char_count
clrf crc_reg
goto end_read_io
WAIT_DATA_STATE
decfsz loop_cnt
goto end_read_io
btfss porta, 0x03
goto weiter0
incf character0
movlw WAIT_FALLING_EDGE
movwf state
movlw 0xf0
movwf loop_cnt
goto end_read_io
weiter0
movlw WAIT_HIGH_PULS
movwf state
movlw 0x30
movwf loop_cnt
goto end_read_io
EXTRACT_BYTE_STATE
incf char_count
movlw 0x01
subwf char_count, w
btfsc STATUS, Z
goto extract_character2
movlw 0x02
subwf char_count, w
btfsc STATUS, Z
goto extract_character1
movlw 0x03
subwf char_count, w
btfsc STATUS, Z
goto extract_character0
extract_character2
movfw character0
movwf character2
movwf crc_data
call crc_table
clrf state
goto end_read_io
extract_character1
movfw character0
movwf character1
movwf crc_data
call crc_table
clrf state
goto end_read_io
extract_character0
movfw character0
movwf crc_data
call crc_table
clrf loop_cnt
clrf char_count
clrf crc_reg
clrf state
movlw 0x00
subwf crc_reg
btfsc STATUS, Z
call set_digit
goto end_read_io
wait_falling_edge_state
movlw 0x00
subwf bit_count, w
btfss STATUS, Z
goto bit_count_positif
movlw EXTRACT_BYTE
movwf state
goto end_read_io
bit_count_positif
btfss porta, 0x03
goto weiter0_wait_falling_edge_state
decfsz loop_cnt
goto not_time_out_wait_falling_edge_state
clrf char_count
clrf crc_reg
clrf state
not_time_out_wait_falling_edge_state
goto end_read_io
weiter0_wait_falling_edge_state
rlf character0
bcf character0, 0
decf bit_count
weiter_wait_data
movlw WAIT_DATA
movwf state
movlw 0x0A
movwf loop_cnt
goto end_read_io
WAIT_HIGH_PULS_STATE
btfss porta, 0x03
goto weiter0_wait_high_puls_state
movlw WAIT_FALLING_EDGE
movwf state
movlw 0xf0
movwf loop_cnt
goto end_read_io
weiter0_wait_high_puls_state
decfsz loop_cnt
goto not_time_out_wait_high_puls_state
clrf char_count
clrf crc_reg
clrf state
not_time_out_wait_high_puls_state
goto end_read_io
set_digit
movfw FSR
movwf fsr_bck
movlw 0x0A
movwf FSR
movfw character2
andlw 0x03
addwf FSR
movfw character1
movwf INDF
movlw 0x1F
andwf fsr_bck, w
movwf FSR
retlw 0x00
power_2
andlw 0x03
addwf PCL
retlw 0x01
retlw 0x02
retlw 0x04
retlw 0x08
crc_table
movlw 0x08
movwf fsr_bck
crc_loop
movfw crc_reg
xorwf crc_data, w
movwf crc_sum
rlf crc_reg
bcf crc_reg, 0
btfss crc_sum, 7
goto crc_weiter
movlw 0x1D
xorwf crc_reg
crc_weiter
rlf crc_data
bcf crc_data, 0
decfsz fsr_bck
goto crc_loop
retlw 0
; remaining code goes here
END ; directive 'end of program'