CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

for loop

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
zeyad



Joined: 24 Feb 2015
Posts: 22

View user's profile Send private message

for loop
PostPosted: Fri Feb 27, 2015 2:20 am     Reply with quote

how to merge these lines into a for loop???
Code:

void s1( )
{
output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);
output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
delay_ms(50);

}
oxo



Joined: 13 Nov 2012
Posts: 219
Location: France

View user's profile Send private message

PostPosted: Fri Feb 27, 2015 3:27 am     Reply with quote

Please mods ban this numpty
zeyad



Joined: 24 Feb 2015
Posts: 22

View user's profile Send private message

for loop
PostPosted: Fri Feb 27, 2015 3:45 am     Reply with quote

oxo wrote:
Please mods ban this numpty


english please
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Feb 27, 2015 11:49 am     Reply with quote

You appear to be repeating the following code several times over
Code:
delay_ms(50);output_b(3);
delay_ms(50);
output_b(6);
delay_ms(50);
output_b(12);
delay_ms(50);
output_b(9);
Get a basic 'C' manual. You will find it in there.

Mike
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri Feb 27, 2015 1:39 pm     Reply with quote

this code is as foolish as the year is long.....

set the port ONCE
and if you need all that delay - add it up and execute a SINGLE delay.\

two lines of code do it all and
there will be no change in function performance except
a lot less code space will be used.

Proteus only teaches you that to really learn,
you should work with hardware instead.

you posted this same ridiculous code in another thread and still don't say what on earth you think it accomplishes.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Feb 27, 2015 3:34 pm     Reply with quote

stepping motor drive ?
3,6,12,9 for ever......
rotates 2 bits
ad nauesum


Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 27, 2015 3:44 pm     Reply with quote

You need to put your PortB values in an array. Then use a for loop to
read the values from the array. Similar to the code shown in the
first example here:
http://stackoverflow.com/questions/13466623/how-to-look-up-sine-of-different-frequencies-from-a-fixed-sized-lookup-table
Except in CCS, the array index 'i' should be declared as 'int16' if you
have a large array of data.

That's enough knowledge to get you going. You also need to study
the C language.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Feb 27, 2015 4:04 pm     Reply with quote

Sorry guys, but can we please close this thread?
It is a duplicate, the same problem is already being discussed in his other thread: http://www.ccsinfo.com/forum/viewtopic.php?t=53579
zeyad



Joined: 24 Feb 2015
Posts: 22

View user's profile Send private message

thank you pcm programmer. it works
PostPosted: Mon Mar 02, 2015 9:44 pm     Reply with quote

PCM programmer wrote:
You need to put your PortB values in an array. Then use a for loop to
read the values from the array. Similar to the code shown in the
first example here:
http://stackoverflow.com/questions/13466623/how-to-look-up-sine-of-different-frequencies-from-a-fixed-sized-lookup-table
Except in CCS, the array index 'i' should be declared as 'int16' if you
have a large array of data.

That's enough knowledge to get you going. You also need to study
the C language.


thank you pcm programmer. it works
zeyad



Joined: 24 Feb 2015
Posts: 22

View user's profile Send private message

stepper motor
PostPosted: Mon Mar 02, 2015 9:48 pm     Reply with quote

temtronic wrote:
stepping motor drive ?
3,6,12,9 for ever......
rotates 2 bits
ad nauesum


Jay


yes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group