View previous topic :: View next topic |
Author |
Message |
faridh3
Joined: 17 Mar 2014 Posts: 21
|
how to use goto / SOLVED |
Posted: Tue Mar 18, 2014 8:29 am |
|
|
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
|
|
Posted: Tue Mar 18, 2014 8:41 am |
|
|
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
|
|
Posted: Tue Mar 18, 2014 12:00 pm |
|
|
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
|
|
Posted: Tue Mar 18, 2014 12:02 pm |
|
|
Thank you guys
I have worked without using it, i found a way. |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Tue Mar 18, 2014 12:09 pm |
|
|
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
|
|
Posted: Tue Mar 18, 2014 12:21 pm |
|
|
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
|
|
Posted: Tue Mar 18, 2014 12:25 pm |
|
|
As the original poster, simply 'edit' the Subject line and include 'solved'.
hth
jay |
|
|
|