summaryrefslogtreecommitdiff
path: root/software/ttx/ttx.asm
blob: 38b92544ba861be2d428745fc8a8da7a57c9a451 (plain) (blame)
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
  ;;
  ;;  mur.sat
  ;;
  ;;  Somewhen in the year 2011, mur.at will have a nano satellite launched
  ;;  into a low earth orbit (310 km above the surface of our planet). The
  ;;  satellite itself is a TubeSat personal satellite kit, developed and
  ;;  launched by interorbital systems. mur.sat is a joint venture of mur.at,
  ;;  ESC im Labor and realraum.
  ;;
  ;;  Please visit the project hompage at sat.mur.at for further information.
  ;; 
  ;;
  ;;  Copyright (C) 2011 Christian Pointner <equinox@mur.at>
  ;;                         
  ;;  This file is part of mur.sat.
  ;;
  ;;  mur.sat is free software: you can redistribute it and/or modify
  ;;  it under the terms of the GNU General Public License as published by
  ;;  the Free Software Foundation, either version 3 of the License, or
  ;;  any later version.
  ;;
  ;;  mur.sat is distributed in the hope that it will be useful,
  ;;  but WITHOUT ANY WARRANTY; without even the implied warranty of
  ;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ;;  GNU General Public License for more details.
  ;;
  ;;  You should have received a copy of the GNU General Public License
  ;;  along with mur.sat. If not, see <http://www.gnu.org/licenses/>.
  ;;
  ;; -------------------------------------
  ;; PREAMBLE

  LIST      p=12F635
  include   "p12f635.inc"
  __config _WUREN_ON & _FCMEN_OFF & _IESO_OFF & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
  
  ;; -------------------------------------
  ;; DEFINES
BEACON_INT  EQU .3              ; *2 = Beacon Interval in seconds
SECCNT      EQU H'007D'

CHAR        EQU H'0041'
CHARCNT     EQU H'0042'
ELEMENT     EQU H'0043'
ELECNT      EQU H'0044'
  
DOT         EQU .256 -  .29
DASH        EQU .256 -  .87
ESPACE      EQU .256 -  .29
CSPACE      EQU .256 -  .87
WSPACE      EQU .256 - .203

CWENABLE    EQU GP0
CWOUT       EQU GP1
SCLK        EQU GP2
SDAT        EQU GP4

W_TEMP      EQU H'007E'
STATUS_TEMP EQU H'007F'

  ;; -------------------------------------
  ;; Reset Vector
  org	      0
  goto      init

  ;; -------------------------------------
  ;; Interrupt Vector
  org	      4
  ;; save context
  movwf     W_TEMP
  swapf     STATUS,W
  movwf     STATUS_TEMP

  btfss     INTCON,INTF
  goto      tmr1_int
ext_int
  ;; TODO: read bit from GPIO,SDAT and add to received string
  goto      interrupt_end
  
tmr1_int
  decf      SECCNT,f

interrupt_end
  ;; restore context
  swapf     STATUS_TEMP,W
  movwf     STATUS
  swapf     W_TEMP,F
  swapf     W_TEMP,W
  retfie

  ;; -------------------------------------
  ;; INIT
init
  ;; bank 1
  bsf       STATUS,RP0
  bcf       STATUS,RP1

  movlw     b'10000011'
  movwf     OPTION_REG
  movlw     b'11111100'
  movwf     TRISIO
  movlw     b'10000001'
  movwf     PIE1
  movlw     b'00000000'
  movwf     OSCCON
  
  bcf       STATUS,RP0  

  ;; bank 0
  movlw     b'01010000'
  movwf     INTCON
  movlw     b'00000111'
  movwf     T1CON
  movlw     b'00000111'
  movwf     CMCON0
  
  bcf       GPIO,CWOUT
  bcf       GPIO,CWENABLE

  movlw     BEACON_INT
  movwf     SECCNT

  bsf       INTCON,GIE
  goto      main

  ;; -------------------------------------
  ;; TABLES

  ;; Morse Codes: 0=dot, 1=dash
getcw
  addwf     PCL,f
  nop
  retlw     b'00010000'                 ; !
  retlw     b'01001000'                 ; "
  retlw     b'00000000'                 ; #
  retlw     b'00010010'                 ; $
  retlw     b'00000000'                 ; %
  retlw     b'01000000'                 ; &
  retlw     b'01111000'                 ; '
  retlw     b'10110000'                 ; (
  retlw     b'10110100'                 ; )
  retlw     b'00000000'                 ; *
  retlw     b'01010000'                 ; +
  retlw     b'11001100'                 ; ,
  retlw     b'10000100'                 ; -
  retlw     b'01010100'                 ; .
  retlw     b'10010000'                 ; /
  retlw     b'11111000'                 ; 0
  retlw     b'01111000'                 ; 1
  retlw     b'00111000'                 ; 2  
  retlw     b'00011000'                 ; 3
  retlw     b'00001000'                 ; 4
  retlw     b'00000000'                 ; 5  
  retlw     b'10000000'                 ; 6
  retlw     b'11000000'                 ; 7
  retlw     b'11100000'                 ; 8  
  retlw     b'11110000'                 ; 9
  retlw     b'11100000'                 ; :
  retlw     b'10101000'                 ; ;
  retlw     b'00010100'                 ; <
  retlw     b'10001000'                 ; =
  retlw     b'10001010'                 ; >
  retlw     b'00110000'                 ; ?  
  retlw     b'01000000'                 ; @ 
  retlw     b'01000000'                 ; A
  retlw     b'10000000'                 ; B
  retlw     b'10100000'                 ; C
  retlw     b'10000000'                 ; D
  retlw     b'00000000'                 ; E
  retlw     b'00100000'                 ; F
  retlw     b'11000000'                 ; G
  retlw     b'00000000'                 ; H
  retlw     b'00000000'                 ; I
  retlw     b'01110000'                 ; J
  retlw     b'10100000'                 ; K
  retlw     b'01000000'                 ; L
  retlw     b'11000000'                 ; M
  retlw     b'10000000'                 ; N
  retlw     b'11100000'                 ; O
  retlw     b'01100000'                 ; P
  retlw     b'11010000'                 ; Q
  retlw     b'01000000'                 ; R
  retlw     b'00000000'                 ; S
  retlw     b'10000000'                 ; T
  retlw     b'00100000'                 ; U
  retlw     b'00010000'                 ; V
  retlw     b'01100000'                 ; W
  retlw     b'10010000'                 ; X
  retlw     b'10110000'                 ; Y
  retlw     b'11000000'                 ; Z
  
  ;; Morse Code Length
getcwlen
  addwf     PCL,f
  nop       
  retlw     .5                          ; !
  retlw     .6                          ; "
  retlw     .0                          ; #
  retlw     .7                          ; $
  retlw     .0                          ; %
  retlw     .5                          ; &
  retlw     .6                          ; '
  retlw     .5                          ; (
  retlw     .6                          ; )
  retlw     .0                          ; *
  retlw     .5                          ; +
  retlw     .6                          ; ,
  retlw     .6                          ; -
  retlw     .6                          ; .
  retlw     .5                          ; /
  retlw     .5                          ; 0
  retlw     .5                          ; 1
  retlw     .5                          ; 2  
  retlw     .5                          ; 3
  retlw     .5                          ; 4
  retlw     .5                          ; 5  
  retlw     .5                          ; 6
  retlw     .5                          ; 7
  retlw     .5                          ; 8  
  retlw     .5                          ; 9
  retlw     .6                          ; :
  retlw     .6                          ; ;
  retlw     .6                          ; <
  retlw     .5                          ; =
  retlw     .7                          ; >
  retlw     .6                          ; ?  
  retlw     .6                          ; @ 
  retlw     .2                          ; A
  retlw     .4                          ; B
  retlw     .4                          ; C
  retlw     .3                          ; D
  retlw     .1                          ; E
  retlw     .4                          ; F
  retlw     .3                          ; G
  retlw     .4                          ; H
  retlw     .2                          ; I
  retlw     .4                          ; J
  retlw     .3                          ; K
  retlw     .4                          ; L
  retlw     .2                          ; M
  retlw     .2                          ; N
  retlw     .3                          ; O
  retlw     .4                          ; P
  retlw     .4                          ; Q
  retlw     .3                          ; R
  retlw     .3                          ; S
  retlw     .1                          ; T
  retlw     .3                          ; U
  retlw     .4                          ; V
  retlw     .3                          ; W
  retlw     .4                          ; X
  retlw     .4                          ; Y
  retlw     .4                          ; Z

  ;; test string
string
  addwf     PCL,f
  nop
  retlw     'T' - ' '
  retlw     'A' - ' '
  retlw     'S' - ' '
  retlw     '.' - ' '
  retlw     'R' - ' '
  retlw     'U' - ' '
  retlw     'M' - ' '
  
  ;; -------------------------------------
  ;; SUBROUTINES
dottime
  movwf     TMR0
  bcf       INTCON,T0IF
dot_inner
  btfss     INTCON,T0IF
  goto      dot_inner
  return

  ;; -------------------------------------
send_beacon
  bsf       GPIO,CWENABLE
  movlw     .7
  movwf     CHARCNT

beacon_next_char
  movf      CHARCNT,w
  call      string
  call      getcw
  movwf     ELEMENT
  movf      CHARCNT,w
  call      string
  call      getcwlen
  movwf     ELECNT
  movf      ELECNT,f
  btfsc     STATUS,Z
  goto      beacon_invalid_char

beacon_next_element
  bsf       GPIO,CWOUT
  btfss     ELEMENT,7
  movlw     DOT
  btfsc     ELEMENT,7
  movlw     DASH
  call      dottime
  bcf       GPIO,CWOUT

  rlf       ELEMENT,f

  decfsz    ELECNT,f
  goto      beacon_element_space

  movlw     CSPACE
  call      dottime
beacon_invalid_char
  decfsz    CHARCNT,f
  goto      beacon_next_char
  bcf       GPIO,CWENABLE
  return

beacon_element_space
  movlw     ESPACE
  call      dottime
  goto      beacon_next_element

  ;; -------------------------------------
  ;; MAINLOOP
main
  ;; this gets called after reset and whenever a wakeup occured
  ;; (after TMR1 overrun or interrupt on GP2)
  movf      SECCNT,f
  btfss     STATUS,Z
  goto      powerdown

  ;; this gets called every BEACON_INT*2 seconds
  movlw     BEACON_INT
  movwf     SECCNT
  call      send_beacon

powerdown
  sleep
  goto      main
  
  ;; -------------------------------------
  ;; END
  end