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

How to change int for #define

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



Joined: 25 Feb 2014
Posts: 34
Location: Brazil

View user's profile Send private message

How to change int for #define
PostPosted: Wed Mar 19, 2014 6:27 pm     Reply with quote

Hi everyone! could someone help me please??

I've tried to change some constants declared as int to #define but when I do it, a lot of error is shown when i try to compile. Error: A numeric expression must appear here.
every line where is used that constants appear these error. I think it's a bug, or not?
PS: before change for #define the program runs.

I'm using the CCS Compiler version 5.018

Thanks!!

Code:

#include <18F4520.h>
#case

#FUSES HS
#FUSES PUT
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOBROWNOUT               //No brownout 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(crystal=20MHz)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,ERRORS)
#use i2c(master, fast, sda=PIN_C4, scl=PIN_C3)

#include <math.h>

//All these #define were int.
#define ADXL345_Address  0XA6; //0xA6 //0x53//0x3a
#define ACCEL_READ_ADDR  0XA7;//0xA7 //0x53//0x3b
#define ACCEL_PWRCTRL_ADDR  0x2d;
#define ACCEL_MEASURE_MODE  0x08;
#define DATA_FORMAT  0x31;
#define OUT_X0  0x32;
#define OUT_X1  0x33;
#define OUT_Y0  0x34;
#define OUT_Y1  0x35;
#define OUT_Z0  0x36;
#define OUT_Z1  0x37;

int accel_data[6];

signed int x, y, z;
unsigned int absx, absy, absz, absxyz;

float x1, y1, z1, R;
float teta=0, gama=0,fi=0;
float roll=0, pitch=0, yaw=0;

void initializingADXL345();
void accelerometer();
void cartesian_coordinates();
void spherical_coordinates();
void flight_coordinates();
void writeRegisterI2C(int8 deviceAddress, int8 address, int8 val);
int readRegisterI2C(int8 deviceAddress, int8 address);

void main()
{

enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
initializingADXL345();// initialize

   while(TRUE)
   {
  output_high(PIN_A0);
  delay_ms (10);

  accelerometer();
  cartesian_coordinates();
//  spherical_coordinates();
//  flight_coordinates();
//  printf("\n");

  output_low(PIN_A0);
  delay_ms (10);
   }

}

void initializingADXL345(){
// Tell the accelerometer to wake up
writeRegisterI2C(ADXL345_Address, DATA_FORMAT, 0X01);
writeRegisterI2C(ADXL345_Address, ACCEL_PWRCTRL_ADDR, ACCEL_MEASURE_MODE);
}

void writeRegisterI2C(int8 deviceAddress, int8 address, int8 val){
   i2c_start();               // start transmission to device
   i2c_write(deviceAddress);  // send device address
   i2c_write(address);        // send register address
   i2c_write(val);            // send value to write
   i2c_stop();                // end transmission
}

int8 readRegisterI2C(int8 deviceAddress, int8 address){
   int v;
   i2c_start();                  // start transmission to device
   i2c_write(deviceAddress);     // This is where you have to _write_ the register number you want
   i2c_write(address);           // register to read
   i2c_start();                  // restart - the bus is now set to _read_
   i2c_write(deviceAddress + 1); // now turn the bus round
   v = i2c_read(0);
   i2c_stop();                   // This will update x, y, and z with new values
   return v;
}

void accelerometer(){
// Read data from the accel
accel_data[0] = readRegisterI2C(ADXL345_Address, OUT_X0);
accel_data[1] = readRegisterI2C(ADXL345_Address, OUT_X1);
accel_data[2] = readRegisterI2C(ADXL345_Address, OUT_Y0);
accel_data[3] = readRegisterI2C(ADXL345_Address, OUT_Y1);
accel_data[4] = readRegisterI2C(ADXL345_Address, OUT_Z0);
accel_data[5] = readRegisterI2C(ADXL345_Address, OUT_Z1);

//////////concatenar datos adxl345/////////////
x=(((accel_data[1])<<8)|accel_data[0]);
y=(((accel_data[3])<<8)|accel_data[2]);
z=(((accel_data[5])<<8)|accel_data[4]);

/*
//Low Pass Filter
x=x*alpha + (x*(1-alpha));
y=y*alpha + (y*(1-alpha));
z=z*alpha + (z*(1-alpha));
*/

printf("%d %d %d\n",x,y,z);
}

void cartesian_coordinates(){ //RETORNANDO VALORES ERRADOS AO CALCULAR O VERSOR
if(x<0) absx=x*(-1); else absx=x;
if(y<0) absy=y*(-1); else absy=y;
if(z<0) absz=z*(-1); else absz=z;
absxyz=(absx*absx)+(absy*absy)+(absz*absz);
R=sqrt(absxyz);
//printf("modulos: %d, %d, %d. soma dos quadrados: %d. raiz quadrada da soma: %.2f\n",absx, absy, absz, absx*absy,R);

x1=x/R;
y1=y/R;
z1=z/R;
//printf("%.2fx, %.2fy, %.2fz\n",x1,y1,z1);
}

void spherical_coordinates(){
teta=acos(x1/R)*180/PI;
gama=acos(y1/R)*180/PI;
fi=acos(z1/R)*180/PI;
//printf("%fº, %fº, %fº (coordenadas esfericas)\n",teta,gama,fi);
}

void flight_coordinates(){
roll  = (atan2(-y, z)*180.0)/PI;
pitch = (atan2(x, sqrt(y*y + z*z))*180.0)/PI;
yaw=0;
if(roll<0) roll+=360;
if((fi>90)&&(fi<180)) pitch=(pitch-180)*(-1); //está no segundo ou terceiro quadrante. força range de 90 ate 270
else if((fi<90)&&(pitch<0)) pitch+=360; //está no quarto quadrante. força range de 270 ate 0

//printf("%fº, %fº, %fº (coordenadas de aviacao)\n",roll,pitch,yaw);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 19, 2014 6:36 pm     Reply with quote

Get rid of the semi-colons at the end of the #define statements.

Also, get rid of the enable INT_RDA interrupts and global interrupts.
You don't have any #int_rda routine in your program. If you enable
RDA interrupts without that routine, the program will crash.
Delete those two lines.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Mar 19, 2014 6:38 pm     Reply with quote

Perhaps you want to start reading on page 99 of the current
CCS manual. Your answer is there. The syntax is messed up !

really
Very Happy Very Happy Very Happy Very Happy
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