Subversion Repositories svn.mios

Rev

Rev 324 | 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->LCD Module Interconnection Test
4
;
5
; ==========================================================================
6
;
7
;  Copyright 2006 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
    return
55
 
56
 
57
;; --------------------------------------------------------------------------
58
;;  This function is called by MIOS in the mainloop when nothing else is to do
59
;; --------------------------------------------------------------------------
60
USER_Tick
61
    return
62
 
63
 
64
;; --------------------------------------------------------------------------
65
;;  This function is periodically called by MIOS. The frequency has to be
66
;;  initialized with MIOS_Timer_Set
67
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
68
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
69
;; --------------------------------------------------------------------------
70
USER_Timer
71
    return
72
 
73
 
74
;; --------------------------------------------------------------------------
75
;;  This function is called by MIOS when a debug command has been received
76
;;  via SysEx
77
;;  Input:
78
;;     o WREG, MIOS_PARAMETER1, MIOS_PARAMETER2, MIOS_PARAMETER3 like
79
;;       specified in the debug command
80
;;  Output:
81
;;     o return values WREG, MIOS_PARAMETER1, MIOS_PARAMETER2, MIOS_PARAMETER3
82
;; --------------------------------------------------------------------------
83
USER_MPROC_DebugTrigger
84
    return
85
 
86
 
87
;; --------------------------------------------------------------------------
88
;;  This function is called by MIOS when the display content should be 
89
;;  initialized. Thats the case during startup and after a temporary message
90
;;  has been printed on the screen
91
;; --------------------------------------------------------------------------
92
USER_DISPLAY_Init
93
    call    MIOS_LCD_Clear
94
 
95
    TABLE_ADDR TEXT_WELCOME_0
96
    call    MIOS_LCD_PrintString
97
    call    MIOS_LCD_PrintString
98
 
878 tk 99
    call    DEBUG_MSG_SendHeader
100
    movlw   '\n'
101
    call    DEBUG_MSG_SendChar
102
    call    DEBUG_MSG_SendFooter
103
 
104
    call    DEBUG_MSG_SendHeader
105
    call    DEBUG_MSG_SendASMString
106
    db  "LCD Interconnection Test\n", 0
107
    call    DEBUG_MSG_SendFooter
108
 
109
    call    DEBUG_MSG_SendHeader
110
    call    DEBUG_MSG_SendASMString
111
    db  "========================\n", 0
112
    call    DEBUG_MSG_SendFooter
113
 
114
    call    DEBUG_MSG_SendHeader
115
    call    DEBUG_MSG_SendASMString
116
    db  "Please play a note on any MIDI channel.\n", 0
117
    call    DEBUG_MSG_SendFooter
118
 
324 tk 119
    bsf DISPLAY_UPDATE_REQ, 0
120
 
121
    return
122
 
123
TEXT_WELCOME_0  STRING 16, 0x00, "Test LCD X-Cons."
124
TEXT_WELCOME_1  STRING  5, 0x40, "Pin: "
125
 
126
;; --------------------------------------------------------------------------
127
;;  This function is called in the mainloop when no temporary message is shown
128
;;  on screen. Print the realtime messages here
129
;; --------------------------------------------------------------------------
130
USER_DISPLAY_Tick
131
    ;; display update requested from USER_SR_Service_Prepare on every LED change
132
    btfss   DISPLAY_UPDATE_REQ, 0
133
    return
134
    bcf DISPLAY_UPDATE_REQ, 0
135
 
136
    ;; write static message again (could have been cleared by last E line toggling)
137
    TABLE_ADDR TEXT_WELCOME_0
138
    call    MIOS_LCD_PrintString
139
    call    MIOS_LCD_PrintString
140
 
141
    ;; print pin name
142
    movlw   0x40 + 5
143
    call    MIOS_LCD_CursorSet
144
    TABLE_ADDR LCD_PIN_NAMES_TABLE
145
    movf    LCD_PIN_NUMBER, W
146
    mullw   LCD_PIN_NAMES_LEN
147
    movf    PRODL, W
148
    addwf   TBLPTRL, F
149
    movf    PRODH, W
150
    addwfc  TBLPTRH, F
151
    movlw   LCD_PIN_NAMES_LEN
152
    call    MIOS_LCD_PrintPreconfString
153
 
878 tk 154
 
155
    ;; send message to MIOS Terminal
156
    call    DEBUG_MSG_SendHeader
157
    call    DEBUG_MSG_SendASMString
158
    db  "Pin '", 0
159
 
160
    TABLE_ADDR LCD_PIN_NAMES_TABLE
161
    movf    LCD_PIN_NUMBER, W
162
    mullw   LCD_PIN_NAMES_LEN
163
    movf    PRODL, W
164
    addwf   TBLPTRL, F
165
    movf    PRODH, W
166
    addwfc  TBLPTRH, F
167
 
168
    ;; always two chars
169
    tblrd*+
170
    movf    TABLAT, W
171
    call    DEBUG_MSG_SendChar
172
    tblrd*+
173
    movf    TABLAT, W
174
    call    DEBUG_MSG_SendChar
175
 
176
    call    DEBUG_MSG_SendASMString
177
    db  "' of MBHP_CORE::J15 set to 5V, all other data/control pins set to 0V", 0
178
    call    DEBUG_MSG_SendFooter
179
 
180
    ;; IMPORTANT!!!
181
    ;; Since a LCD message could overwrite the data/address/control
182
    ;; line value, we update the pins again
324 tk 183
    goto    LCD_SetPin
184
 
185
 
186
 
187
LCD_PIN_NAMES_LEN   EQU 2
188
LCD_PIN_NAMES_NUM   EQU 11
189
LCD_PIN_NAMES_TABLE
190
    db  "D0"
191
    db  "D1"
192
    db  "D2"
193
    db  "D3"
194
    db  "D4"
195
    db  "D5"
196
    db  "D6"
197
    db  "D7"
198
    db  "E "
199
    db  "RW"
200
    db  "RS"
201
 
202
 
203
;; --------------------------------------------------------------------------
204
;;  This function is called by MIOS when a complete MIDI event has been received
205
;;  Input:
206
;;     o first  MIDI event byte in MIOS_PARAMETER1
207
;;     o second MIDI event byte in MIOS_PARAMETER2
208
;;     o third  MIDI event byte in MIOS_PARAMETER3
209
;; --------------------------------------------------------------------------
210
USER_MPROC_NotifyReceivedEvent
211
    ;; if modulation wheel received: set new pin
212
    movf    MIOS_PARAMETER1, W
213
    andlw   0xf0
214
    xorlw   0xb0
878 tk 215
    bnz USER_NotifyReceivedEvent_ChkNote
324 tk 216
    movf    MIOS_PARAMETER2, W
217
    xorlw   0x01
878 tk 218
    bnz USER_NotifyReceivedEvent_ChkNote
324 tk 219
 
220
    movf    MIOS_PARAMETER3, W
221
    movwf   LCD_PIN_NUMBER
222
    movlw   LCD_PIN_NAMES_NUM
223
    cpfslt  LCD_PIN_NUMBER, ACCESS
224
    clrf LCD_PIN_NUMBER
225
    bsf DISPLAY_UPDATE_REQ, 0
226
 
878 tk 227
    ;; set the pin depending on selected LCD number
324 tk 228
    call    LCD_SetPin
878 tk 229
    rgoto   USER_NotifyReceivedEvent_End
230
 
231
 
232
USER_NotifyReceivedEvent_ChkNote
233
    ;; alternative control via MIDI keyboard (Note On Events with velocity > 0)
234
    movf    MIOS_PARAMETER1, W
235
    andlw   0xf0
236
    xorlw   0x90
237
    bnz USER_NotifyReceivedEvent_End
238
    movf    MIOS_PARAMETER3, W
239
    bz  USER_NotifyReceivedEvent_End
240
    ;; normalize note to 0..11 range
241
    movf    MIOS_PARAMETER2, W
242
USER_NotifyReceivedEvent_NoteNor
243
    addlw   -12
244
    BRA_IFCLR WREG, 7, ACCESS, USER_NotifyReceivedEvent_NoteNor
245
    addlw   12      ; now in range 0..11
246
    movwf   LCD_PIN_NUMBER
247
 
248
    movlw   LCD_PIN_NAMES_NUM
249
    cpfslt  LCD_PIN_NUMBER, ACCESS
250
    clrf LCD_PIN_NUMBER
251
    bsf DISPLAY_UPDATE_REQ, 0
252
 
253
    ;; set the pin depending on selected LCD number
254
    call    LCD_SetPin
255
    ;;  rgoto   USER_NotifyReceivedEvent_End
256
 
324 tk 257
USER_NotifyReceivedEvent_End
258
    return
259
 
260
 
261
;; --------------------------------------------------------------------------
262
;;  This function is called by MIOS when a MIDI event has been received
263
;;  which has been specified in the CONFIG_MIDI_IN table
264
;;  Input:
265
;;     o number of entry in WREG
266
;;     o first  MIDI event byte in MIOS_PARAMETER1
267
;;     o second MIDI event byte in MIOS_PARAMETER2
268
;;     o third  MIDI event byte in MIOS_PARAMETER3
269
;; --------------------------------------------------------------------------
270
USER_MPROC_NotifyFoundEvent
271
    return
272
 
273
 
274
;; --------------------------------------------------------------------------
275
;;  This function is called by MIOS when a MIDI event has not been completly
276
;;  received within 2 seconds
277
;; --------------------------------------------------------------------------
278
USER_MPROC_NotifyTimeout
279
    return
280
 
281
 
282
;; --------------------------------------------------------------------------
283
;;  This function is called by MIOS when a MIDI byte has been received
284
;;  Input:
285
;;     o received MIDI byte in WREG and MIOS_PARAMETER1
286
;; --------------------------------------------------------------------------
287
USER_MPROC_NotifyReceivedByte
288
    return
289
 
290
;; --------------------------------------------------------------------------
291
;;  This function is called by MIOS before the transfer of a MIDI byte. 
292
;;  It can be used to monitor the Tx activity or to do any other actions
293
;;  (e.g. to switch a pin for multiplexed MIDI Outs) before the byte will 
294
;;  be sent.
295
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
296
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
297
;;  Input:
298
;;     o transmitted byte in WREG
299
;; --------------------------------------------------------------------------
300
USER_MIDI_NotifyTx
301
    return
302
 
303
;; --------------------------------------------------------------------------
304
;;  This function is called by MIOS when a MIDI byte has been received.
305
;;  It can be used to monitor the Rx activity or to do any action - e.g.
306
;;  to react on realtime events like MIDI clock (0xf8) with a minimum latency
307
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
308
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible!
309
;;  Input:
310
;;     o received byte in WREG
311
;; --------------------------------------------------------------------------
312
USER_MIDI_NotifyRx
313
    return
314
 
315
;; --------------------------------------------------------------------------
316
;;  This function is called by MIOS when an button has been toggled
317
;;  Input:
318
;;     o Button number in WREG and MIOS_PARAMETER1
319
;;     o Button value MIOS_PARAMETER2:
320
;;       - 1 if button has been released (=5V)
321
;;       - 0 if button has been pressed (=0V)
322
;; --------------------------------------------------------------------------
323
USER_DIN_NotifyToggle
324
    return
325
 
326
 
327
;; --------------------------------------------------------------------------
328
;;  This function is called by MIOS when an encoder has been moved
329
;;  Input:
330
;;     o Encoder number in WREG and MIOS_PARAMETER1
331
;;     o signed incrementer value in MIOS_PARAMETER2:
332
;;       - is positive when encoder has been turned clockwise
333
;;       - is negative when encoder has been turned counter clockwise
334
;; --------------------------------------------------------------------------
335
USER_ENC_NotifyChange
336
    return
337
 
338
 
339
;; --------------------------------------------------------------------------
340
;;  This function is called by MIOS before the shift register are loaded
341
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
342
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible
343
;; --------------------------------------------------------------------------
344
USER_SR_Service_Prepare
345
    return
346
 
347
 
348
;; --------------------------------------------------------------------------
349
;;  This function is called by MIOS after the shift register have been loaded
350
;;  Note that this is an interrupt service routine! Use FSR2 instead of FSR0
351
;;  and IRQ_TMPx instead of TMPx -- and make the routine as fast as possible
352
;; --------------------------------------------------------------------------
353
USER_SR_Service_Finish
354
    return
355
 
356
;; --------------------------------------------------------------------------
357
;;  This function is called by MIOS when a pot has been moved
358
;;  Input:
359
;;     o Pot number in WREG and MIOS_PARAMETER1
360
;;     o LSB value in MIOS_PARAMETER2
361
;;     o MSB value in MIOS_PARAMETER3
362
;; --------------------------------------------------------------------------
363
USER_AIN_NotifyChange
364
    return
365
 
366
 
367
 
368
;; --------------------------------------------------------------------------
369
;;  This function sets a LCD pin depending on LCD_PIN_NUMBER
370
;; --------------------------------------------------------------------------
371
;; Pins of LC-Display
372
MIOS_CLCD_LAT_D     EQU LATB    ; Pin B.7-0
373
MIOS_CLCD_PORT_D    EQU     PORTB
374
MIOS_CLCD_TRIS_D    EQU     TRISB
375
 
376
MIOS_CLCD_LAT_E     EQU LATD
377
MIOS_CLCD_PIN_E     EQU 7       ; Pin D.7
378
MIOS_CLCD_LAT_RW    EQU     LATD
379
MIOS_CLCD_PIN_RW    EQU     6               ; Pin D.6
380
MIOS_CLCD_LAT_RS    EQU     LATD
381
MIOS_CLCD_PIN_RS    EQU     5               ; Pin D.5
382
 
383
LCD_SetPin
384
    ;; clear the pins
385
    clrf    MIOS_CLCD_LAT_D
386
    bcf MIOS_CLCD_LAT_E, MIOS_CLCD_PIN_E
387
    bcf MIOS_CLCD_LAT_RW, MIOS_CLCD_PIN_RW
388
    bcf MIOS_CLCD_LAT_RS, MIOS_CLCD_PIN_RS
389
    ;; enable output driver of data pins
390
    clrf    MIOS_CLCD_TRIS_D
391
 
392
    ;; set the selected pin
393
    movf    LCD_PIN_NUMBER, W
394
    JUMPTABLE_2BYTES 11 ; entries
395
    rgoto   LCD_SetPin0
396
    rgoto   LCD_SetPin1
397
    rgoto   LCD_SetPin2
398
    rgoto   LCD_SetPin3
399
    rgoto   LCD_SetPin4
400
    rgoto   LCD_SetPin5
401
    rgoto   LCD_SetPin6
402
    rgoto   LCD_SetPin7
403
    rgoto   LCD_SetPin8
404
    rgoto   LCD_SetPin9
405
    rgoto   LCD_SetPin10
406
 
407
LCD_SetPin0
408
    bsf MIOS_CLCD_LAT_D, 0
409
    return
410
 
411
LCD_SetPin1
412
    bsf MIOS_CLCD_LAT_D, 1
413
    return
414
 
415
LCD_SetPin2
416
    bsf MIOS_CLCD_LAT_D, 2
417
    return
418
 
419
LCD_SetPin3
420
    bsf MIOS_CLCD_LAT_D, 3
421
    return
422
 
423
LCD_SetPin4
424
    bsf MIOS_CLCD_LAT_D, 4
425
    return
426
 
427
LCD_SetPin5
428
    bsf MIOS_CLCD_LAT_D, 5
429
    return
430
 
431
LCD_SetPin6
432
    bsf MIOS_CLCD_LAT_D, 6
433
    return
434
 
435
LCD_SetPin7
436
    bsf MIOS_CLCD_LAT_D, 7
437
    return
438
 
439
LCD_SetPin8
440
    bsf MIOS_CLCD_LAT_E, MIOS_CLCD_PIN_E
441
    return
442
 
443
LCD_SetPin9
444
    bsf MIOS_CLCD_LAT_RW, MIOS_CLCD_PIN_RW
445
    return
446
 
447
LCD_SetPin10
448
    bsf MIOS_CLCD_LAT_RS, MIOS_CLCD_PIN_RS
449
    return
450
 
451
 
452
    END