View previous topic :: View next topic |
Author |
Message |
Vincent112
Joined: 30 Jul 2011 Posts: 4
|
Help needed |
Posted: Wed Nov 02, 2011 10:03 am |
|
|
Hi all, sorry for the newbie question but I've encounter some error while trying to compile my source file.
int Ring_counts = 0;
unsigned char Input_from_porta = 0x00;
when I try to compile it, errors occur.
error 51 : A numeric expression must appear here.
Did I do something wrong in declaring a variable? Thanks in advance for the helps given. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Wed Nov 02, 2011 10:23 am |
|
|
Triple check the lines _in front_ of the error line.
What you post is fine, but errors like this occur on the first occasion where the result becomes impossible for the compiler. This means that an error on a line, can show as a problem several lines latter, not in the actual line where the fault is.
Also look at the placement of the lines - need to be outside the functions for global declarations, or at the start of a function segment, for others. Indeterminate errors can occur if they are in the wrong location.
Also look carefully at things like function names. If you have a function called 'Ring_counts', or one called Input_from_porta, you can't also have a variable with the same name.
If you can't see what is wrong, cut and past say the ten lines up to and including the fault ones here, and we may be able to help.
Best Wishes |
|
|
Vincent112
Joined: 30 Jul 2011 Posts: 4
|
|
Posted: Wed Nov 02, 2011 10:32 am |
|
|
Code: | void main()
{
while (true)
{
detect_count_offhook();
play_message1();
hangs_up ();
}
}
void detect_count_offhook(void)
{
set_tris_a(all_in);
set_tris_c(all_out);
int Ring_counts = 0;
unsigned char Input_from_porta = 0x00;
while (ring_counts <= max_number_of_rings)
{
input_from_porta = port_a;
if ((input_from_porta & mask_bit0)== 0)
{
ring_counts +=1;
delay_ms (3000);
}
}
port_c = pc0_high;
}
|
is this sufficient enough? because I'm taking reference a sample coding from internet. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 02, 2011 11:34 am |
|
|
Quote: | void detect_count_offhook(void)
{
set_tris_a(all_in);
set_tris_c(all_out);
int Ring_counts = 0;
unsigned char Input_from_porta = 0x00;
|
CCS wants variable declarations to be placed at the start of the function.
Place lines of code after that. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Wed Nov 02, 2011 3:39 pm |
|
|
Not only CCS.
_C_ requires this.
It is only latter extended languages like C++, that allow 'inline' declarations like this.
Best Wishes |
|
|
|