Paso 6: El código.
'****************************************************************' * Nombre: UNTITLED. BAS *
' * Autor: Matthew Reid *
' * Aviso: Copyright (c) 2012 [Seleccione Ver... OPCIONES DEL EDITOR] *
' *: Todos los derechos reservados *
'* Date : 9/5/2012 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
PAUSE 300
incluyen "modedefs.bas"
#CONFIG
__CONFIG _CONFIG1L, _PLLDIV_5_1L y _CPUDIV_OSC1_PLL2_1L y _USBDIV_2_1L
__CONFIG _CONFIG1H, _FOSC_HS_1H y _FCMEN_ON_1H y _IESO_ON_1H
__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_ON_2L & _BORV_3_2L & _VREGEN_OFF_2L
_WDTPS_256_2H, _WDT_ON_2H y _CONFIG2H __CONFIG
_PBADEN_OFF_3H, _MCLRE_OFF_3H y _CONFIG3H __CONFIG
__CONFIG _CONFIG4L, _STVREN_ON_4L & _LVP_OFF_4L & _XINST_OFF_4L & _DEBUG_OFF_4L
#endconfig
define OSC 20
OSCCON = % 00001000
' configurar el puerto serial hardware
definir HSER_RCSTA 90H
definir HSER_TXSTA 24H
definir HSER_BAUD 31250
' puertos i2c
SDA var PORTB.2
SCL var PORTB.1
' botón variables
' variables de columna 1
buttonval1 var byte
bouncecheck1 var byte
buttonstate1 var bit [4]
i var byte
valor1 var byte
' variables de columna 2
buttonval2 var byte
bouncecheck2 var byte
buttonstate2 var bit [4]
value2 var byte
' variables de columna 3
buttonval3 var byte
bouncecheck3 var byte
buttonstate3 var bit [4]
valor3 var byte
' columna 4variables
buttonval4 var byte
bouncecheck4 var byte
buttonstate4 var bit [4]
value4 var byte
' bankchange variable
norte del estado var bit
Downstate var bit
byte de var j: j = 1
c var byte
' variables para una a d (IC2)
un var byte [8]
dos var byte [8]
tres var word [8]: tres = 0
var palabra de umbral: umbral = 50
prevpotval var byte [8]
prevadval var word [8]
currentadval var word [8]
' variables para una a d (IC1)
ella.1 var byte [8]
two1 var byte [8]
three1 var word [8]: tres = 0
prevpotval1 var byte [8]
prevadval1 var word [8]
currentadval1 var word [8]
' dirección de Puerto
TRISA = % 00000000
TRISB = % 00000001
trisc = % 10110110
' habilitar RC4 y RC5
Ucon.3 = 0
ucfg.3 = 1
' desactivar la interna A D
adcon0 = % 00111100
adcon1 = % 00001111
' enciende el lcd y configurar el brillo al máximo
PAUSE 1000
serout PORTB.3, N9600, [$1b, $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 v1_1 PORTB.3,N9600,["Midi Pad"]
serout PORTB.3,N9600,[$fe,$c0]
serout PORTB.3,N9600,["Matt Reid 2012"]
' intro flash
' rojo
Porta.0 = 1
Porta.1 = 0
Porta.2 = 0
PAUSE 400
' verde
Porta.0 = 0
Porta.1 = 1
Porta.2 = 0
PAUSE 400
' azul
Porta.0 = 0
Porta.1 = 0
Porta.2 = 1
PAUSE 400
' morado
Porta.0 = 1
Porta.1 = 0
Porta.2 = 1
PAUSE 400
' blanco
Porta.0 = 1
Porta.1 = 1
Porta.2 = 1
PAUSE 400
' cian
Porta.0 = 0
Porta.1 = 1
Porta.2 = 1
PAUSE 400
'_________________________
' leer Banco de eeprom
leer 5, j
mainloop:
GoSub bankchange
GoSub keypress
GoSub potread
GoSub RGB
Goto mainloop
bankchange:
' Banco para arriba
Si portc.2 = 1 & estado = 1 entonces
j = j + 1
Si j > 8 entonces
j = 1
endif
' borrar todas las notas
para i = 0 a 128
hserout [$92, i, 0]
siguiente
' escribir Banco cambio de eeprom
escribir 5, j
Norte = 0
endif
Si portc.2 = 0 & estado = 0 entonces
estado = 1
endif
' Banco de abajo
Si portc.1 = 1 & downstate = 1 entonces
j = j - 1
Si j < 1 entonces
j = 8
endif
' borrar todas las notas
para i = 0 a 128
hserout [$92, i, 0]
siguiente
' escribir Banco cambio de eeprom
escribir 5, j
Downstate = 0
endif
Si portc.1 = 0 & downstate = 0 entonces
Downstate = 1
endif
' Mostrar la Banco
serout PORTB.3, N9600, [$Fe, $c0]
serout PORTB.3, N9600, ["Banco", "", #j, ""]
Si j = 1 entonces
c = 0
endif
Si j = 2 entonces
c = 16
endif
Si j = 3 entonces
c = 32
endif
Si j = 4 entonces
c = 48
endif
Si j = 5 entonces
c = 64
endif
Si j = 6 entonces
c = 80
endif
Si j = 7 entonces
c = 96
endif
Si j = 8 entonces
c = 112
endif
volver
potread:
' cosas de potenciómetro adc---
' leer ic2
para i = 1 a 8
tres [i] = 0
Si i = 1 entonces
i2cwrite SDA, SCL, % 00010000, [% 10001100]
endif
Si i = 2 entonces
i2cwrite SDA, SCL, % 00010000, [% 11001100]
endif
Si i = 3 entonces
i2cwrite SDA, SCL, % 00010000, [% 10011100]
endif
Si i = 4 then
i2cwrite SDA, SCL, % 00010000, [% 11011100]
endif
Si i = 5 then
i2cwrite SDA, SCL, % 00010000, [% 10101100]
endif
Si i = 6 entonces
i2cwrite SDA, SCL, % 00010000, [% 11101100]
endif
Si i = 7 entonces
i2cwrite SDA, SCL, % 00010000, [% 10111100]
endif
Si i = 8 entonces
i2cwrite SDA, SCL, % 00010000, [% 11111100]
endif
"esta pausa es importante mantener el adc de saltando
pausa de 4
i2cread SDA, SCL, % 00010001, [[i], dos [i]]
tres [i] una [i] = | tres [i]
tres [i] = tres [i] << 4
dos [i] = dos [i] >> 4
tres [i] = dos [i] | tres [i]
currentadval [i] = tres [i]
' pausa de 10
tres [i] = tres [i] * 128
tres [i] = div32 4095
Si abs (currentadval [i] - prevadval[i]) > = umbral entonces
hserout [$B2, 13 + i, 3 [i]]
prevpotval [i] = tres [i]
prevadval [i] = currentadval [i]
' Mostrar un valor d
serout PORTB.3, N9600, [$Fe, $80]
serout PORTB.3, N9600, [#178, "", #(13+i), "", #three [i], ""]
endif
siguiente
' leer ic1
para i = 1 a 8
three1 [i] = 0
Si i = 1 entonces
i2cwrite SDA, SCL, % 00010100, [% 10001100]
endif
Si i = 2 entonces
i2cwrite SDA, SCL, % 00010100, [% 11001100]
endif
Si i = 3 entonces
i2cwrite SDA, SCL, % 00010100, [% 10011100]
endif
Si i = 4 then
i2cwrite SDA, SCL, % 00010100, [% 11011100]
endif
Si i = 5 then
i2cwrite SDA, SCL, % 00010100, [% 10101100]
endif
Si i = 6 entonces
i2cwrite SDA, SCL, % 00010100, [% 11101100]
endif
Si i = 7 entonces
i2cwrite SDA, SCL, % 00010100, [% 10111100]
endif
Si i = 8 entonces
i2cwrite SDA, SCL, % 00010100, [% 11111100]
endif
"esta pausa es importante mantener el adc de saltando
pausa de 4
i2cread SDA, SCL, % 00010101, [ella.1 [i], two1 [i]]
three1 [i] = ella.1 [i] | three1 [i]
three1 [i] = three1 [i] << 4
two1 [i] = two1 [i] >> 4
three1 [i] = two1 [i] | three1 [i]
currentadval1 [i] = three1 [i]
' pausa de 10
three1 [i] = three1 [i] * 128
three1 [i] = div32 4095
Si abs (currentadval1 [i] - prevadval1[i]) > = umbral entonces
hserout [$B2, 13 + i, three1 [i]]
prevpotval1 [i] = three1 [i]
prevadval1 [i] = currentadval1 [i]
' Mostrar un valor d
serout PORTB.3, N9600, [$Fe, $80]
serout PORTB.3, N9600, [#178, "", #(21+i), "", #three1 [i], ""]
endif
siguiente
volver
KeyPress:
' botón código
'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
pausa 1
bouncecheck1.0 = portc.4
bouncecheck1.1 = portc.5
bouncecheck1.2 = portc.7
bouncecheck1.3 = portb.0
Si buttonval1 = bouncecheck1 entonces
para i = 0 a 3' cuenta de 0 a 3
valor1 = buttonval1 >> i
Si value1.0 = 1 & buttonstate1 [i] = 1 entonces
hserout [$92, c +, 0]
serout PORTB.3, N9600, [$Fe, $80]
serout PORTB.3, N9600, [#146,"", #(c + i), "", #0, ""]
buttonstate1 [i] = 0
endif
Si value1.0 = 0 & buttonstate1 [i] = 0 entonces
hserout [$92, c + i, 100]
serout PORTB.3, N9600, [$Fe, $80]
serout PORTB.3, N9600, [#146,"", #(c + i), "", #100, ""]
buttonstate1 [i] = 1
endif
siguiente
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
pausa 1
bouncecheck2.0 = portc.4
bouncecheck2.1 = portc.5
bouncecheck2.2 = portc.7
bouncecheck2.3 = portb.0
Si buttonval2 = bouncecheck2 entonces
para i = 0 a 3' cuenta de 0 a 3
valor2 = buttonval2 >> i
Si value2.0 = 1 & buttonstate2 [i] = 1 entonces
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
Si value2.0 = 0 & buttonstate2 [i] = 0 entonces
hserout [$92, c + 4 + i, 100]
serout PORTB.3, N9600, [$Fe, $80]
serout PORTB.3, N9600, [#146,"", #(c + 4 + i), "", #100, ""]
buttonstate2 [i] = 1
endif
siguiente
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
pausa 1
bouncecheck3.0 = portc.4
bouncecheck3.1 = portc.5
bouncecheck3.2 = portc.7
bouncecheck3.3 = portb.0
Si buttonval3 = bouncecheck3 entonces
para i = 0 a 3' cuenta de 0 a 3
valor3 = buttonval3 >> i
Si value3.0 = 1 & buttonstate3 [i] = 1 entonces
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
Si value3.0 = 0 & buttonstate3 [i] = 0 entonces
hserout [92$ c + 8 + i, 100]
serout PORTB.3, N9600, [$Fe, $80]
serout PORTB.3, N9600, [#146,"", #(c + 8 + i), "", #100, ""]
buttonstate3 [i] = 1
endif
siguiente
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
pausa 1
bouncecheck4.0 = portc.4
bouncecheck4.1 = portc.5
bouncecheck4.2 = portc.7
bouncecheck4.3 = portb.0
Si buttonval4 = bouncecheck4 entonces
para i = 0 a 3' cuenta de 0 a 3
value4 = buttonval4 >> i
Si value4.0 = 1 & buttonstate4 [i] = 1 entonces
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
Si value4.0 = 0 & buttonstate4 [i] = 0 entonces
hserout [92$ c + 12 + i, 100]
serout PORTB.3, N9600, [$Fe, $80]
serout PORTB.3, N9600, [#146,"", #(c + 12 + i), "", #100, ""]
buttonstate4 [i] = 1
endif
siguiente
endif
volver
RGB:
Si j = 1 entonces
' amarillo
Porta.1 = 0
pauseus 200
Porta.0 = 1
Porta.1 = 1
Porta.2 = 0
endif
Si j = 2 entonces
' rojo
Porta.0 = 1
Porta.1 = 0
Porta.2 = 0
endif
Si j = 3 entonces
' verde
Porta.0 = 0
Porta.1 = 1
Porta.2 = 0
endif
Si j = 4 entonces
' azul
Porta.0 = 0
Porta.1 = 0
Porta.2 = 1
endif
Si j = 5 entonces
' morado
Porta.0 = 1
Porta.1 = 0
Porta.2 = 1
endif
Si j = 6 entonces
' blanco
Porta.0 = 1
Porta.1 = 1
Porta.2 = 1
endif
Si j = 7 entonces
' cian
Porta.0 = 0
Porta.1 = 1
Porta.2 = 1
endif
Si j = 8 entonces
' azul
Porta.0 = 0
Porta.1 = 0
Porta.2 = 1
endif
volver