Help me put my code on a diet
MikeyMustang
Posts: 22
I know there are better ways to write this code. I am a newbie and need some guidance on how to TRIM this code up for memory space
Thanks
Mike WA3O
Thanks
Mike WA3O
Comments
For i = 0 to 100
toggle pinNumber
LOOKUP i, [noparse][[/noparse]10,58,09, ...], pauseValue
PAUSE pausevalue
NEXT
I created a couple of subroutines -- "Dit:" and "Dah:".· Each call to the subroutine saves you about 6 bytes of storage.
I started to translate all your HIGH 14: Pause 50: LOW 14 instances to a "GOSUB DIT" -- but got tired.· Hopefully, you see the pattern.
Oh, and note that your "AUX1ON:" routine will 'fall through' to "AUX1OFF:" the way you have it now.
Oh, and note the "IF DTMF = 1 THEN CWM1" does a GOTO CWM1.· You CAN do "IF DTMF = 1 THEN GOSUB CWM1" if that's what you want.
The "DATA" statement is the beginning of an example where you 'encode' the Dit/Dah you want to send as data statements.
Post Edited (allanlane5) : 10/28/2008 2:16:04 PM GMT
You must have read my mind....(short story) LOL! I started to that that exact thing at work today and for some reason it ate up more space? I also am wondering if I really need to make sure both pins are off...kinda of redundant... do gosubs take up more space?
I did a
dah: pulsout 13, 180
dit: pulseout 14, 60
spc1: pause 50
spc2: pause 660
and this ate up the code when I
gosub dit
gosub spc1
gosub dah
gosub spc2
for an "a"
Thanks for the other comments I am confused what the differance between the goto and the gosub would be?
Thanks for the comments
Mike WA3O
as for the AUXon and AUxoff I suppose iI have to goto main or a return so they don't "fall thru"?
I am confused a little about the DATA comment but...
Thanks for the tip I was able to save alot of space using the GOSUB'S
Here is the finished product.
Thanks Again
Mike WA3O
Post Edited (MikeyMustang) : 10/29/2008 8:21:41 PM GMT
The following attachment has translated your "DIT", "DAH", and "Pause 660" statements into a 1, 0, or 2 DATA value.
It uses a "-1" to indicate the end of a message.
Now, all you have to do is assign the DATA address to "MsgAddr", and call "SendMessage". This saves a LOT of space.
I've translated your first two messages into DATA statements -- you should be able to do the rest.
Was this a test? LOL I got it to work but for some reason the program didn't like the -1 for a stop bit I changed it to a 6 and added a
6 at the end of each line
IF CheckByte = 6 then return
and it seems to work?????
Maybe beginners luck?
Anyways thanks for the help and you saved me tons of memory and now I am able to pit some preset freqs in the program
Thanks
Mike WA3O
I have really used up the code space on the chip now and I am pretty happy with the finished product. I guess if I really want more space I should upgrade to a better BS2 chip and suggestions? Also The dtmf decode seems to be a little slow ...I can type the dtmf in fast and the BS only decodes the first 2 digits and looses track is this a function of the chip being too slow or maybe the hardware (8880 chip)?
Thanks again for all the help...its guys like you who make this hobby happen and keeps Basic stamps rolling.
My next chip will be a BS2pe so I can do DTMF to I2c for the Si570 chip...
Mike WA3O