ilteris kaplan blog

Solo Test Buggy Code

October 12, 2005

It has been harder than I thought. This whole debugging period is really stealing so much time off of me.
I have prepared a pseudo code of what we should do before going into the PicBasic Pro here you can see it:

onPress switch
checkit
if(1)
if on
‘get the value stored in a variable (this is going to be the value of the first led)
‘check one row up/down/right/left is on or off state
if on ‘check one row up/down/right/left is on or off state
‘get the value stored in a variable (this is going to be the value of the second led)
if on
break;
if off
‘check those variables are in a proper horizontal or a vertical axis at all.
if true
‘get the pin of the LED that can be pressed and store in a variable.
if false
break; if off
break;
if off
break;
if(2)
if on
break;
if off
‘get the pin value from the global variable and light it and turn off the previous ones.

Here is the code I have for the proto type we are trying to prepare with David today. Basically It was supposed to be a working example of a 9 LED series, which are in a plus shape position, I have managed to make it work on the first move which is the middle is empty and you force your piece to go jump over the one below the middle, with your two switch. When I tried to extend the code for the second movement, it didn’t work out. I need to ask question regarding this.

TRISB = %11111111 ‘To keep all the PORTB as an input
TRISC= %00000000 ‘Same sense, PORTC is set to output.
TRISD = %11110000

state var word ‘State variable is there to be the flag.

PORTC = %11111011
PORTD = %11111111
main:

‘if switch bottom is pressed
if PORTB.0 then
‘put a flag that it is pressed with the state variable
state = 1
endif
’ the middle button is pressed and our state is 1
IF PORTB.2 and state == 1 THEN
’ do readfirst subroutine
GOsub readFirst
else

IF PORTB.3 and state == 2 then
state=3
endif
if portb.1 and state == 3 then
gosub readSecond
endif
endif
goto main

readFirst:
‘check if middle led is turned off

IF PORTC.2 == 0 then
‘if it is turned off then make the bottom led and the
one above it turned off
low PORTD.0
low PORTC.3
high PORTC.2
‘problem here, should I set the others led again to
high, because
‘they were high in the setup??
HIGH PORTC.0
HIGH PORTC.1
‘change our state to 2 in case not to worry about this
statement again
state=2
endif
return
‘this subroutine is making one of my leds going to 0 state, I suspect it is just processing its if statement ‘above and making this sub work and thus leaving my LED in that position.

readSecond:
if portc.1 == 0 then
low portc.3
low portc.2
high portc.1
state=3
endif
return