Board index » delphi » Newbie, How to make interruptable loop ?

Newbie, How to make interruptable loop ?

Hi There

It probably is REALLY stupid to ask my following question, but
nevertheless here it is :

First a little info. I use System51 compiler for a singlechip (80C535).

How can i create a loop that i can interrupt by a keyboard stroke ?
The loop needs to create a clock output on a output-port for a stepmotor
controller.

Here is my procedure :
(*-------------------------------------------------------*)
Procedure clock(speed);
var
    I : byte;
speed : byte;
ch    :char;

Begin
  for I = 0 to speed do begin
  p6.1 := true;
  end;  
  for I = 0 to speed do begin
  p6.1 := false;
  end;
read (ch);
case ch of 'q' : stop;
end;

(*--------------------------------------------------------*)

Thanx alot

Brian (remove NOSPAM for mailing)

 

Re:Newbie, How to make interruptable loop ?


there are a couple of things that you can do to allow this, but I
think that the best couple of ways are:

while not keypressed do (procedure);

repeat
until keypressed;

Just know that in my experience (Using TP6) you can only do this once
in a program without setting the keypressed to false. (I had to
convert a procedure from TP7 to TP6 when I stopped using TP7... it had
a repeat until keypressed loop that was replaced with
tmpvar:=readkey;)

Also, your procedure declaration is a bit weird, and probably won't
work.

It should be

procedure clock(speed:byte);

You can then remove the speed variable from your variable
declarations.

So your procedure would be:

procedure clock(speed:byte);
var
  i:byte;
begin
  keypressed:=False;
  while not keypressed do begin
    for i:=0 to speed do p6.1:=True;
    for i:=0 to speed do p6.1:=False;
  end;
end;

On Tue, 29 Jun 1999 05:32:47 +0100, Brian Johansen

Quote
<bkjoh...@NOSPAMdscc.dk> wrote:
>Hi There

>It probably is REALLY stupid to ask my following question, but
>nevertheless here it is :

>First a little info. I use System51 compiler for a singlechip (80C535).

>How can i create a loop that i can interrupt by a keyboard stroke ?
>The loop needs to create a clock output on a output-port for a stepmotor
>controller.

>Here is my procedure :
>(*-------------------------------------------------------*)
>Procedure clock(speed);
>var
>    I : byte;
>speed : byte;
>ch    :char;

>Begin
>  for I = 0 to speed do begin
>  p6.1 := true;
>  end;  
>  for I = 0 to speed do begin
>  p6.1 := false;
>  end;
>read (ch);
>case ch of 'q' : stop;
>end;

>(*--------------------------------------------------------*)

>Thanx alot

>Brian (remove NOSPAM for mailing)

-RK :T
r-k-r-o-l...@-i-s-t-a-r-.-c-a

Spammers will be prosecuted to the full extent of
international law.

Other Threads