This repository was archived by the owner on Oct 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken_generator.asm
103 lines (79 loc) · 1.57 KB
/
token_generator.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
PROCESSOR 10F200
#include "p10f200.inc"
; HTdly - Width of HasToken pulse
; Tdly - Width of token
GenT: equ GP0
RemT: equ GP1
TO: equ GP2
TI: equ GP3
d1var: equ 0x10
d2var: equ 0x11
d3var: equ 0x12
; Disable reset pin, code protection and watchdog timer
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF
org 0x00
movlw b'10011111' ; Disable Timer input on GP2 pin
option
movlw b'00001011' ; Set GP2 to output
tris GPIO
bsf GPIO, TO ; Clear TO line, GPIO is undefined after POR
; 2 second delay on reset
movlw d'200' ; 200 * 10ms = 2s
movwf d1var
d1: movlw d'100' ; 100 * 100us = 10ms
movwf d2var
d2: call Pdly
decfsz d2var, 1
goto d2
decfsz d1var, 1
goto d1
; GenT pin checking/token generating
Loop: btfsc GPIO, GenT ; Skip next if clear
goto TIif
movlw d'100' ; 10ms debouncing delay
movwf d3var
d3: call Pdly
decfsz d3var, 1
goto d3
WaitGT: btfss GPIO, GenT ; Wait for GenT to go high before generating
goto WaitGT
bcf GPIO, TO ; Generate token
call Tdly
bsf GPIO, TO
; TI checking/token propagating
TIif: btfsc GPIO, TI ; Skip next if set
goto Loop
SendT: btfss GPIO, TI ; Wait for TI to clear before sending token
goto SendT
btfss GPIO, RemT ; Don't propagate token if it's to be removed
goto Loop
bcf GPIO, TO
call Tdly
bsf GPIO, TO
goto Loop
Tdly: nop ; 7us delay
nop
nop
retlw 0x00
Pdly: call Tdly ; 100us delay
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
call Tdly
retlw 0x00
end