If pin0=1 AND flag1=1 then gosub button2 - WHAT WRONG HAL9000!

NOS9

New Member
Hi everyone,

I am having some trouble with the picaxe vsm simulation software. I am trying to use a single button on pin0 to turn on an output for a relay on outpin1. The code i have used has worked perfectly fine for a real 28x1 microcontroller before, but it wont work for the 40x1 microcontroller simulated by the picaxe vsm.

The button turns the relay output on, but wont turn off. If i use a second button, it will turn on with pin0 and off with pin1 problem free. If i use a AND flag1=1 to identify between two different status of the problem, it turns on but still wont turn off with one or two buttons.

This code with two buttons, and works.
Code:
do
	if pin0=1 then 
		gosub button1
	elseif pin1=1 then 
		gosub button2
	endif
loop


button1:
	let flag1=1
	let outpin1=1
	gosub timer30
	
return	


button2:
	let flag1=0
	let outpin1=0
	gosub timer30
return

timer30:
	value = 300
	
	do until value = 1
		if value > 1 then 
		value = value - 1
	elseif value = 0 then endif
		
	loop
Return


This code is with the flag1 being used to detect the status of the program, and detects pin0 when first pressed, but then does not switch off when pin1 button is pressed.
Code:
do
	if pin0=1 AND flag1=0 then 
		gosub button1
	elseif pin1=1 AND flag1=1 then 
		gosub button2
	endif
loop


button1:
	let flag1=1
	let outpin1=1
	gosub timer30
	
return	


button2:
	let flag1=0
	let outpin1=0
	gosub timer30
return

timer30:
	value = 300
	
	do until value = 1
		if value > 1 then 
		value = value - 1
	elseif value = 0 then endif
		
	loop
Return
Ive used this code before in another project for a real 28x1 and a 28x2 microcontroller and it worked problem free in many places, please could someone look over these examples. I assume i am making a mistake some where, but i can not see it and i am beginning to assume it could be the simulator.

Any help would truly be welcomed, thank you.
NOS9
 

NOS9

New Member
Ive been looking in to the issue a bit more at or two after my first post, and i am wondering if maybe i using the flag1 for something it shouldn't be used for. As i looked up on flags and they seem to be linked with interrupts.

If i make a variable as flag_relay, and set that to a value of 1, then it will work, but if i use flag1=1 then it wont work, but i have used this method before in an older project, and maybe it worked for what i was doing, but it was an incorrect use.

So am i using the flag1 incorrectly, if i use it as a general flag?
 

Technical

Technical Support
Staff member
In theory you can use flag1 as a general purpose flag, but only if interrupts are not being used. However it would be far better to use one of the general purpose bitx flags, e.g. bit1 instead. Just remember bit0 to bit7 are all part of b0, so don't use b0 as well.
 
Top