1 | $regfile = "m8def.dat" ' ATMEGA8
|
2 | $crystal = 8000000 ' 8 MHz
|
3 | $baud = 31250 ' MIDI-Baudrate (31,25kBit)
|
4 |
|
5 |
|
6 | Config Adc = Single , Prescaler = Auto , Reference = Avcc
|
7 | Start Adc
|
8 |
|
9 |
|
10 | Taster Alias Pind
|
11 | Taster1 Alias Pinb
|
12 |
|
13 |
|
14 | Ddrd = &B00000010 ' Output auf TXD (PD1) pin3
|
15 |
|
16 | Portd = &B11111101 ' Pull-Up für Taster
|
17 | Portb = &B11111111
|
18 |
|
19 |
|
20 |
|
21 | Dim Note As Byte
|
22 | Dim Velocity As Byte
|
23 | Dim Befehl As Byte
|
24 | Dim Wert As Word
|
25 | Dim Noteon As Byte
|
26 | Dim Noteoff As Byte
|
27 | Dim Controlchange As Byte
|
28 | Dim Keydown(8)as Byte ' Tasten-Merker
|
29 | Dim Keydown1(8)as Byte
|
30 | Dim Fader(8) As Byte
|
31 | Dim Count As Byte ' ADC Werte (Fader)
|
32 |
|
33 |
|
34 | Noteon = &H90 'channel 1
|
35 | Noteoff = &H80
|
36 | Controlchange = &HB0 'CC1
|
37 |
|
38 |
|
39 | Declare Sub Sendmidi(byval Befehl As Byte , Wert As Word)
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | Do
|
45 | For Count = 0 To 7 Step 1
|
46 |
|
47 |
|
48 | 'Tasterreihe Port D
|
49 |
|
50 | If Taster.count = 0 Then
|
51 | If Keydown(count + 1) = 1 Then
|
52 |
|
53 | Befehl = Noteon
|
54 | Velocity = &H7E '0-7F
|
55 | Wert = Count + 1 'Note 1-8
|
56 | Shift Wert , Left , 8 'Schieben (Byte zu Word)
|
57 | Wert = Wert + Velocity
|
58 |
|
59 | If Count = 1 Then 'PD1 überspringen (UART)
|
60 | Else
|
61 | Call Sendmidi(befehl , Wert)
|
62 | End If
|
63 |
|
64 | Keydown(count + 1) = 0 'Tasten merker
|
65 |
|
66 | End If
|
67 | Else
|
68 | If Keydown(count + 1) = 0 Then
|
69 |
|
70 | Befehl = Noteoff
|
71 | Velocity = &H00 '0-7F
|
72 | Wert = Count + 1 'Note 1-8
|
73 | Shift Wert , Left , 8 'Schieben (Byte zu Word)
|
74 | Wert = Wert + Velocity
|
75 |
|
76 | If Count = 1 Then 'PD1 überspringen (UART)
|
77 | Else
|
78 | Call Sendmidi(befehl , Wert)
|
79 | End If
|
80 |
|
81 | Keydown(count + 1) = 1 'Tasten merker
|
82 |
|
83 | End If
|
84 | End If
|
85 |
|
86 |
|
87 | 'Tasterreihe Port B
|
88 |
|
89 | If Taster1.count = 0 Then
|
90 | If Keydown1(count + 1) = 1 Then
|
91 | Befehl = Noteon
|
92 | Velocity = &H7E
|
93 | Wert = Count + 9 'Note 9-16
|
94 | Shift Wert , Left , 8
|
95 | Wert = Wert + Velocity
|
96 | Call Sendmidi(befehl , Wert)
|
97 | Keydown1(count + 1) = 0
|
98 | End If
|
99 | Else
|
100 | If Keydown1(count + 1) = 0 Then
|
101 | Befehl = Noteoff
|
102 | Velocity = &H00
|
103 | Wert = Count + 9
|
104 | Shift Wert , Left , 8
|
105 | Wert = Wert + Velocity
|
106 | Call Sendmidi(befehl , Wert)
|
107 | Keydown1(count + 1) = 1
|
108 | End If
|
109 | End If
|
110 |
|
111 |
|
112 | 'Fader Port C
|
113 |
|
114 | If Fader(count + 1) <> Getadc(count) Then
|
115 | Befehl = Controlchange
|
116 | Velocity = Getadc(count)
|
117 | Shift Velocity , Right , 3
|
118 | Wert = Count + 8
|
119 | Shift Wert , Left , 8
|
120 | Wert = Wert + Velocity
|
121 | Call Sendmidi(befehl , Wert)
|
122 | End If
|
123 |
|
124 | Fader(count + 1) = Getadc(count)
|
125 |
|
126 | Next Count
|
127 |
|
128 |
|
129 | Loop
|
130 | End
|
131 |
|
132 | Sub Sendmidi(byval Befehl As Byte , Wert As Word)
|
133 |
|
134 | Print Hex(befehl);
|
135 | Print Hex(wert);
|
136 |
|
137 |
|
138 | Waitms 20
|
139 |
|
140 | End Sub
|