View Full Version : memory slot question for bs2sx

09-05-2008, 09:50 AM
I'm building a midi keyboard, the program is nothing fancy mostly a series of if then statements checking for key presses. I tried compiling the program on the bs2, but I ran out of space in the EEPROM. I have a BS2sx in the mail currently so that I can take advantage of the 8 memory slots for my code. Could anyone tell me how variables are moved from slot to slot? I plan on simply going from slot 0 to the next until I have all my code in the EEPROM. Will the variable values storing key presses be carried over from slot 0 to slot 1 or no? Just to give you an idea some of my code follows:

' {$STAMP BS2sx}
'{$PBASIC 2.5}
'PIN Definitions
A0 PIN 0
A1 PIN 1
A2 PIN 2
A3 PIN 3
E1 PIN 4 'Enable input high for HCT138
midioutpin PIN 5
RX1 PIN 14
RX2 PIN 15

note VAR Byte
play1 VAR Bit
play2 VAR Bit
play3 VAR Bit
play4 VAR Bit
play5 VAR Bit
play6 VAR Bit
play7 VAR Bit
play8 VAR Bit
play9 VAR Bit
play10 VAR Bit
play11 VAR Bit
play12 VAR Bit

'midioutpin CON 5
midibaudmode CON 32780
ch1on CON 144
ch1off CON 128
vel CON 127

'128=note off
'Code For HCT 138 Demultiplexer
DEBUG "Check 138",CR,CR
IF (RX1 = 0) AND (play1=0) THEN 'Check key press, play1 tells whether or not the key was pressed in the passed and stops the same note from being repeatedly played
SEROUT midioutpin, midibaudmode, [ch1on, 38, vel]
play1 = 1
DEBUG "First HIGH Key pressed",CR
IF (RX1=1) AND (play1=1) THEN
SEROUT midioutpin, midibaudmode, [ch1off, 38, vel]
'Check LOW KEY
IF (RX2 = 0) AND (play2=0) THEN 'Check key press
DEBUG "First LOW Key pressed",CR
SEROUT midioutpin, midibaudmode, [ch1on, 62, vel]
IF (RX2=1) AND (play2=1) THEN
SEROUT midioutpin, midibaudmode, [ch1off, 62, vel]

Ideally all my IO pins would not change, would I have to redefine these as well as my variables in the beginning of another program slot? The program will check keys 1-22 in slot 0 23-40 in slot 1 and so on until I send it back to slot 0. It's important that the variables playx, which tell whether a note is already playing be unchanged when I switch. Without playx when you hold down a key it will repeatedly play the note instead of just once. Any help would be greatly appreciated.

09-05-2008, 12:04 PM
See http://forums.parallax.com/showthread.php?p=748201

"If you build it, they will come."

09-05-2008, 07:53 PM
Bottom line -- there's only ONE set of "Variables", kept in registers on the CPU. You CAN use multiple 'memory slots' using the "RUN" command, but it's more complicated than a simple GOSUB call. Follow the links in the postings before this one to find the method.