View Full Version : Run "runs" part of old program...

02-23-2010, 12:03 PM
I just bought a stamp homework board.

I write a simple program to turn on an LED, then off.

I click on run and that programs·loads into the homework board and runs - turns on the LED, then off.

Then I load in a new simple program which keeps the LED off...

...but in the process of that new program loading via the run function, the homework board runs the old program which is still in the memory of the homework board. So the LED flashes on again.

Then of course once the new program is loaded, I can hit reset on the homework board and the LED stays off.

Why is the old program running when I am loading a new program in via run?

This is not a big deal. I am trying to teach someone "1's and 0's" and how these turn on/off LED's and so forth.

So I would like to enter a "1" on the screen, run the program, and he then sees the light come on then go off.

Then enter a 0 on the screen, run the program, and he sees no light come on.

Mike Green
02-23-2010, 12:35 PM
When you use the RUN menu item in the Stamp Editor, the Editor forces the Stamp Homework Board to reset, then instructs the Stamp to download the program to an EEPROM that is part of the Stamp on the Homework Board. Sometimes more than one reset occurs, usually once when the Editor opens the communications port and once when it actually begins the downloading process. The old program might start running briefly before the Stamp is reset again and the new program is downloaded. If the old program is very simple, it might do what it's supposed to do before it's replaced by the new program.

02-23-2010, 12:48 PM
Thank you!

I was just poking around and found the following command...

DATA 0(2048)

...Says to run it by itself and it will clear the memory...

Hummm... Perhaps if I placed that at the end of my first program, it would be a "self destructing program" which removes itself from memory after running?

Mike Green
02-23-2010, 01:00 PM
It won't do what you expect.

DATA 0(2048)

This compiles into a program consisting of 2048 zero bytes which simply fills up the EEPROM with zero bytes when it's downloaded using the Stamp Editor. Since the EEPROM is filled with zeros, any program that was there gets replaced with the zeros. The DATA statement is not something that gets executed. It simply produces data which gets downloaded to the Stamp the same way (and in the same place) as a program. Since DATA statements start beginning at location zero and the program starts at the other end of memory and works downwards (towards zero), the two can coexist (as long as they don't overlap).

You can't really write a completely "self destructing program" since the program will destroy itself before it completes its task. There'll be a piece of the program left. Practically speaking, that may not matter. You can use WRITE statements to write data to the EEPROM (including the part with the program in it).

02-23-2010, 01:14 PM
Thanks. The following as the last entry in my program did the trick.

WRITE 2047, 0