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

Very Simple Declaration Question

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



Joined: 13 Nov 2005
Posts: 8

View user's profile Send private message

Very Simple Declaration Question
PostPosted: Sun Nov 13, 2005 10:50 pm     Reply with quote

I'm a beginner, and I keep getting this error 'A numeric expression must appear here' referring to the int declaration in the following code I found on the board:
---------------------------------------------
#include <16F877.h>
#include <button.c>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

int option1=0; //B0
int option2=0; //A4

void main() {
printf("\n\rStart: ");

set_tris_a(0x10); // Set Pin A4 as input
set_tris_b(0x01); // Set Pin B0 as input
while(1)
{
if(button(PIN_B0, 0, 50, 10, option1, 1))
printf("B");

if(button(PIN_A4, 0, 50, 10, option2, 1))
printf("A");

delay_ms(10);
}

}
---------------------------

I don't understand why the error is occuring!! I have spent about an hour an a silly int declaration. Please help!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 13, 2005 11:50 pm     Reply with quote

Quote:
I keep getting this error 'A numeric expression must appear here'

Post your compiler version.
If you don't know the version, then this thread tells different ways to find it:
http://www.ccsinfo.com/forum/viewtopic.php?t=23441
honeytree



Joined: 13 Nov 2005
Posts: 8

View user's profile Send private message

PostPosted: Mon Nov 14, 2005 12:03 am     Reply with quote

PCWH Complier

IDE 3.235
PCM 3.236d
PCH 3.236d
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 14, 2005 12:40 am     Reply with quote

You're using the demo, within the PCW IDE.
I installed the command line compiler, PCM vs. 3.236, and compiled
within MPLAB and didn't get any errors.

Can you try the following program and see if you get any errors ?
You said your problem is with the declaration of the variables, so this
little program will test just that issue.
Code:

#include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)

int option1=0; 
int option2=0; 

void main()
{


while(1);
}
 
honeytree



Joined: 13 Nov 2005
Posts: 8

View user's profile Send private message

PostPosted: Mon Nov 14, 2005 12:46 am     Reply with quote

This code works fine.


#include <16F877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)

int option1=0;
int option2=0;

void main()
{


while(1);
}
------------------------------------------------------------------
I tried again with the below code and still get the error. Do I need to reinstall the software?
---------------------------------------------------------------
#include <16F877.h>
#include <button.c>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

// These are the "Bvar" variables.
//

int button1=0; //B0
int button2=0; //A4




// Function parameters:
//
// button(pin, DownState, Delay, Rate, BVar, Action)
//
// Returns: The value of the Action variable (normally
// set = 1) is returned when the button is
// pressed. When the button isn't pressed,
// the opposite value is returned (normally 0).
//======================================
void main() {
printf("\n\rStart: ");

set_tris_a(0x10); // Set Pin A4 as input
set_tris_b(0x01); // Set Pin B0 as input

// This shows how to do a button loop. The PicDem2-Plus
// board has buttons on pins RA4 and RB0. There is one
// button() function below for each button. When the
// button on RB0 is pressed, "B" is displayed on the
// terminal window. When the RA4 button is pressed, "A"
// is displayed. If you hold the buttons down for more
// than 1/2 second, they will auto-repeat 10 times per
// second.

while(1)
{
if(button(PIN_B0, 0, 50, 10, button1, 1))
printf("B");

if(button(PIN_A4, 0, 50, 10, button2, 1))
printf("A");

// You must use a delay statement in the loop.
// A good value to use is 10 ms.
delay_ms(10);
}

}
}
honeytree



Joined: 13 Nov 2005
Posts: 8

View user's profile Send private message

PostPosted: Mon Nov 14, 2005 12:57 am     Reply with quote

It actually runs without error until the button.c is included (see below)


//=====================================
// The following macro is used by the Button function.
#define read_bit_var(x) bit_test(*(int *)(x >> 3), x & 7)


//=====================================
int button(int16 pin, int downstate, int delay,
int rate, int &BVar, int action)
{
int pin_value;

// Read the button pin.
pin_value = read_bit_var(pin);

// Check if the button is pressed. It's pressed if the
// pin value is the same as the "downstate". If it's not
// pressed, then zero the Bvar and return "Not pressed".
if(pin_value != downstate)
{
Bvar = 0;
return(!action);
}

// The button is pressed. Check to see if it's a new
// keypress. We can tell if it's a new keypress by
// checking if BVar = 0. If so, load the counter with
// the initial auto-repeat delay and return "Pressed".
// (If the delay has been set to 0, then load a non-zero
// value to allow the function to operate properly).
if(Bvar == 0)
{
if(delay == 0)
Bvar = 255;
else
Bvar = delay;

return(action);
}

// Decrement the auto-repeat counter.
Bvar--;

// Check if we just counted down to 0. If so, then load
// the counter with the auto-repeat interval and return
// "Pressed". If the delay is set to 0 or 255, it means
// that auto-repeat is disabled, so fall through and
// return "Not Pressed".
if(BVar == 0)
{
BVar = rate;

if((delay != 0) && (delay != 255))
return(action);
}

// If the counter is positive, then it means an auto-repeat
// is still pending, so return "Not Pressed".
return(!action);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Nov 14, 2005 1:03 am     Reply with quote

I'll download the demo and test it tomorrow morning.
Ttelmah
Guest







PostPosted: Mon Nov 14, 2005 3:42 am     Reply with quote

As posted, the 'button' function, has no terminating '}'. If this is what is actually being included,then it'll cause a syntax error latter in the code, as is being displayed.......

Best Wishes
honeytree



Joined: 13 Nov 2005
Posts: 8

View user's profile Send private message

PostPosted: Mon Nov 14, 2005 6:48 am     Reply with quote

still receive the same error with button function correctly terminated. thanks,
honeytree



Joined: 13 Nov 2005
Posts: 8

View user's profile Send private message

PostPosted: Mon Nov 14, 2005 9:14 am     Reply with quote

Nevermind!! I ran the code on another computer and it works fine. Strange.

Thanks.
Ttelmah
Guest







PostPosted: Mon Nov 14, 2005 9:29 am     Reply with quote

The normal reason for this, is that the compiler is finding a different 'button.c', to the once you think it is loading. Hint here. The '<' brackets, mean to search in the compilers 'system' paths. If instead you bracket with ", then the compiler searches the loal directory by default. Normally the '<' brackets should be reserved for 'system includes' (things like stdio.h etc.), to avoid this behaviour.

Best Wishes
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