Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

function can not get back?

Status
Not open for further replies.

eray81

Junior Member level 3
Joined
Jan 1, 2012
Messages
29
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,461
I wrote a function below. it must check out the incoming data from uart then it must complete himself and go back to main routine. But it doesnt. Please help.
Code:
 void incoming1(void){
  if(getc()==id1){
    goto s1;}
    s1:
    while(true){
    if(kbhit()){
    if(getc()==id2){
    goto s2;}}}
    s2:
    while(true){
    if(kbhit()){
    if(getc()==id3){
    goto s3;}}}
    s3:
    while(true){
    if(kbhit()){
    if(getc()==id4){
    goto s4;}}}
    s4:
    while(true){
    if(kbhit()){
    if(getc()==0x55){
   if(f==1){ output_high(pin_a6);output_low(pin_a7); goto s5;}
   if(f==2){ output_low(pin_a6);output_high(pin_a7);goto s5;}
  
   }
    if(getc()==0x45){ output_low(pin_a6);output_low(pin_a7);goto s5;}
   }
   }
  s5:
delay_ms(1);
}
 

I have some questions:

What is the microcontroller and the compiler that you are using?

I modify a little your code for clarify


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
void incoming1(void)
{
    if(getc()==id1)
    {
        goto s1;
    } // if(getc()==id1)
    s1:
    while(true)
    {
        if(kbhit())
        {
            if(getc()==id2)
            {
                goto s2;
            } // if(getc()==id2)
        } // if(kbhit())
    } // while(true)
    s2:
    while(true)
    {
        if(kbhit())
        {
                if(getc()==id3)
            {
                    goto s3;
            } // if(getc()==id3)
        } // if(kbhit())
    } // while(true)
    s3:
        while(true)
    {
            if(kbhit())
        {
                if(getc()==id4)
            {
                    goto s4;
            } // if(getc()==id4)
        } // if(kbhit())
    } // while(true)
    s4:
        while(true)
    {
            if(kbhit())
        {
                if(getc()==0x55)
            {
                   if(f==1)
                {
                     output_high(pin_a6);output_low(pin_a7); goto s5;
                } // if(f==1)
                   if(f==2)
                {
                     output_low(pin_a6);output_high(pin_a7);goto s5;
                } // if(f==2)
 
            } // if(getc()==0x55)
                if(getc()==0x45)
            {
                 output_low(pin_a6);output_low(pin_a7);goto s5;
            } // if(getc()==0x45)
        } // if(kbhit())
    } // while(true)
    s5:





I suggest, do not use goto's. Replace it by a break statement




Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
void incoming1(void)
{
 
    
     while (!kbhit()) // ADDED
    if(getc()==id1)
    {
        break; // Changed
    } // if(getc()==id1)
    s1:
    while(true)
    {
        if(kbhit())
        {
            if(getc()==id2)
            {
//                goto s2;
break;
            } // if(getc()==id2)
        } // if(kbhit())
    } // while(true)
    s2:
    while(true)
    {
        if(kbhit())
        {
                if(getc()==id3)
            {
        //            goto s3;
break;
            } // if(getc()==id3)
        } // if(kbhit())
    } // while(true)
    s3:
        while(true)
    {
            if(kbhit())
        {
                if(getc()==id4)
            {
        //            goto s4;
   break;
            } // if(getc()==id4)
        } // if(kbhit())
    } // while(true)
    s4:
        while(true)
    {
            if(kbhit())
        {
                if(getc()==0x55)
            {
                   if(f==1)
                {
                     output_high(pin_a6);output_low(pin_a7); goto s5;
                } // if(f==1)
                   if(f==2)
                {
                     output_low(pin_a6);output_high(pin_a7);goto s5;
                } // if(f==2)
 
            } // if(getc()==0x55)
                if(getc()==0x45)
            {
                 output_low(pin_a6);output_low(pin_a7);goto s5;
            } // if(getc()==0x45)
 
              break; // <== I suppose that's the cause that routine never returns. You missed a goto to s5, or I suggest a break here
        } // if(kbhit())
    } // while(true)
    s5:

 
Last edited by a moderator:

ı use ccs c compiler and i use pic16f886 microcontroller.
 

Check the code I posted. I maybe the last break is the sollution. The last while never outs in your code.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top