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 support@ccsinfo.com

error on my compiler 4.100

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



Joined: 08 Apr 2010
Posts: 11

View user's profile Send private message

error on my compiler 4.100
PostPosted: Tue May 24, 2011 8:37 am     Reply with quote

Hi everyone,
I am a new C programmer and i write a simple code but already have problem.
the error message says that "Error 51, a numeric expression must be here".
this happen right at my variable delaration such as int and float.

below is my code
#include "C:\Microcontroller Firmware Center\main-18F.h"
#include "C:\Microcontroller Firmware Center\Flex_LCD.c"
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdlibm.h>
#include <string.h>
#define START_BUTTON PIN_C0
#define STOP_BUTTON PIN_B0
#define STATUS_LED PIN_C1
#define EXEC_STATUS PIN_C2

void Blink_LED (int flash_time, int flash_delay);
void LCD_Test();

void main()
{
setup_adc_ports(AN0|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_4|ADC_TAD_MUL_20);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// setup_oscillator(OSC_20MHZ|OSC_INTRC|OSC_31250|OSC_PLL_ON);

// TODO: USER CODE!!
lcd_init();
LCD_Test();
float Pressure_Sensor_Scale = 0.0005; <---- Error happen at this point.
float data_in = 0, Pressure_Read = 0, Vref = 5.000, adc_resolution = 1023.00;
set_adc_channel(0);
output_high(STATUS_LED);
printf("Press START_BUTTON NOW!\n\r");
while (TRUE)
{
while (input(START_BUTTON) == 1 )
{
// output_toggle(STATUS_LED);
// delay_ms(100);
;
}
// Blink_LED (3,100);
// data_in = read_adc();
data_in = (float)(read_adc() * Vref)/adc_resolution;
Pressure_Read = (float)(data_in / Pressure_Sensor_Scale);
printf("Sensor Output Voltage is: %3.3fV \n\r", data_in);
printf(lcd_putc, "Pressure Read is: %3.3f PSI \n\r", Pressure_Read);
printf(lcd_putc, "\fThis is the 1st line");
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue May 24, 2011 9:08 am     Reply with quote

Although some CCS C versions tolerate it, the C standard (in contrast to C++) doesn't allow variable declarations in the middle of the code.
olivier



Joined: 08 Apr 2010
Posts: 11

View user's profile Send private message

PostPosted: Tue May 24, 2011 9:27 am     Reply with quote

FvM wrote:
Although some CCS C versions tolerate it, the C standard (in contrast to C++) doesn't allow variable declarations in the middle of the code.

thank you for replying me back. I have a CCS compiler. and as you mention, it should tolerate my define the variable however it was not.
i try it at the top and it work. so weird. same compiler but at different computer does not work the same.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed May 25, 2011 2:10 am     Reply with quote

Though the later compilers will tolerate declarations inside the code. You _must_ still always declare variables before they are used.
This is why it fails in what you post.
It is always better to stick to C syntax and declare at the start. It makes the code portable to other C's, and avoids this type of problem.

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