PDA

View Full Version : Advice needed. FOR...NEXT loop



atomski
- 18th June 2004, 08:42
Hello all,

PROBLEM
********
I'm trying to send 10 consecutive tones using FREQOUT command. Here's my code:

Tone1 VAR Word
...
Tone 10 VAR Word
Loop:
FREQOUT Pin, Period, Tone1
FREQOUT Pin, Period, Tone2
FREQOUT Pin, Period, Tone3
FREQOUT Pin, Period, Tone4
FREQOUT Pin, Period, Tone5
FREQOUT Pin, Period, Tone6
FREQOUT Pin, Period, Tone7
FREQOUT Pin, Period, Tone8
FREQOUT Pin, Period, Tone9
FREQOUT Pin, Period, Tone10
PAUSE 1000
GOTO Loop

QUESTION
*********
Can I use a FOR...NEXT loop in order to use just one FREQOUT statement instead of ten? For example:

Loop:
FOR i = 1 TO 10
Tone = Tone(i)
FREQOUT Pin, Period, Tone
NEXT i
i = 0
PAUSE 1000
GOTO Loop

PS When I try to compile this I get an error. Can anyone give me a clue as to how I might go about solving this problem? Thank you in advance.

--
Sincerest regards,

YZ7REA Vladimir M SKrbic
4N7ATV Repeater Administrator
YU7GHZ Radio Club President

Melanie
- 18th June 2004, 10:31
Tone var Byte [11]

Note: Tone is now an Array, but since the first element of the array is Tone[0], Tone[10] is actually the eleventh element, which is why I've defined eleven elements above.

Loop:
FOR i = 1 TO 10
FREQOUT Pin, Period, Tone[i]
NEXT i

Naturally you will have to preset the array values of Tone before you run the subroutine...

...or if you have lots of tunes to play try presetting them in EEPROM...

Loop:
For i = 1 to 10
Read i,tone
FREQOUT Pin, Period, Tone
NEXT i

Melanie

atomski
- 18th June 2004, 11:12
Thanks Mel,

I knew I was on the right track, however I just couldn't figure it out but once again Mel comes to the rescue! :D

Vlad

atomski
- 24th June 2004, 18:23
Mel, I have another question for you regarding this problem.
I've done what you've suggested as shown below:

Tone var Byte[11]

Loop:
FOR i = 1 TO 10
FREQOUT Pin, Period, Tone[i]
NEXT i

However I have 10 4-digit dec numbers that the PC program
is sending out via rs-232 as ASCII characters in hex format
as shown below:
for 1234 it sends $04, $D2
or
for 5678 it sends $16, $2E

So, my numbers are WORD sized. Can my Tone array hold
10 word sized velues?

How can I get them by using HSERIN command? Perhaps
like this:

HSERIN [STR Tone\11]

Also, how can I store these 10 values (the Tone array) into
the on-board eeprom and read them back from eeprom to
memory at power-up?

--
Sincerest regards,

YZ7REA Vladimir M SKrbic
4N7ATV Repeater Administrator
YU7GHZ Radio Club President

Melanie
- 24th June 2004, 19:32
Uggghhh... so perhaps you want me to write your whole program for you?

> So, my numbers are WORD sized. Can my Tone array hold 10 word sized velues?

Sure... try this...

Tone var WORD [11]

and suddenly like by magic they can hold values bigger than 8 bits.

> How can I get them by using HSERIN command?

I'm going to be cruel to be kind... do an experiment and display the result on an LCD or PC to see what happens. Since I don't know the format of the data being captured by HSERIN, I can't answer that anyway.

> Also, how can I store these 10 values (the Tone array) into the on-board eeprom and read them back from eeprom to memory at power-up?

Go back over answers I've posted (or Messaged) in the past to you over Reading and Writing from/to EEPROM. BYTE at a time, and use Highbyte/Lowbyte to re-assemble Words. I do vaguely recall exchanging on this topic about two/three months ago.

Melanie

atomski
- 25th June 2004, 07:36
Mel, please don't get upset if I ask for advice. The whole
trick about successful programming is in grasping the concept
of "how the stuff works". When I ask for advice, I ask for an
idea and want to understand how something works. When I
post a code snippet and say I'm not sure if it's ok, I really
need help. But if I come and say I need someone to write or
give me the whole code, that's another thing. I'm not trying
to argue with you here, it's just that the very idea of
someone even thinking I'm a lazy butt who wants someone
else to do all his work for him makes me feel bad. I spend
countless hours programming, learning in the process,
building stuff that works and doesn't work sometimes. If
that's the case it's "back to the drawing board" for me. When
I'm stuck I ask people for advice, cuz like you I also love
helping people out whenever I can. You've helped me and
many others in the past and your help proved to be
invaluable, so I thank you for that. Please accept my apology
if I made you upset.

Vlad

Melanie
- 25th June 2004, 08:33
Far from being upset, that was posted with good humour... I must try to moderate it, perhaps it didnt come across in the spirit it was intended - for which I appologise. Saying that, I'm trying not to repeat answers I've already given you in the past.

Melanie
- 25th June 2004, 09:25
Also check this thread from July 2003...

FYI - How to Access individual bytes in Word Arrays

looks like a contender for the new FAQ category...

atomski
- 25th June 2004, 13:41
Thanks Mel, hey no prb about yr remarks. I'll be a good
boy and try to behave in the future :)

BTW I would have probably gotten the joke if there was a
smiley attached at the end. Sorry, may bad

Vlad