rajesh1987
Junior Member level 2
- Joined
- Dec 5, 2012
- Messages
- 21
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,283
- Activity points
- 1,430
hi
Im trying to read values from IMU sensor , but while trying to compile it shows error, while clicking any error it always goes to #include <18f4550.h> line..
the error occurring while compiling are
my code is
kindly help me to overcome this
Im trying to read values from IMU sensor , but while trying to compile it shows error, while clicking any error it always goes to #include <18f4550.h> line..
the error occurring while compiling are
Executing: "C:\Program files\Picc\CCSC.exe" +FH "imuwork.c" +DF +LN +T +A +M +Z +Y=9 +EA
*** Error 7 "imuwork.c" Line 1(0,1): Invalid Pre-Processor directive
*** Error 1 "imuwork.c" Line 1(0,1): Illegal C character in input file 0x00
*** Error 128 "imuwork.c" Line 1(0,1): A #DEVICE required before this line
*** "imuwork.c" Line 1: Error #1: Illegal C character in input file 0x00
*** "imuwork.c" Line 1: Error #48: Expecting a (
*** "imuwork.c" Line 1: Error #1: Illegal C character in input file 0x00
6 Errors, 0 Warnings.
my code is
Code:
#include <18F4550.h>
#fuses NOWDT,HS,NOPROTECT,NOLVP
//#fuses HS,MCLR,NOWDT,NOPROTECT,NOLVP,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=4000000)
#use i2c(Master,sda=PIN_B0,scl=PIN_B1)
#include<lcd.c>
#define LCD_ENABLE_PIN PIN_C2
#define LCD_RS_PIN PIN_C0
#define LCD_RW_PIN PIN_C1
#define DATA_PORT PORTD
//#include<lcd.c>
//#include <imu.C>
#define L3G_DEVICE_AUTO 0
#define L3G4200D_DEVICE 1
#define L3GD20_DEVICE 2
// SA0 states
#define L3G_SA0_LOW 0
#define L3G_SA0_HIGH 1
#define L3G_SA0_AUTO 2
// register addresses
#define gyro_ADD_W 0b11010110
#define gyro_ADD_R 0b11010111
#define L3G_WHO_AM_I 0x0F
#define L3G_CTRL_REG1 0x20
#define L3G_CTRL_REG2 0x21
#define L3G_CTRL_REG3 0x22
#define L3G_CTRL_REG4 0x23
#define L3G_CTRL_REG5 0x24
#define L3G_REFERENCE 0x25
#define L3G_OUT_TEMP 0x26
#define L3G_STATUS_REG 0x27
#define L3G_OUT_X_L 0x28
#define L3G_OUT_X_H 0x29
#define L3G_OUT_Y_L 0x2A
#define L3G_OUT_Y_H 0x2B
#define L3G_OUT_Z_L 0x2C
#define L3G_OUT_Z_H 0x2D
#define L3G_FIFO_CTRL_REG 0x2E
#define L3G_FIFO_SRC_REG 0x2F
#define L3G_INT1_CFG 0x30
#define L3G_INT1_SRC 0x31
#define L3G_INT1_THS_XH 0x32
#define L3G_INT1_THS_XL 0x33
#define L3G_INT1_THS_YH 0x34
#define L3G_INT1_THS_YL 0x35
#define L3G_INT1_THS_ZH 0x36
#define L3G_INT1_THS_ZL 0x37
#define L3G_INT1_DURATION 0x38
#define LSM303DLH_DEVICE 0
#define LSM303DLM_DEVICE 1
#define LSM303DLHC_DEVICE 2
#define LSM303_DEVICE_AUTO 3
// SA0_A states
#define LSM303_SA0_A_LOW 0
#define LSM303_SA0_A_HIGH 1
#define LSM303_SA0_A_AUTO 2
// register addresses
#define acce_ADD_W 0b00110010
#define acce_ADD_R 0b00110011
#define LSM303_CTRL_REG1_A 0x20
#define LSM303_CTRL_REG2_A 0x21
#define LSM303_CTRL_REG3_A 0x22
#define LSM303_CTRL_REG4_A 0x23
#define LSM303_CTRL_REG5_A 0x24
#define LSM303_CTRL_REG6_A 0x25
#define LSM303_REFERENCE_A 0x26
#define LSM303_STATUS_REG_A 0x27
#define LSM303_OUT_X_L_A 0x28
#define LSM303_OUT_X_H_A 0x29
#define LSM303_OUT_Y_L_A 0x2A
#define LSM303_OUT_Y_H_A 0x2B
#define LSM303_OUT_Z_L_A 0x2C
#define LSM303_OUT_Z_H_A 0x2D
#define LSM303_FIFO_CTRL_REG_A 0x2E
#define LSM303_FIFO_SRC_REG_A 0x2F
#define LSM303_INT1_CFG_A 0x30
#define LSM303_INT1_SRC_A 0x31
#define LSM303_INT1_THS_A 0x32
#define LSM303_INT1_DURATION_A 0x33
#define LSM303_INT2_CFG_A 0x34
#define LSM303_INT2_SRC_A 0x35
#define LSM303_INT2_THS_A 0x36
#define LSM303_INT2_DURATION_A 0x37
#define LSM303_CLICK_CFG_A 0x38
#define LSM303_CLICK_SRC_A 0x39
#define LSM303_CLICK_THS_A 0x3A
#define LSM303_TIME_LIMIT_A 0x3B
#define LSM303_TIME_LATENCY_A 0x3C
#define LSM303_TIME_WINDOW_A 0x3D
#define magn_ADD_W 0b00111100
#define magn_ADD_R 0b00111101
#define LSM303_CRA_REG_M 0x00
#define LSM303_CRB_REG_M 0x01
#define LSM303_MR_REG_M 0x02
#define LSM303_OUT_X_H_M 0x03
#define LSM303_OUT_X_L_M 0x04
#define LSM303_OUT_Y_H_M 0x05
#define LSM303_OUT_Y_L_M 0x06
#define LSM303_OUT_Z_H_M 0x07
#define LSM303_OUT_Z_L_M 0x08
#define LSM303_SR_REG_M 0x09
#define LSM303_IRA_REG_M 0x0A
#define LSM303_IRB_REG_M 0x0B
#define LSM303_IRC_REG_M 0x0C
#define LSM303_TEMP_OUT_H_M 0x31
#define LSM303_TEMP_OUT_L_M 0x32
int8 konum=0, hesapH=0,hesapL=0;
signed long hesap=0;
void writeRegister(int8 reg,int8 value,int tur)
{
i2c_start();
i2c_write(tur);
i2c_write(reg);
i2c_write(value);
i2c_stop();
}
void init_gyro()
{
writeRegister(L3G_CTRL_REG1,0b11101111,gyro_ADD_W);
writeRegister(L3G_CTRL_REG2,0b00000000,gyro_ADD_W);
writeRegister(L3G_CTRL_REG4,0b0010000,gyro_ADD_W);
}
void init_acce()
{
writeRegister(LSM303_CTRL_REG1_A,0x47,acce_ADD_W);
writeRegister(LSM303_CTRL_REG4_A,0b00101000,acce_ADD_W);
}
void init_magn()
{
writeRegister(LSM303_SR_REG_M, 0b00000001,magn_ADD_W);
writeRegister(LSM303_IRA_REG_M,0b01001000,magn_ADD_W);
writeRegister(LSM303_IRB_REG_M,0b00110100,magn_ADD_W);
writeRegister(LSM303_IRC_REG_M,0b00110011,magn_ADD_W);
writeRegister(LSM303_CRA_REG_M,0b10010000,magn_ADD_W);
writeRegister(LSM303_CRB_REG_M,0b10000000,magn_ADD_W);
writeRegister(LSM303_MR_REG_M, 0b00000000,magn_ADD_W);
}
int a;
void Hesapla_Yaz(int adresR,int adresW) //adresR=device Read adres,adresW =device write adres
{
int i;a=1;int b=0;char c;
for ( i=40;i<46;i+=2) //40=0x28 xHbit, 42=0x2b yHbit, 44=0x2d zHbit
{
b=i; //b=hbit, b+1=lbit. acce,gyro xHbit=0x28 xLbit=029
if (adresR==magn_ADD_R)
{
konum=2;
b=i-37;//magnetometer xLbit=3 xHbit=4,yLbit=5 yHbit=6,zHbit=7,zHbit=8
c="m";
}
i2c_start();i2c_write(adresW);i2c_write(b);i2c_start();i2c_write(adresR);hesapH=i2c_read(),i2c_read(0);i2c_stop(); //hesapH=device x or y or z hbit
i2c_start();i2c_write(adresW);i2c_write(b+1);i2c_start();i2c_write(adresR);hesapL=i2c_read(),i2c_read(0);i2c_stop(); //hesapL=device x or y or z Lbit
hesap=make16(hesapH,hesapL);//hesap =long variable
if (adresR==acce_ADD_R)
{
konum=3;//lcd line
hesap=hesap>>4; //Accelerometer: one 12-bit reading (left-justified) per axis
c="a";
}
if (adresR==gyro_ADD_R)
{
c="g";
konum=4;
}
Lcd_gotoxy(konum+8, 1);
printf(lcd_putc,"\%c",c);
Lcd_gotoxy(1, 1);
printf(lcd_putc,"satirlar=");//lcd 2x16 for konum=1 or 2
Lcd_gotoxy(a, konum);
printf(lcd_putc,"\%Ld",hesap);
a=a+6; //lcd row
}
}
void main()
{
set_tris_c(0x00); //FE
set_tris_D(0x00);
lcd_init();
printf(lcd_putc, "\f");
lcd_gotoxy(1, 1);
printf(lcd_putc, "minimu9 v2");
init_gyro();
init_acce();
init_magn();
lcd_init();
while(1)
{
hesapla_yaz(gyro_ADD_R,gyro_ADD_W); //only gyro
hesapla_yaz(acce_ADD_R,acce_ADD_W); //only accelometer
init_magn(); //not work Without this.//compas for
hesapla_yaz(magn_ADD_R,magn_ADD_W);//compas
delay_ms(100);
printf(lcd_putc"\f");
}
}
kindly help me to overcome this