Schritt 6: Der Code.
'****************************************************************"* Name: ohne Titel. BAS *
' * Autor: Matthew Reid *
"* Hinweis: Copyright (c) 2012 [Wählen Sie Ansicht... EDITOR-OPTIONEN] *
' *: Alle Rechte vorbehalten *
'* Date : 9/5/2012 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
Anhalten von 300
sind "modedefs.bas"
#CONFIG
__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HS_1H & _FCMEN_ON_1H & _IESO_ON_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_3_2L & _VREGEN_OFF_2L
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_256_2H
__CONFIG _CONFIG3H, _MCLRE_OFF_3H & _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
#endconfig
definieren Sie OSC 20
OSCCON = % 00001000
"Hardware serielle Schnittstelle einrichten
definieren Sie HSER_RCSTA 90H
definieren Sie HSER_TXSTA 24H
definieren Sie HSER_BAUD 31250
"i2c Anschlüsse
SDA Var PORTB.2
SCL Var PORTB.1
"Variablen-Taste
"Spalte 1 Variablen
buttonval1 Var byte
bouncecheck1 Var byte
buttonstate1 Var Bit [4]
Ich Var Byte
Wert1 Var byte
' Spalte 2 Variablen
buttonval2 Var byte
bouncecheck2 Var byte
buttonstate2 Var Bit [4]
Value2 Var byte
' Spalte 3 Variablen
buttonval3 Var byte
bouncecheck3 Var byte
buttonstate3 Var Bit [4]
Wert3 Var byte
"Spalte 4variables
buttonval4 Var byte
bouncecheck4 Var byte
buttonstate4 Var Bit [4]
Wert4 Var byte
"Bankchange-Variable
Hinterland Var bit
Downstate Var bit
j Var Byte: j = 1
C Var byte
' Variablen für ein d (IC2)
ein Var Byte [8]
zwei Var Byte [8]
drei Var Wort [8]: 3 = 0
Schwelle Var Wort: Schwelle = 50
Prevpotval Var Byte [8]
Prevadval Var Wort [8]
Currentadval Var Wort [8]
' Variablen für ein d (IC1)
One1 Var Byte [8]
zwei1 Var Byte [8]
three1 Var Wort [8]: 3 = 0
prevpotval1 Var Byte [8]
prevadval1 Var Wort [8]
currentadval1 Var Wort [8]
"Richtung port
Trisa = % 00000000
Trisb = % 00000001
Trisc = % 10110110
"aktivieren Sie RC4 und RC5
Ucon.3 = 0
ucfg.3 = 1
"deaktivieren Sie interne A bis D
adcon0 = % 00111100
adcon1 = % 00001111
"schalten Sie lcd und stellen Sie Helligkeit auf max
Anhalten von 1000
Serout PORTB.3, N9600, [$ 1 b, $2a, $FF]
Serout PORTB.3,N9600,[$1b,$30]
Serout PORTB.3,N9600,[$1b,$2a,200]
Serout PORTB.3,N9600,[$1b,$46]
Serout PORTB.3,N9600,[$fe,$80]
Serout PORTB.3,N9600,["Midi Pad v1_1"]
Serout PORTB.3,N9600,[$fe,$c0]
Serout PORTB.3,N9600,["Matt Reid 2012"]
"Flash-Intro
"rot
Porta.0 = 1
Porta.1 = 0
Porta.2 = 0
Anhalten von 400
"grün
Porta.0 = 0
Porta.1 = 1
Porta.2 = 0
Anhalten von 400
"blau
Porta.0 = 0
Porta.1 = 0
Porta.2 = 1
Anhalten von 400
"lila
Porta.0 = 1
Porta.1 = 0
Porta.2 = 1
Anhalten von 400
"weiß
Porta.0 = 1
Porta.1 = 1
Porta.2 = 1
Anhalten von 400
"Cyan
Porta.0 = 0
Porta.1 = 1
Porta.2 = 1
Anhalten von 400
'_________________________
"Bank aus Eeprom lesen
Lesen Sie die 5, j
Mainloop:
GOSUB-bankchange
GOSUB keypress
GOSUB-potread
GOSUB RGB
GOTO mainloop
Bankchange:
"bank up
Wenn portc.2 = 1 & Upstate = 1 then
j = j + 1
Wenn j > 8 dann
j = 1
ENDIF
"alle Notizen löschen
für i = 0 bis 128
Hserout [$92, i, 0]
nächsten ich
"Bank Änderung in Eeprom schreiben
Schreiben Sie 5, j
Upstate = 0
ENDIF
Wenn portc.2 = 0 & Upstate = 0 then
Upstate = 1
ENDIF
"bank nach unten
Wenn portc.1 = 1 & Downstate = 1 then
j = j - 1
Wenn j < 1 dann
j = 8
ENDIF
"alle Notizen löschen
für i = 0 bis 128
Hserout [$92, i, 0]
nächsten ich
"Bank Änderung in Eeprom schreiben
Schreiben Sie 5, j
Downstate = 0
ENDIF
Wenn portc.1 = 0 & Downstate = 0 then
Downstate = 1
ENDIF
"Bank anzeigen
Serout PORTB.3, N9600, [$Fe, $c0]
Serout PORTB.3, N9600, ["BANK", "", #j, ""]
Wenn j = 1 then
c = 0
ENDIF
Wenn j = 2 dann
c = 16
ENDIF
Wenn j = 3 then
c = 32
ENDIF
Wenn j = 4 then
c = 48
ENDIF
Wenn j = 5 then
c = 64
ENDIF
Wenn j = 6 then
c = 80
ENDIF
Wenn j = 7 then
c = 96
ENDIF
Wenn j = 8 dann
c = 112
ENDIF
Rückkehr
Potread:
"adc Potentiometer Sachen---
"lesen Sie ic2
für i = 1 bis 8
drei [i] = 0
Wenn ich = 1 then
i2cwrite SDA, SCL, % 00010000, [% 10001100]
ENDIF
Wenn ich dann 2 =
i2cwrite SDA, SCL, % 00010000, [% 11001100]
ENDIF
Wenn ich dann 3 =
i2cwrite SDA, SCL, % 00010000, [% 10011100]
ENDIF
Wenn ich dann 4 =
i2cwrite SDA, SCL, % 00010000, [% 11011100]
ENDIF
Wenn ich dann 5 =
i2cwrite SDA, SCL, % 00010000, [% 10101100]
ENDIF
Wenn ich dann 6 =
i2cwrite SDA, SCL, % 00010000, [% 11101100]
ENDIF
Wenn ich dann 7 =
i2cwrite SDA, SCL, % 00010000, [% 10111100]
ENDIF
Wenn ich dann 8 =
i2cwrite SDA, SCL, % 00010000, [% 11111100]
ENDIF
"Diese Pause ist wichtig, um zu verhindern, dass der adc herumspringen
4 anhalten
i2cread SDA, SCL, % 00010001, [ein [i], zwei [i]]
drei [i] = ein [i] | drei [i]
drei [i] = drei [i] << 4
zwei [i] = zwei [i] >> 4
drei [i] = zwei [i] | drei [i]
Currentadval [i] = drei [i]
"anhalten 10
drei [i] = drei [i] * 128
drei [i] = div32 4095
Wenn abs (Currentadval [i] - prevadval[i]) > = Schwelle dann
Hserout [$B2, 13 + i, drei [i]]
Prevpotval [i] = drei [i]
Prevadval [i] = Currentadval [i]
"zeigen Sie eine d Wert
Serout PORTB.3, N9600, [$Fe, $80]
Serout PORTB.3, N9600, [#178, "", #(13+i), "", #three [i], ""]
ENDIF
nächsten ich
"ic1 zu lesen
für i = 1 bis 8
three1 [i] = 0
Wenn ich = 1 then
i2cwrite SDA, SCL, % 00010100, [% 10001100]
ENDIF
Wenn ich dann 2 =
i2cwrite SDA, SCL, % 00010100, [% 11001100]
ENDIF
Wenn ich dann 3 =
i2cwrite SDA, SCL, % 00010100, [% 10011100]
ENDIF
Wenn ich dann 4 =
i2cwrite SDA, SCL, % 00010100, [% 11011100]
ENDIF
Wenn ich dann 5 =
i2cwrite SDA, SCL, % 00010100, [% 10101100]
ENDIF
Wenn ich dann 6 =
i2cwrite SDA, SCL, % 00010100, [% 11101100]
ENDIF
Wenn ich dann 7 =
i2cwrite SDA, SCL, % 00010100, [% 10111100]
ENDIF
Wenn ich dann 8 =
i2cwrite SDA, SCL, % 00010100, [% 11111100]
ENDIF
"Diese Pause ist wichtig, um zu verhindern, dass der adc herumspringen
4 anhalten
i2cread SDA, SCL, % 00010101, [one1 [i] zwei1 [i]]
three1 [i] = regiert1 [i] | three1 [i]
three1 [i] = three1 [i] << 4
zwei1 [i] = zwei1 [i] >> 4
three1 [i] = zwei1 [i] | three1 [i]
currentadval1 [i] = three1 [i]
"anhalten 10
three1 [i] = three1 [i] * 128
three1 [i] = div32 4095
Wenn abs (currentadval1 [i] - prevadval1[i]) > = Schwelle dann
Hserout [$B2, 13 + i, three1 [i]]
prevpotval1 [i] = three1 [i]
prevadval1 [i] = currentadval1 [i]
"zeigen Sie eine d Wert
Serout PORTB.3, N9600, [$Fe, $80]
Serout PORTB.3, N9600, [#178, "", #(21+i), "", #three1 [i], ""]
ENDIF
nächsten ich
Rückkehr
Tastendruck:
"Code-Taste
'set column 1--------------------------------------------------------------------
PORTB.4 = 0
PORTB.5 = 1
PORTB.6 = 1
PORTB.7 = 1
buttonval1 = 0
bouncecheck1 = 0
buttonval1.0 = portc.4
buttonval1.1 = portc.5
buttonval1.2 = portc.7
buttonval1.3 = portb.0
1 Pause
bouncecheck1.0 = portc.4
bouncecheck1.1 = portc.5
bouncecheck1.2 = portc.7
bouncecheck1.3 = portb.0
Wenn buttonval1 = bouncecheck1 then
für i = 0 zu 3' Zählung von 0 bis 3
Wert1 = buttonval1 >> ich
Wenn value1.0 = 1 & buttonstate1 [i] = 1 then
Hserout [$92, c + i, 0]
Serout PORTB.3, N9600, [$Fe, $80]
Serout PORTB.3, N9600, [#146,"", #(c + i), "", #0, ""]
buttonstate1 [i] = 0
ENDIF
Wenn value1.0 = 0 & buttonstate1 [i] = 0 then
Hserout [$92, c + i, 100]
Serout PORTB.3, N9600, [$Fe, $80]
Serout PORTB.3, N9600, [#146,"", #(c + i), "", #100, ""]
buttonstate1 [i] = 1
ENDIF
nächsten ich
ENDIF
'set column 2--------------------------------------------------------------------
PORTB.4 = 1
PORTB.5 = 0
PORTB.6 = 1
PORTB.7 = 1
buttonval2 = 0
bouncecheck2 = 0
buttonval2.0 = portc.4
buttonval2.1 = portc.5
buttonval2.2 = portc.7
buttonval2.3 = portb.0
1 Pause
bouncecheck2.0 = portc.4
bouncecheck2.1 = portc.5
bouncecheck2.2 = portc.7
bouncecheck2.3 = portb.0
Wenn buttonval2 = bouncecheck2 then
für i = 0 zu 3' Zählung von 0 bis 3
Value2 = buttonval2 >> ich
Wenn value2.0 = 1 & buttonstate2 [i] = 1 then
Hserout [$92 C + 4 + i, 0]
Serout PORTB.3, N9600, [$Fe, $80]
Serout PORTB.3, N9600, [#146,"", #(C + 4 + i), "", #0, ""]
buttonstate2 [i] = 0
ENDIF
Wenn value2.0 = 0 & buttonstate2 [i] = 0 then
Hserout [$92 C + 4 + ich, 100]
Serout PORTB.3, N9600, [$Fe, $80]
Serout PORTB.3, N9600, [#146,"", #(C + 4 + i), "", #100, ""]
buttonstate2 [i] = 1
ENDIF
nächsten ich
ENDIF
'set column 3--------------------------------------------------------------------
PORTB.4 = 1
PORTB.5 = 1
PORTB.6 = 0
PORTB.7 = 1
buttonval3 = 0
bouncecheck3 = 0
buttonval3.0 = portc.4
buttonval3.1 = portc.5
buttonval3.2 = portc.7
buttonval3.3 = portb.0
1 Pause
bouncecheck3.0 = portc.4
bouncecheck3.1 = portc.5
bouncecheck3.2 = portc.7
bouncecheck3.3 = portb.0
Wenn buttonval3 = bouncecheck3 then
für i = 0 zu 3' Zählung von 0 bis 3
Wert3 = buttonval3 >> ich
Wenn value3.0 = 1 & buttonstate3 [i] = 1 then
Hserout [$92 C +, 8 + i, 0]
Serout PORTB.3, N9600, [$Fe, $80]
Serout PORTB.3, N9600, [#146,"", #(C + 8 + i), "", #0, ""]
buttonstate3 [i] = 0
ENDIF
Wenn value3.0 = 0 & buttonstate3 [i] = 0 then
Hserout [$92 C +, 8 + ich, 100]
Serout PORTB.3, N9600, [$Fe, $80]
Serout PORTB.3, N9600, [#146,"", #(C + 8 + i), "", #100, ""]
buttonstate3 [i] = 1
ENDIF
nächsten ich
ENDIF
'set column 4--------------------------------------------------------------------
PORTB.4 = 1
PORTB.5 = 1
PORTB.6 = 1
PORTB.7 = 0
buttonval4 = 0
bouncecheck4 = 0
buttonval4.0 = portc.4
buttonval4.1 = portc.5
buttonval4.2 = portc.7
buttonval4.3 = portb.0
1 Pause
bouncecheck4.0 = portc.4
bouncecheck4.1 = portc.5
bouncecheck4.2 = portc.7
bouncecheck4.3 = portb.0
Wenn buttonval4 = bouncecheck4 then
für i = 0 zu 3' Zählung von 0 bis 3
Wert4 = buttonval4 >> ich
Wenn value4.0 = 1 & buttonstate4 [i] = 1 then
Hserout [$92 C + 12 + i, 0]
Serout PORTB.3, N9600, [$Fe, $80]
Serout PORTB.3, N9600, [#146,"", #(C + 12 + i), "", #0, ""]
buttonstate4 [i] = 0
ENDIF
Wenn value4.0 = 0 & buttonstate4 [i] = 0 then
Hserout [$92 C + 12 + ich, 100]
Serout PORTB.3, N9600, [$Fe, $80]
Serout PORTB.3, N9600, [#146,"", #(C + 12 + i), "", #100, ""]
buttonstate4 [i] = 1
ENDIF
nächsten ich
ENDIF
Rückkehr
RGB:
Wenn j = 1 then
"gelb
Porta.1 = 0
Pauseus 200
Porta.0 = 1
Porta.1 = 1
Porta.2 = 0
ENDIF
Wenn j = 2 dann
"rot
Porta.0 = 1
Porta.1 = 0
Porta.2 = 0
ENDIF
Wenn j = 3 then
"grün
Porta.0 = 0
Porta.1 = 1
Porta.2 = 0
ENDIF
Wenn j = 4 then
"blau
Porta.0 = 0
Porta.1 = 0
Porta.2 = 1
ENDIF
Wenn j = 5 then
"lila
Porta.0 = 1
Porta.1 = 0
Porta.2 = 1
ENDIF
Wenn j = 6 then
"weiß
Porta.0 = 1
Porta.1 = 1
Porta.2 = 1
ENDIF
Wenn j = 7 then
"Cyan
Porta.0 = 0
Porta.1 = 1
Porta.2 = 1
ENDIF
Wenn j = 8 dann
"blau
Porta.0 = 0
Porta.1 = 0
Porta.2 = 1
ENDIF
zurück