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

how to use goto / SOLVED

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



Joined: 17 Mar 2014
Posts: 21

View user's profile Send private message Send e-mail

how to use goto / SOLVED
PostPosted: Tue Mar 18, 2014 8:29 am     Reply with quote

Hello,
I got an error for the way i used the 'goto' function
How am i supposed to use it ?
Thank you.

Farid

Code:
#include <18F4520.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES XT                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)

#use delay(clock=4000000)

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)

#include "LCD2x16.h"

void main() {

   set_tris_a(0xD5);
   set_tris_b(0x55);
   set_tris_c(0x55);
   lcd_init();
   int i=1;
   int level;
   int counterR;
   int counterL;
   loop
   do
   {
   counterR=6;
   counterL=5;
   
   level=input_state(PIN_A0);
   if(level==0)
      {output_low(PIN_A1);}
   else{
      output_high(PIN_A1);
      counterL--;
   }
     
   level=input_state(PIN_A2);
   if(level==0)
      output_low(PIN_A3);
   else{
      output_high(PIN_A3);
      counterL--;
   }
     
   level=input_state(PIN_A4);
   if(level==0)
      output_low(PIN_A5);
   else{
      output_high(PIN_A5);
      counterL=counterL-1;
   }
   
   level=input_state(PIN_B0);
   if(level==0)
      output_low(PIN_B1);
   else{
      output_high(PIN_B1);
      counterL=counterL-1;
   }
   
   level=input_state(PIN_B2);
   if(level==0)
      output_low(PIN_B3);
   else{
      output_high(PIN_B3);
      counterL=counterL-1;
   }
   
   level=input_state(PIN_B4);
   if(level==0)
      output_low(PIN_B5);
   else{
      output_high(PIN_B5);
      counterR=counterR-1;
   }
   
   level=input_state(PIN_B6);
   if(level==0)
      output_low(PIN_B7);
   else{
      output_high(PIN_B7);
      counterR=counterR-1;
   }
   
   level=input_state(PIN_C0);
   if(level==0)
      output_low(PIN_C1);
   else{
      output_high(PIN_C1);
      counterR=counterR-1;
   }
   
   level=input_state(PIN_C2);
   if(level==0)
      output_low(PIN_C3);
   else{
      output_high(PIN_C3);
      counterR=counterR-1;
   }
   
   level=input_state(PIN_C4);
   if(level==0)
      output_low(PIN_C5);
   else{
      output_high(PIN_C5);
      counterR=counterR-1;
   }
   
  level=input_state(PIN_C6);
   if(level==0)
      output_low(PIN_C7);
   else{
      output_high(PIN_C7);
      counterR=counterR-1;
   }
   
   if(counterR==6 && counterL==5){
      goto loop;
   }
   else{
      lcd_putc('\f');
      printf(lcd_putc, "<%d            %d>\nFARID / HABIB   ",counterL,counterR);
   }
   
   }
   while(i==1);
   
   

}


Last edited by faridh3 on Tue Mar 18, 2014 12:38 pm; edited 1 time in total
stinky



Joined: 05 Mar 2012
Posts: 99
Location: Central Illinois

View user's profile Send private message

PostPosted: Tue Mar 18, 2014 8:41 am     Reply with quote

Best practice to avoid it and choose another method for program flow. http://xkcd.com/292/
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Mar 18, 2014 12:00 pm     Reply with quote

the goto must go to a label identified as

label:


in your case, "loop:" (<-- That's a COLON, not a semi-colon.)

But it really should be avoided at all costs.

(I'll admit, I've seen some cases where it actually makes sense to use... but I still avoid it at all costs.)

Your case is not one of them.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
faridh3



Joined: 17 Mar 2014
Posts: 21

View user's profile Send private message Send e-mail

PostPosted: Tue Mar 18, 2014 12:02 pm     Reply with quote

Thank you guys
I have worked without using it, i found a way.
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Mar 18, 2014 12:09 pm     Reply with quote

Then considering marking the topic with "SOLVED" in the subject so people know..


and posting your solution.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
faridh3



Joined: 17 Mar 2014
Posts: 21

View user's profile Send private message Send e-mail

PostPosted: Tue Mar 18, 2014 12:21 pm     Reply with quote

I am sorry but i am new at this .. how can i mark it as solved ?
temtronic



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

View user's profile Send private message

PostPosted: Tue Mar 18, 2014 12:25 pm     Reply with quote

As the original poster, simply 'edit' the Subject line and include 'solved'.

hth
jay
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