Subversion Repositories svn.mios

Rev

Rev 324 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
324 tk 1
; $Id: main.asm 878 2010-01-02 15:40:58Z tk $
2
;
3
; A CORE->DIN/DOUT Module Interconnection Test
4
;
5
; ==========================================================================
6
;
7
;  Copyright 2004 Thorsten Klose (tk@midibox.org)
8
;  Licensed for personal non-commercial use only.
9
;  All other rights reserved.
10
; 
11
; ==========================================================================
12
 
13
;; ---[ MIOS header file ]---
14
#include <mios.h>
15
 
16
;; ---[ useful macros ]---
17
#include <macros.h>
18
 
19
;; ---[ vectors to MIOS functions (never change!) ]---
20
#include <mios_vectors.inc>
21
 
22
;; ---[ user hooks (never change!) ]---
23
#include <user_vectors.inc>
24
 
25
;; ==========================================================================
26
;;  General Application Settings
27
;; ==========================================================================
28
 
29
;; ---[ variables used by application ]---
30
#include "app_defines.h"
31
 
32
; ==========================================================================
33
 
34
;; ---[ configuration table for MIDI processor and rotary encoders ]---
35
#include <mios_mt_table.inc>
36
#include <mios_enc_table.inc>
37
 
38
;; ---[ Custom LCD driver ]---
39
#include <app_lcd.inc>
40
 
878 tk 41
;; ---[ Debug Message Module ]---
42
#include <debug_msg.inc>
43
 
44
 
324 tk 45
;; ==========================================================================
46
;;  All MIOS hooks in one file
47
;; ==========================================================================
48
 
49
;; --------------------------------------------------------------------------
50
;;  This function is called by MIOS after startup to initialize the 
51
;;  application
52
;; --------------------------------------------------------------------------
53
USER_Init
54
    clrf    SRIO_PIN_NUMBER
55
    call    SRIO_SetPin
56
    return
57
 
58
 
59
;; --------------------------------------------------------------------------
60
;;  This function is called by MIOS in the mainloop when nothing else is to do
61
;; --------------------------------------------------------------------------
62
USER_Tick
63
    return
64
 
65
 
66
;; --------------------------------------------------------------------------
67
;;  This function is periodically called by MIOS. The frequency has to be
68
;;  initialized with MIOS_Timer_Set
69
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
70
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
71
;; --------------------------------------------------------------------------
72
USER_Timer
73
    return
74
 
75
 
76
;; --------------------------------------------------------------------------
77
;;  This function is called by MIOS when a debug command has been received
78
;;  via SysEx
79
;;  Input:
80
;;     o WREG, MIOS_PARAMETER1, MIOS_PARAMETER2, MIOS_PARAMETER3 like
81
;;       specified in the debug command
82
;;  Output:
83
;;     o return values WREG, MIOS_PARAMETER1, MIOS_PARAMETER2, MIOS_PARAMETER3
84
;; --------------------------------------------------------------------------
85
USER_MPROC_DebugTrigger
86
    return
87
 
88
 
89
;; --------------------------------------------------------------------------
90
;;  This function is called by MIOS when the display content should be 
91
;;  initialized. Thats the case during startup and after a temporary message
92
;;  has been printed on the screen
93
;; --------------------------------------------------------------------------
94
USER_DISPLAY_Init
95
    call    MIOS_LCD_Clear
96
 
97
    TABLE_ADDR TEXT_WELCOME_0
98
    call    MIOS_LCD_PrintString
99
    call    MIOS_LCD_PrintString
100
 
878 tk 101
    call    DEBUG_MSG_SendHeader
102
    movlw   '\n'
103
    call    DEBUG_MSG_SendChar
104
    call    DEBUG_MSG_SendFooter
105
 
106
    call    DEBUG_MSG_SendHeader
107
    call    DEBUG_MSG_SendASMString
108
    db  "SRIO Interconnection Test\n", 0
109
    call    DEBUG_MSG_SendFooter
110
 
111
    call    DEBUG_MSG_SendHeader
112
    call    DEBUG_MSG_SendASMString
113
    db  "=========================\n", 0
114
    call    DEBUG_MSG_SendFooter
115
 
116
    call    DEBUG_MSG_SendHeader
117
    call    DEBUG_MSG_SendASMString
118
    db  "Please play a note on any MIDI channel.\n", 0
119
    call    DEBUG_MSG_SendFooter
120
 
324 tk 121
    bsf DISPLAY_UPDATE_REQ, 0
122
 
123
    return
124
 
125
TEXT_WELCOME_0  STRING 13, 0x00, "Test DIN&DOUT"
126
TEXT_WELCOME_1  STRING 13, 0x40, "Module, Pin: "
127
 
128
;; --------------------------------------------------------------------------
129
;;  This function is called in the mainloop when no temporary message is shown
130
;;  on screen. Print the realtime messages here
131
;; --------------------------------------------------------------------------
132
USER_DISPLAY_Tick
133
    ;; display update requested from USER_SR_Service_Prepare on every LED change
134
    btfss   DISPLAY_UPDATE_REQ, 0
135
    return
136
    bcf DISPLAY_UPDATE_REQ, 0
137
 
138
    ;; print pin name
139
    movlw   0x4d
140
    call    MIOS_LCD_CursorSet
141
    TABLE_ADDR SRIO_PIN_NAMES_TABLE
142
    movf    SRIO_PIN_NUMBER, W
143
    mullw   SRIO_PIN_NAMES_LEN
144
    movf    PRODL, W
145
    addwf   TBLPTRL, F
146
    movf    PRODH, W
147
    addwfc  TBLPTRH, F
148
    movlw   SRIO_PIN_NAMES_LEN
878 tk 149
    call    MIOS_LCD_PrintPreconfString
150
 
151
 
152
    ;; send message to MIOS Terminal
153
    call    DEBUG_MSG_SendHeader
154
 
155
    movf    SRIO_PIN_NUMBER, W
156
    bz  USER_DISPLAY_Tick_DO
157
    addlw   -1
158
    bz  USER_DISPLAY_Tick_SC
159
    addlw   -1
160
    bz  USER_DISPLAY_Tick_RC
161
    rgoto   USER_DISPLAY_Tick_Fail
162
 
163
USER_DISPLAY_Tick_DO
164
    call    DEBUG_MSG_SendASMString
165
    db  "Pin J8:DO set to 5V, J8:SC/J9:SC and J8:RC/J9:RC set to 0V. ", 0
166
    rgoto   USER_DISPLAY_Tick_Cont
167
 
168
USER_DISPLAY_Tick_SC
169
    call    DEBUG_MSG_SendASMString
170
    db  "Pin J8:SC/J9:SC set to 5V, J8:DO and J8:RC/J9:RC set to 0V. ", 0
171
    rgoto   USER_DISPLAY_Tick_Cont
172
 
173
USER_DISPLAY_Tick_RC
174
    call    DEBUG_MSG_SendASMString
175
    db  "Pin J8:RC/J9:RC set to 5V, J8:DO and J8:SC/J9:SC set to 0V. ", 0
176
    rgoto   USER_DISPLAY_Tick_Cont
177
 
178
USER_DISPLAY_Tick_Fail
179
    call    DEBUG_MSG_SendASMString
180
    db  "Something unexpected happened! Please report to tk@midibox.org! ", 0
181
    ;;  rgoto   USER_DISPLAY_Tick_Cont
182
 
183
USER_DISPLAY_Tick_Cont
184
    BRA_IFSET MIOS_SRIO_PORT_DIN, MIOS_SRIO_PIN_DIN, ACCESS, USER_DISPLAY_Tick_DI1
185
USER_DISPLAY_Tick_DI0
186
    call    DEBUG_MSG_SendASMString
187
    db  "Pin J9:SI reads Logic-0 (ca. 0V).\n", 0
188
    goto    DEBUG_MSG_SendFooter
189
 
190
USER_DISPLAY_Tick_DI1  
191
    call    DEBUG_MSG_SendASMString
192
    db  "Pin J9:SI reads Logic-1 (ca. 5V).\n", 0
193
    goto    DEBUG_MSG_SendFooter
194
 
324 tk 195
 
196
 
197
SRIO_PIN_NAMES_LEN  EQU 2
198
SRIO_PIN_NAMES_NUM  EQU 3
199
SRIO_PIN_NAMES_TABLE
200
    db  "DO"
201
    db  "SC"
202
    db  "RC"
203
 
204
 
205
;; --------------------------------------------------------------------------
206
;;  This function is called by MIOS when a complete MIDI event has been received
207
;;  Input:
208
;;     o first  MIDI event byte in MIOS_PARAMETER1
209
;;     o second MIDI event byte in MIOS_PARAMETER2
210
;;     o third  MIDI event byte in MIOS_PARAMETER3
211
;; --------------------------------------------------------------------------
212
USER_MPROC_NotifyReceivedEvent
213
    ;; if modulation wheel received: set new pin
214
    movf    MIOS_PARAMETER1, W
215
    andlw   0xf0
216
    xorlw   0xb0
878 tk 217
    bnz USER_NotifyReceivedEvent_ChkNote
324 tk 218
    movf    MIOS_PARAMETER2, W
219
    xorlw   0x01
878 tk 220
    bnz USER_NotifyReceivedEvent_ChkNote
324 tk 221
 
222
    movf    MIOS_PARAMETER3, W
223
    movwf   SRIO_PIN_NUMBER
224
    movlw   SRIO_PIN_NAMES_NUM
225
    cpfslt  SRIO_PIN_NUMBER, ACCESS
226
    clrf SRIO_PIN_NUMBER
227
    bsf DISPLAY_UPDATE_REQ, 0
228
 
878 tk 229
    ;; set the pin depending on selected SRIO number
324 tk 230
    call    SRIO_SetPin
878 tk 231
    rgoto   USER_NotifyReceivedEvent_End
232
 
233
 
234
USER_NotifyReceivedEvent_ChkNote
235
    ;; alternative control via MIDI keyboard (Note On Events with velocity > 0)
236
    movf    MIOS_PARAMETER1, W
237
    andlw   0xf0
238
    xorlw   0x90
239
    bnz USER_NotifyReceivedEvent_End
240
    movf    MIOS_PARAMETER3, W
241
    bz  USER_NotifyReceivedEvent_End
242
    ;; normalize note to 0..11 range
243
    movf    MIOS_PARAMETER2, W
244
USER_NotifyReceivedEvent_NoteNor
245
    addlw   -12
246
    BRA_IFCLR WREG, 7, ACCESS, USER_NotifyReceivedEvent_NoteNor
247
    addlw   12      ; now in range 0..11
248
    movwf   SRIO_PIN_NUMBER
249
 
250
    movlw   SRIO_PIN_NAMES_NUM
251
    cpfslt  SRIO_PIN_NUMBER, ACCESS
252
    clrf SRIO_PIN_NUMBER
253
    bsf DISPLAY_UPDATE_REQ, 0
254
 
255
    ;; set the pin depending on selected SRIO number
256
    call    SRIO_SetPin
257
    ;;  rgoto   USER_NotifyReceivedEvent_End
258
 
324 tk 259
USER_NotifyReceivedEvent_End
260
    return
261
 
262
 
263
;; --------------------------------------------------------------------------
264
;;  This function is called by MIOS when a MIDI event has been received
265
;;  which has been specified in the CONFIG_MIDI_IN table
266
;;  Input:
267
;;     o number of entry in WREG
268
;;     o first  MIDI event byte in MIOS_PARAMETER1
269
;;     o second MIDI event byte in MIOS_PARAMETER2
270
;;     o third  MIDI event byte in MIOS_PARAMETER3
271
;; --------------------------------------------------------------------------
272
USER_MPROC_NotifyFoundEvent
273
    return
274
 
275
 
276
;; --------------------------------------------------------------------------
277
;;  This function is called by MIOS when a MIDI event has not been completly
278
;;  received within 2 seconds
279
;; --------------------------------------------------------------------------
280
USER_MPROC_NotifyTimeout
281
    return
282
 
283
 
284
;; --------------------------------------------------------------------------
285
;;  This function is called by MIOS when a MIDI byte has been received
286
;;  Input:
287
;;     o received MIDI byte in WREG and MIOS_PARAMETER1
288
;; --------------------------------------------------------------------------
289
USER_MPROC_NotifyReceivedByte
290
    return
291
 
292
;; --------------------------------------------------------------------------
293
;;  This function is called by MIOS before the transfer of a MIDI byte. 
294
;;  It can be used to monitor the Tx activity or to do any other actions
295
;;  (e.g. to switch a pin for multiplexed MIDI Outs) before the byte will 
296
;;  be sent.
297
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
298
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
299
;;  Input:
300
;;     o transmitted byte in WREG
301
;; --------------------------------------------------------------------------
302
USER_MIDI_NotifyTx
303
    return
304
 
305
;; --------------------------------------------------------------------------
306
;;  This function is called by MIOS when a MIDI byte has been received.
307
;;  It can be used to monitor the Rx activity or to do any action - e.g.
308
;;  to react on realtime events like MIDI clock (0xf8) with a minimum latency
309
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
310
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
311
;;  Input:
312
;;     o received byte in WREG
313
;; --------------------------------------------------------------------------
314
USER_MIDI_NotifyRx
315
    return
316
 
317
;; --------------------------------------------------------------------------
318
;;  This function is called by MIOS when an button has been toggled
319
;;  Input:
320
;;     o Button number in WREG and MIOS_PARAMETER1
321
;;     o Button value MIOS_PARAMETER2:
322
;;       - 1 if button has been released (=5V)
323
;;       - 0 if button has been pressed (=0V)
324
;; --------------------------------------------------------------------------
325
USER_DIN_NotifyToggle
326
    return
327
 
328
 
329
;; --------------------------------------------------------------------------
330
;;  This function is called by MIOS when an encoder has been moved
331
;;  Input:
332
;;     o Encoder number in WREG and MIOS_PARAMETER1
333
;;     o signed incrementer value in MIOS_PARAMETER2:
334
;;       - is positive when encoder has been turned clockwise
335
;;       - is negative when encoder has been turned counter clockwise
336
;; --------------------------------------------------------------------------
337
USER_ENC_NotifyChange
338
    return
339
 
340
 
341
;; --------------------------------------------------------------------------
342
;;  This function is called by MIOS before the shift register are loaded
343
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
344
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible
345
;; --------------------------------------------------------------------------
346
USER_SR_Service_Prepare
347
    return
348
 
349
 
350
;; --------------------------------------------------------------------------
351
;;  This function is called by MIOS after the shift register have been loaded
352
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
353
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible
354
;; --------------------------------------------------------------------------
355
USER_SR_Service_Finish
356
    return
357
 
358
;; --------------------------------------------------------------------------
359
;;  This function is called by MIOS when a pot has been moved
360
;;  Input:
361
;;     o Pot number in WREG and MIOS_PARAMETER1
362
;;     o LSB value in MIOS_PARAMETER2
363
;;     o MSB value in MIOS_PARAMETER3
364
;; --------------------------------------------------------------------------
365
USER_AIN_NotifyChange
366
    return
367
 
368
 
369
 
370
;; --------------------------------------------------------------------------
371
;;  This function sets a DIN/DOUT pin depending on SRIO_PIN_NUMBER
372
;; --------------------------------------------------------------------------
373
MIOS_SRIO_LAT_SCLK  EQU LATD    ; Pin D.3
374
MIOS_SRIO_PIN_SCLK  EQU 3
375
MIOS_SRIO_LAT_RCLK  EQU LATD    ; Pin D.2
376
MIOS_SRIO_PIN_RCLK  EQU 2
377
MIOS_SRIO_PORT_DIN  EQU PORTD   ; Pin D.1
378
MIOS_SRIO_PIN_DIN   EQU 1
379
MIOS_SRIO_LAT_DOUT  EQU LATD    ; Pin D.0
380
MIOS_SRIO_PIN_DOUT  EQU 0
381
 
382
SRIO_SetPin
383
    ;; clear the pins
384
    bcf MIOS_SRIO_LAT_DOUT, MIOS_SRIO_PIN_DOUT
385
    bcf MIOS_SRIO_LAT_SCLK, MIOS_SRIO_PIN_SCLK
386
    bcf MIOS_SRIO_LAT_RCLK, MIOS_SRIO_PIN_RCLK
387
 
388
    ;; set the selected pin
389
    movf    SRIO_PIN_NUMBER, W
390
    JUMPTABLE_2BYTES 3  ; entries
391
    rgoto   SRIO_SetPin0
392
    rgoto   SRIO_SetPin1
393
    rgoto   SRIO_SetPin2
394
 
395
SRIO_SetPin0
396
    bsf MIOS_SRIO_LAT_DOUT, MIOS_SRIO_PIN_DOUT
397
    return
398
 
399
SRIO_SetPin1
400
    bsf MIOS_SRIO_LAT_SCLK, MIOS_SRIO_PIN_SCLK
401
    return
402
 
403
SRIO_SetPin2
404
    bsf MIOS_SRIO_LAT_RCLK, MIOS_SRIO_PIN_RCLK
405
    return
406
 
407
    END