View previous topic :: View next topic |
Author |
Message |
umka
Joined: 28 Aug 2007 Posts: 99 Location: New Zealand
|
how to get into a sub routine |
Posted: Sun Nov 18, 2007 7:44 pm |
|
|
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 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
umka
Joined: 28 Aug 2007 Posts: 99 Location: New Zealand
|
|
Posted: Mon Nov 19, 2007 12:17 am |
|
|
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
|
|
Posted: Mon Nov 19, 2007 12:19 am |
|
|
What PIC are you using ?
Are you using the demo version of compiler ? |
|
|
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Mon Nov 19, 2007 5:28 am |
|
|
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
|
|
Posted: Mon Nov 19, 2007 1:59 pm |
|
|
sorry using a PIC16f877a
i think compiler is called pcm 4.038. |
|
|
umka
Joined: 28 Aug 2007 Posts: 99 Location: New Zealand
|
|
Posted: Tue Nov 20, 2007 8:06 pm |
|
|
cheers set works a treat |
|
|
|