View previous topic :: View next topic |
Author |
Message |
sunangel368
Joined: 29 Mar 2009 Posts: 4
|
newbie here, don't understand the errors and warnings @@ |
Posted: Sun Mar 29, 2009 2:56 am |
|
|
Hello everyone, i'm writing a program act as a traffic on diverting high speed clock signals generated from an external source.
upon activating a bypass pin, i can generate forward/reverse signals manually.
the script is below:
Code: |
#include <18f4331.h>
#DEVICE HIGH_INTS=TRUE
#device adc=8
#use delay(clock=40M, oscillator=10M)
#fuses noprotect,nowdt,hpol_low
#include <stdlib.h>
#define up_but PIN_A0
#define down_but PIN_A1
#define bypass_but PIN_A2
#define dir_out PIN_B1
#define step_out PIN_B0
#define dir_in PIN_C1
#define step_in PIN_C0
#byte porta=5
#byte portb=6
#byte portc=7
int delay_time = 500;
void output_down_signal();
void output_up_signal();
void pass_through_signal();
void no_movement();
void main()
{
do{
if(input(bypass_but)==1 && input(up_but)==1)
{
output_up_signal();
}
else if(input(bypass_but)==1 && input(down_but)==1)
{
output_down_signal();
}
else if(input(bypass_but)==1 && input(up_but)==0 && input(down_but)==0)
{
no_movement();
}
else if(input(bypass_but)==0 && (input(up_but)==1))
{
pass_through_signal();
}
else if(input(bypass_but)==0 && (input(down_but)==1))
{
pass_through_signal();
}
}while(1);
void output_down_signal()
{
output_low(dir_out); //Lo Signal on Dir //Start Loop
output_high(step_out); //Hi on Step Signal
delay_ms(20); //Delay 20ms
output_low(step_out); //Low on Step Signal
delay_ms(delay_time); //Delay from Setting
}
void output_up_signal()
{
output_high(dir_out); //Hi Signal on Dir
output_high(step_out); //Hi on Step Signal
delay_ms(20); //Delay 20ms
output_low(step_out); //Lo on Step Signal
delay_ms(delay_time); //Delay from Setting
}
void pass_through_signal()
{
if(input(step_in)==1)
{ output_high(step_out); }
else
{ output_low(step_out); }
if(input(dir_in)==1)
{ output_high(dir_out); }
else
{ output_low(dir_out); }
}
void no_movement();
{
output_low(step_out);
output_low(dir_out);
if(input(step_in)==1)
{ output_low(step_out); }
else
{ output_low(step_out); }
if(input(dir_in)==1)
{ output_low(dir_out); }
else
{ output_low(dir_out); }
}
}
|
the errors and warnings generated are:
>>>Warning 203 "main.c" Line 58(1,1): Condition always TRUE (There shouldn't be any problem with WHILE Loop, i think.)
*** Error 51 "main.c" Line 60(1,5): A numeric expression must appear here
*** Error 51 "main.c" Line 69(1,5): A numeric expression must appear here
*** Error 51 "main.c" Line 78(1,5): A numeric expression must appear here
*** Error 51 "main.c" Line 91(1,5): A numeric expression must appear here
(The errors are something to do with void?)
Last edited by sunangel368 on Sun Mar 29, 2009 5:54 am; edited 3 times in total |
|
|
AsmallGuy Guest
|
|
Posted: Sun Mar 29, 2009 3:58 am |
|
|
Gosh, could you use the "code" .. "/code" formatting? it's kind of difficoult to read your code; also, please, can you highlight the lines indicated by the numbers where the errors appears?
About the warning, nothing to worry, it's ok for the while(1). |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Mar 29, 2009 4:07 am |
|
|
You have function definitions inside main(), that's no valid C syntax.
Place them before main() and remove the semicolon with void no_movement(); |
|
|
sunangel368
Joined: 29 Mar 2009 Posts: 4
|
|
Posted: Sun Mar 29, 2009 5:50 am |
|
|
FvM wrote: | You have function definitions inside main(), that's no valid C syntax.
Place them before main() and remove the semicolon with void no_movement(); |
FvM, i didn't see any function definitions. I only write those if and then thingy there! I don't quite understand , but thanks for the semicolon in the void no_movement()! thanks!
Last edited by sunangel368 on Sun Mar 29, 2009 6:03 am; edited 1 time in total |
|
|
sunangel368
Joined: 29 Mar 2009 Posts: 4
|
|
Posted: Sun Mar 29, 2009 5:51 am |
|
|
AsmallGuy wrote: | Gosh, could you use the "code" .. "/code" formatting? it's kind of difficoult to read your code; also, please, can you highlight the lines indicated by the numbers where the errors appears?
About the warning, nothing to worry, it's ok for the while(1). |
AsmallGuy, i'm sorry, i've never really used a forum with other functions, only other than typing! very sorry! thanks for the while comment though! |
|
|
sunangel368
Joined: 29 Mar 2009 Posts: 4
|
|
Posted: Sun Mar 29, 2009 6:18 am |
|
|
Hello FvM!
I found an extra bracket that wrecks the code! seems like the main is overlapping the whole code! Thanks!
Charles |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Mar 29, 2009 10:55 am |
|
|
The CCS C IDE editor has a useful feature of displaying matching paranthesis. It's very easy to see issues like the present one. |
|
|
|