One function works but the other doesn't. Why?
OK, I have my stamp hooked up to an MT8816 and I am able to control it with some very lengthy code but when I try to condense it, all of the pins from 8-15 go High when "TX1 = 0" in the second code section. I will try to be very descriptive below. The program that does work is this:
The following code is a change to the subs that connect and disconnect X to Y connections on the MT8816
Obviously the name of the function is different too but that is also changed in my "IF" statements in the "Main" program. The problem from what I can see is that in my second set of code, pins 8-15 go High when they should be low where I set "TX1 = 0". I have no idea why. Another note is that by the time the function ends, they are back to Low. Any ideas anyone? Thanks.
Jeremy
' {STAMP BS2SX}
' {$PBASIC 2.5}
DATA_LINE CON 5 'Pin 38 on MT8816
CS_LINE CON 6 'Pin 36 on MT8816
STROBE_LINE CON 7 'Pin 18 on MT8816
RESET_LINE CON 8 'Pin 3 on MT8816
AX0 CON 9 'Pin 5 on MT8816
AX1 CON 10 'Pin 22 on MT8816
AX2 CON 11 'Pin 23 on MT8816
AX3 CON 12 'Pin 4 on MT8816
AY0 CON 13 'Pin 24 on MT8816
AY1 CON 14 'Pin 25 on MT8816
AY2 CON 15 'Pin 2 on MT8816
OUTH = %11111111 'Makes pins 8-15 outputs
DIRH = %00000000 'Sets pins 8-15 to low
Reset:
HIGH RESET_LINE 'Sets MT8816 Reset Line to High which closes all X to Y connections
PAUSE 25 'Wait 25 ms which is way longer than necessary
LOW RESET_LINE 'Sets MT8816 Reset Line to Low and it is now ready to accept commands
DEBUG CR, "The MT8816 was just reset..."
main:
DO
IF (IN0 = 0) THEN 'If button 1 is pressed, then
GOSUB C_X0_Y0 'go to that sub
ELSEIF (IN1 = 0) THEN 'If button 2 is pressed, then
GOSUB D_X0_Y0 'go to that sub
ELSEIF (IN3 = 0) THEN 'If button 3 is pressed, then
GOSUB Reset 'go to that sub
ENDIF
LOOP
C_X0_Y0:
LOW AX0 'Sets AX0 to Low
LOW AX1 'Sets AX1 to Low
LOW AX2 'Sets AX2 to Low
LOW AX3 'Sets AX3 to Low
LOW AY0 'Sets AY0 to Low
LOW AY1 'Sets AY1 to Low
LOW AY2 'Sets AY2 to Low
PAUSE 10 'Pause for grins
HIGH DATA_LINE 'Data Line is High which means that the MT8816 is going to make a connection
HIGH CS_LINE 'CS Line is high for something
HIGH STROBE_LINE 'Strobe Line is High for something
PAUSE 10 'Pause for grins
LOW STROBE_LINE 'Strobe Line is low, thus setting the connection
LOW CS_LINE 'CS Line is low for something
LOW DATA_LINE 'Data Line is low for something
DO WHILE (IN0 = 0) 'Do the loop while the button is still pressed to avoid the function being run a few times on a single button press
PAUSE 25 'Wait a bit
LOOP 'If its pressed, then loop again
DEBUG CR, "X0 and Y0 are connected..."
RETURN 'Go back to Main and look for a new button press
D_X0_Y0:
LOW AX0 'Sets AX0 to Low
LOW AX1 'Sets AX1 to Low
LOW AX2 'Sets AX2 to Low
LOW AX3 'Sets AX3 to Low
LOW AY0 'Sets AY0 to Low
LOW AY1 'Sets AY1 to Low
LOW AY2 'Sets AY2 to Low
PAUSE 10 'Pause for grins
LOW DATA_LINE 'Data Line is Low which means that the MT8816 is going to sever a connection
HIGH CS_LINE 'CS Line is high for something
HIGH STROBE_LINE 'Strobe Line is High for something
PAUSE 10 'Pause for grins
LOW STROBE_LINE 'Strobe Line is low, thus setting the connection
LOW CS_LINE 'CS Line is low for something
LOW DATA_LINE 'Data Line is low for something
DO WHILE (IN1 = 0) 'Do the loop while the button is still pressed to avoid the function being run a few times on a single button press
PAUSE 25 'Wait a bit
LOOP 'If its pressed, then loop again
DEBUG CR, "X0 and Y0 are not connected..."
RETURN 'Go back to Main and look for a new button press
The following code is a change to the subs that connect and disconnect X to Y connections on the MT8816
Connect_TX1:
TX1 = 1
LOOKUP TX1, [noparse][[/noparse] %00000000, %00000001, %00000010, %00000100 ], DIRH 'This is a connection list for Y0 to connect to X0, X1, X2 or X3
PAUSE 10 'Pause for grins
HIGH DATA_LINE 'Data Line is High which means that the MT8816 is going to make a connection
HIGH CS_LINE 'CS Line is high for something
HIGH STROBE_LINE 'Strobe Line is High for something
'It is at this point that all of the pins from 8-15 go High. What? How is that possible? What don't I understand?
PAUSE 10 'Pause for grins
LOW STROBE_LINE 'Strobe Line is low, thus setting the connection
LOW CS_LINE 'CS Line is low for something
LOW DATA_LINE 'Data Line is low for something
DO WHILE (IN0 = 0) 'Do the loop while the button is still pressed to avoid the function being run a few times on a single button press
PAUSE 25 'Wait a bit
LOOP 'If its pressed, then loop again
DEBUG CR, "TX1 and RX1 are connected..."
RETURN 'Go back to Main and look for a new button press
Obviously the name of the function is different too but that is also changed in my "IF" statements in the "Main" program. The problem from what I can see is that in my second set of code, pins 8-15 go High when they should be low where I set "TX1 = 0". I have no idea why. Another note is that by the time the function ends, they are back to Low. Any ideas anyone? Thanks.
Jeremy

Comments
'
[noparse][[/noparse] Subroutines ]
·C_D_X0_Y0:
····· LOW AX0···················· · 'Sets AX0 to Low
····· LOW AX1··················· ·· 'Sets AX1 to Low
····· LOW AX2···················· · 'Sets AX2 to Low
····· LOW AX3···················· · 'Sets AX3 to Low
····· LOW AY0··················· · 'Sets AY0 to Low
····· LOW AY1··················· · 'Sets AY1 to Low
····· LOW AY2··················· · 'Sets AY2 to Low
····· PAUSE 10··················· ·'Pause for grins
····· RETURN
C_D_X0_Y0_1:
····· LOW STROBE_LINE······ ·· 'Strobe Line is low, thus setting the connection
····· LOW CS_LINE·············· ··'CS Line is low for something
····· LOW DATA_LINE·········· · 'Data Line is low for something
····· RETURN
I do not know if this is right or if it will work or not
C_D_X0_Y0:
DIRH = %00000000········· 'Sets pins 8-15 to low
····· PAUSE 10··········· 'Pause for grins
····· RETURN
C_D_X0_Y0_1:
· OUTB = %0000
· PAUSE 10
····· RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 11/19/2009 3:27:44 AM GMT
I am new to all this and maybe I don't see the direction you are going and how this might be possible with your code. Thanks for your help [noparse]:)[/noparse]
Jeremy
YEAH!!! That was it. Changed:
to:
and it works great!
Thank you so much.
Jeremy
Post Edited (ns7r) : 11/19/2009 4:34:07 AM GMT