-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChairWithCommitmentIssues.txt
248 lines (227 loc) · 3.83 KB
/
ChairWithCommitmentIssues.txt
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
;**** Timer ****
TSCR1 EQU $46
TSCR2 EQU $4D
TIOS EQU $40
TCTL1 EQU $48
TCTL2 EQU $49
TFLG1 EQU $4E
TIE EQU $4C
TSCNT EQU $44
TC4 EQU $58
TC1 EQU $52
;***************
;*** PORTS ****
DDRA EQU $02
PORTA EQU $00
PORTB EQU $01
DDRB EQU $03
PORTM EQU $0250
DDRM EQU $0252
;**************
;*** ADC Unit ***
ATDCTL2 EQU $122
ATDCTL4 EQU $124
ATDCTL5 EQU $125
ATDSTAT0 EQU $126
ATD1DR1H EQU $132
ATD1DR1L EQU $133
;****************
MS_CONST equ $FFFF
; Include .hc12 directive, in case you need MUL
.hc12
ORG $1000
MinSpot ds 1 ; hunched forward
MaxSpot ds 1 ; right at the back of the chair
ORG $400
LDS #$4000
; Set MinSpot and MaxSpot values
LDAA #!80
STAA MinSpot
LDAA #!180
STAA MaxSpot
; Initialize A/D
LDAA #%11000000 ; initialize ADTCTL2 -- power up, set fast flag clearing
STAA $122 ; which is ADTCTL2
; wait a bit for thing to boot up
LDY #!5
JSR Delay
LDAA #%11100101 ; initialize ADTCTL4 -- 8 bit res, 16 A/D clock, and PRS to 00101
STAA $124 ; which is ADTCTL4
JSR InitLCD; Initialize LCD
; Check temp "seat" sensor for "person"
Heat LDAA #$C1
STAA ATDCTL5
BRCLR ATDSTAT0,$80,*
LDAB ATD1DR1L
CMPB #!200
BLS Heat
;Timer
LDAA #$90
STAA TSCR1
LDAA #$04
STAA TSCR2
LDAA #$10
STAA TIOS
LDAA #$01
STAA TCTL1
LDD TSCNT
ADDD #$FF
STD TC4
BRA SitTime
; While NOT standing up, check posture - if timer is up, print STAND UP until "person" is up
SitTime BRCLR TFLG1,$10,Posture
LOOP JSR PrintStandUp
LDAA #$C1
STAA ATDCTL5
BRCLR ATDSTAT0,$80,*
LDAB ATD1DR1L
CMPB #!200
BLS Heat
BRA LOOP
; Check "posture"
Posture LDAB #%11000000 ; end with 000 for ch0 (potentiometer)
STAB ATDCTL5
BRCLR ATDSTAT0,%10000000,* ; wait for bit 7 on ADTSTAT0 ($126) to detect
LDAB ATD1DR1L
CMPB MinSpot
BLS PrintLeanBack
CMPB MaxSpot
BHI PrintLeanForwards
BRA PrintBlank
Delay DEY
BNE Delay
RTS
PrintLeanBack:
LDX #LeanBack ; Load String Pointer
PSHX ; Push array pointer
JSR SENDSTR
LEAS 2,SP ; Clean up the mess.
BRA SitTime
PrintLeanForwards:
LDX #LeanForwards ; Load String Pointer
PSHX ; Push array pointer
JSR SENDSTR
LEAS 2,SP ; Clean up the mess.
BRA SitTime
PrintStandUp:
LDX #StandUp ; Load String Pointer
PSHX ; Push array pointer
JSR SENDSTR
LEAS 2,SP ; Clean up the mess.
RTS
PrintBlank:
LDX #Blank ; Clear display using Blank String (pointer)
PSHX
JSR SENDSTR
LEAS 2,SP ; Clean up the mess
BRA SitTime
SENDSTR:
LDY 2,SP
LDAA #1
PSHA
PSHA
JSR SendWithDelay
PULA
PULA
LOOPSTR:
LDAA 1,Y+ ; Get the current value and THEN increment the pointer
BNE DO_NEXT; We must count each non-zero value
RTS ; If we get here, we found the null-terminator.
DO_NEXT:
PSHA
LDAA #1
PSHA
BSET PORTM,$04
JSR SendWithDelay
BCLR PORTM,$04
PULA
PULA
BRA LOOPSTR
InitLCD LDAA #$FF ; Set port A to output for now
STAA DDRA
LDAA #$1C ; Set port M bits 4,3,2
STAA DDRM
LDAA #$30 ; We need to send this command a bunch of times
PSHA
LDAA #5
PSHA
JSR SendWithDelay
PULA
LDAA #1
PSHA
JSR SendWithDelay
JSR SendWithDelay
JSR SendWithDelay
PULA
PULA
LDAA #$08
PSHA
LDAA #1
PSHA
JSR SendWithDelay
PULA
PULA
LDAA #1
PSHA
PSHA
JSR SendWithDelay
PULA
PULA
LDAA #6
PSHA
LDAA #1
PSHA
JSR SendWithDelay
PULA
PULA
LDAA #$0E
PSHA
LDAA #1
PSHA
JSR SendWithDelay
PULA
PULA
RTS
SendWithDelay:
TSX
LDAA 3,X
STAA PORTA
BSET PORTM,$10 ; Turn on bit 4
JSR Delay1MS
BCLR PORTM,$10 ; Turn off bit 4
TSX
LDAA 2,X
PSHA
CLRA
PSHA
JSR DelayPrint
PULA
PULA
RTS
Delay1MS:
PSHX
LDX #MS_CONST
ms_loop:
CPX #0
BEQ ms_done
DEX
BRA ms_loop
ms_done:
PULX
RTS
DelayPrint:
PSHX
LDX 4,SP
delay_loop:
CPX #0
BEQ delay_done
JSR Delay1MS
DEX
BRA delay_loop
delay_done:
PULX
RTS
LeanForwards: DB 'L','e','a','n',' ','F','o','r','w','a','r','d','s',0
LeanBack: DB 'L','e','a','n',' ','B','a','c','k',0
StandUp: DB 'S','t','a','n','d',' ','U','p',0
Blank: DB '',0