Run "runs" part of old program...
bill190
Posts: 769
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.
·
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.
·
Comments
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?
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).
WRITE 2047, 0