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 support@ccsinfo.com

how to get into a sub routine

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



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

how to get into a sub routine
PostPosted: Sun Nov 18, 2007 7:44 pm     Reply with quote

i am writing a program and dont know how to get from the main routine into a differant one. say i have:

Code:
void main()
   {
   
   some code

   While (1)
   
      read ADC

      if ADC == 10

      {
         go to sub 1
      }

      if ADC == 20

      {
         got o sub 2
      }

      line 1 display string 1
      line 2 display string 2
      line 3 display string 3

   }

void sub 1 (viod)

   {
   define string 1
   define string 2
   define string 3
   }

void sub 2 (viod)

   {
   define string 1
   define string 2
   define string 3
   }


how does one get from the while (1) loop into the void sub1 (void) and void sub2 (void) to get 3 strings and then back into the while loop?

please help this is kind of urgent Embarassed
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 18, 2007 9:12 pm     Reply with quote

See the program in this link. You call a function by name, and
give it parameters if that's part of the function's definition.
http://www.ccsinfo.com/forum/viewtopic.php?t=32168&start=1
umka



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

PostPosted: Mon Nov 19, 2007 12:17 am     Reply with quote

if i put all the sub routines in the while loop it runs out of rom.

in each sub routines there is 5 to 15 if statements so as to set the 3 strings.

once out of the sub i want the program to go back into the while loop witht he 3 string it has just gotten.

then display the strings on a lcd.

i have written the code but it is 1500 lines long in c so dont want to post unless u think this might help.

i just need a means of getting out of the while loop going through some if statements getting the 3 string and then returning to the while loop and displaying the string
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 19, 2007 12:19 am     Reply with quote

What PIC are you using ?

Are you using the demo version of compiler ?
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Nov 19, 2007 5:28 am     Reply with quote

Something like:

Code:
char *pstring1,*pstring2,*pstring3;

const char s1[] = "string1";
// etc

void sub_1 (void)

   {
   pstring1 = s1;
   pstring2 = s2;
   pstring3 = s3;
   }

void sub_2 (void)

   {
   pstring1 = s4;
   pstring2 = s5;
   pstring3 = s6;

   }

void main()
{
   
   // some code

   While (1)
    {
      //read ADC

      if (ADC == 10 )

      {
         sub_1();
      }

      if (ADC == 20 )

      {
         sub_2();
      }

      display (line1,  pstring1);
      display (line2, pstring2);
      display (line3, pstring3);
   }
}
 
umka



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

PostPosted: Mon Nov 19, 2007 1:59 pm     Reply with quote

sorry using a PIC16f877a

i think compiler is called pcm 4.038.
umka



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

PostPosted: Tue Nov 20, 2007 8:06 pm     Reply with quote

cheers set works a treat
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