|
|
View previous topic :: View next topic |
Author |
Message |
rajm
Joined: 06 Nov 2012 Posts: 29
|
minIMu9v2 problem |
Posted: Tue Mar 05, 2013 10:09 pm |
|
|
My sensor is minIMU9v2 from pololu, the link is:
[ http://www.pololu.com/catalog/product/1268 ]
I have written code to read accelerometer values from the three sensor with in it, but im not getting anything, someone do the changes to read the sensor values.. this code i have edited from other sensor code, the link for orginal code from wich i edited was:
[ http://rigodenshi.blogspot.in/2010/10/accelerometer-lis3lv02dl-controlled-by.html ], which will print result in pc, but i need to print it in lcd.
my code is:
Code: |
#include <18f4550.h>
#device ADC=10
#fuses HS,MCLR,NOWDT,NOPROTECT,NOLVP,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,stream=Rec_Dat) /*Set USART to 9600 Baudrate */
#use I2C(master,sda=PIN_B0, scl=PIN_B1, force_hw) /*Set I2C Settings */
#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>
//long int n,ch0;
//unsigned int i,I2c_Data[10];
int x_acc, y_acc, z_acc; //x,y,z-data_16bit
float X_out; //Define floating variables for results in G units
float Y_out;
float Z_out;
#define WRITE 0x32
#define READ 0x33
#define REG1_A 0x20
#define REG2_A 0x21
#define OUT_X_L_A 0x28
#define OUT_X_H_A 0x29
#define OUT_Y_L_A 0x2A
#define OUT_Y_H_A 0x2B
#define OUT_Z_L_A 0x2C
#define OUT_Z_H_A 0x2D
int read_acc(int address_out); //reading
long acc_change(int data_H,int data_L); //change
float convert_into_g(int data);
/*void WriteData(unsigned char address, unsigned char data)
{
i2c_start();
i2c_write(0x98);
i2c_write(address);
i2c_write(data);
i2c_stop();
delay_ms(100);
}*/
//#define LED PIN_B2
int read_acc(int address_out)
{
int DL=0x00, DH=0x00;
int out = 0;
i2c_start(); //Start communication
i2c_write(WRITE); //prepare the device to receive data
i2c_write(address_out|0x80); //address register, autoincrement of address
i2c_start(); //
i2c_write(READ); //Prepares the device to be read
DL=i2c_read(); //Read data LSB
DH=i2c_read(0); //Read data MSB
i2c_stop(); //Stop condition
//concatenating result
out=DL|((DH&0x0F)<<8); //Join the LSB and the MSB
return(out); //Returns the result
}
float convert_into_g(int data)
{
float output;
output=(float)data; //Converts integer data into float
if (data>=2048) //check if the result is indicating a negative value
{
output=(output/1024)-4; //Converts into g
}
if (data<2048) //if the result indicates a positive value
{
output=output/1024; //converts into g
}
return(output); //Returns the result
}
void main()
{
//setup_adc_ports(NO_ANALOGS);
lcd_init();
set_tris_c(0xff);
set_tris_d(0x00);
//i2c_start();
//i2c_write(0x6B);
//WriteData(0x30,0xFF);
i2c_start(); //Sends a start command to the device
i2c_write(WRITE); //Sends a single byte preparing the device to receive data
i2c_write(REG1_A); //Indicate the device's addres to be modified
i2c_write(0x19); //11100111 = C7-->Turn on device activating all the axis, 640Hz sampling rate
i2c_stop(); //Stop I2C transmission
i2c_start(); //Start I2C communication
i2c_write(WRITE); //Sends command to write data
i2c_write(REG2_A); //Address the control register 2
i2c_write(0x40); //01000001 --> 2g, no update between readings,12bits right justified
i2c_stop(); //Close trasmmision
while(true)
{
lcd_gotoxy(1,1);
lcd_putc(" acc:");
//output_high(LED);
x_acc = read_acc(OUT_X_L_A); //Read data for the x axis
y_acc = read_acc(OUT_Y_L_A); //Read data for the y axis
z_acc = read_acc(OUT_Z_L_A); //Read data for the z axis
X_out=convert_into_g(x_acc); //Converts binary value into g
Y_out=convert_into_g(y_acc);
Z_out=convert_into_g(z_acc);
lcd_gotoxy(2,2);
printf( LCD_PUTC, X_out " %g=%u ", X_out); //display //send results over RS232
printf(LCD_PUTC, Y_out " %g =%u", Y_out); //display
printf(LCD_PUTC, Z_out "%g=%u \n \r", Z_out); //display
delay_ms(10); //delay for sampling 100Hz
//output_low(LED);
//WriteData(0x30,0xFF);
// i2c_start(); /* Read Mode */
//i2c_write(0x99);
//i2c_write(0x6B);
// for(i=0;i<7;i++)
// {
//I2c_Data[i]=i2c_read(0x28); /* Read Data */
// }
//I2c_Data[i]=i2c_read(0);
// lcd_gotoxy(2,2);
//printf("\n\rX=%u",I2c_Data[0]); /* Send X-axis value */
//printf(" Y=%u",I2c_Data[1]); /* Send Y-axis value */
//printf(" Z=%u",I2c_Data[2]); /* Send Z-axis value
i2c_stop();
//delay_ms(1000);
}
} | regards |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Wed Mar 06, 2013 10:03 am |
|
|
Obvious glaring problem. How big is an 'int' in CCS?.
Best Wishes |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9240 Location: Greensville,Ontario
|
|
Posted: Wed Mar 06, 2013 10:41 am |
|
|
Also...
according to the datasheet, the device is not I2C FAST rated...so I'd be testing at the SLOW rate(100KHz).
And...
make it easier for us to read...get rid of any commented out code
hth
jay |
|
|
rajm
Joined: 06 Nov 2012 Posts: 29
|
|
Posted: Thu Mar 07, 2013 3:30 am |
|
|
this code does not giving any output in lcd. tell me how to use the registers in the datasheet to make the the sensor work.. also tell me how you are identifying about fast or slow in data sheet.. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Mar 07, 2013 4:34 am |
|
|
temtronic wrote: | according to the datasheet, the device is not I2C FAST rated...so I'd be testing at the SLOW rate(100KHz). | Where did you find this information? In the datasheets I find support for Fast mode:
LSM303DLHC datasheet, page 1 wrote: | LSM303DLHC includes an I2C serial bus interface that supports standard and fast mode 100 kHz and 400kHz. |
L3GD20 datasheet, page 22 wrote: | The I2C interface is compliant with fast mode (400 kHz) I2C standards as well as with normal mode. |
Code: | i2c_write(0x40); //01000001 --> 2g, no update between readings,12bits right justified | 0x40 != 01000001 This kind of discrepancy between comments and actual code always gives me a very bad feeling. It is a bug, but is the code wrong or only a textual error?
With a quick glance I spotted at least one other line with the same error type.
Quote: | this code does not giving any output in lcd. | Have you ever managed to get any output to the LCD? First make sure a simple "hello world" program works before expanding your project to include the more complex parts.
It seems to me like you have received enough tips to create a new version of your program. Incorporate all these changes and tips, then post your new version. |
|
|
rajm
Joined: 06 Nov 2012 Posts: 29
|
|
Posted: Fri Mar 08, 2013 2:18 am |
|
|
yes i have got output in lcd, but i dont know how to proceed with this sensor. any one kindly help me to use the register from the datasheet also tell me what data i should write in that register in order to read sensor values..
regards |
|
|
twidget
Joined: 21 Feb 2013 Posts: 32 Location: Orange County, California
|
|
Posted: Fri Mar 08, 2013 2:45 am |
|
|
Hello, have your read the examples? they have them for arduino, you might be able to use that code to help build your own?
Quote: | The Pololu MinIMU-9 v2 is a compact (0.8″ × 0.5″) board that combines ST’s L3GD20 3-axis gyroscope and LSM303DLHC 3-axis accelerometer and 3-axis magnetometer to form an inertial measurement unit (IMU); we therefore recommend careful reading of the L3GD20 datasheet (2MB pdf) and the LSM303DLHC datasheet (629k pdf) before using this product. |
http://www.pololu.com/catalog/product/1268
Maybe re-read the data sheet again. Also, I find it helpful to add debugging code into my programs. You can add a code in your Main; before the while loop, that displays "hello World" (I use a scrolling message and call it a boot screen).
And if your displaying info on an LCD, you dont want to just display the info, give it a label that prints on the LCD.
Code: | lcd_init();
lcd_gotoxy(1,1);
printf(lcd_putc,"Obj:%ld",comp); |
Doing these things will help you identify where the problem is in your code. If you see the label "Obj:" but no data, then check out your I2C code.
What value pull-up resistors are you using on your I2C BUS? Have you scoped the data line and verified data transfer? |
|
|
twidget
Joined: 21 Feb 2013 Posts: 32 Location: Orange County, California
|
|
Posted: Fri Mar 08, 2013 2:53 am |
|
|
Code: | lcd_gotoxy(2,2);
printf( LCD_PUTC, X_out " %g=%u ", X_out); //display //send results over RS232
printf(LCD_PUTC, Y_out " %g =%u", Y_out); //display
printf(LCD_PUTC, Z_out "%g=%u \n \r", Z_out); //display |
I think you need to rework your LCD coding .. Im thinking your not seeing anything, not even an = symbol? |
|
|
twidget
Joined: 21 Feb 2013 Posts: 32 Location: Orange County, California
|
|
Posted: Fri Mar 08, 2013 3:06 am |
|
|
I don't know what your trying to display on your LCD but I think you need a 4x20. You have 4 prints to the LCD but you never defined where the cursor starts, If I needed to display all the info at one time, I would go with a 4x20 and do something like this:
Code: |
lcd_init();
lcd_gotoxy(1,1);
printf(lcd_putc," acc:");
lcd_gotoxy(1,2);
printf(lcd_putc,"%g=%u ", X_out);
lcd_gotoxy(1,3);
printf(lcd_putc,"%g =%u", Y_out);
lcd_gotoxy(1,4);
printf(lcd_putc,"%g=%u", Z_out); |
Otherwise, display the value you need, then clear your LCD and display another value, clear the LCD and display another value.. etc. |
|
|
vrs
Joined: 30 Apr 2013 Posts: 18
|
|
Posted: Tue Apr 30, 2013 9:03 pm |
|
|
Code: |
#include "C:\Users\semerci\Desktop\dddd\lcdddd.h"
#include <flexLCD.C>
#include <imu.C>
#int_SSP
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3)
void SSP_isr(void)
{
}
//int16 x=0;
int16 acceX=0,acceY=0,acceZ=0,temp=0;
int16 gyroX=0,gyroY=0,gyroZ=0;
int16 magnX=0,magnY=0,magnZ=0;
void writeRegister(int8 reg,int8 value,int tur)
{
i2c_start(); lcd_gotoxy(6, 1);printf(lcd_putc, "1");
i2c_write(tur); lcd_gotoxy(7, 1);printf(lcd_putc, "1");
i2c_write(reg); lcd_gotoxy(8, 1);printf(lcd_putc, "1");
i2c_write(value); lcd_gotoxy(9, 1);printf(lcd_putc, "1");
i2c_stop(); lcd_gotoxy(10, 1);printf(lcd_putc, "1");
delay_ms(50); lcd_gotoxy(0, 1);printf(lcd_putc, "dışarıda");
}
void init_gyro()
{
writeRegister(L3G_CTRL_REG1,0x0F,gyro_ADD_W);//0b00001111);
//writeRegister(L3G_CTRL_REG2,0b00001000,gyro_ADD_W);
//writeRegister(L3G_CTRL_REG3,0b00001000,gyro_ADD_W);
writeRegister(L3G_CTRL_REG4,0x20,gyro_ADD_W);//0b10110000); //10110000
//writeRegister(L3G_CTRL_REG5,0b00000000,gyro_ADD_W);
}
void init_acce()
{
writeRegister(LSM303_CTRL_REG1_A,0x47,acce_ADD_W);//0b00001111);
//writeRegister(L3G_CTRL_REG2,0b00001000,acce_ADD_W);
//writeRegister(L3G_CTRL_REG3,0b00001000,acce_ADD_W);
writeRegister(LSM303_CTRL_REG4_A,0x28,acce_ADD_W);//0b10110000); //10110000
//writeRegister(L3G_CTRL_REG5,0b00000000,acce_ADD_W);
}
void init_magn()
{
writeRegister(LSM303_SR_REG_M, 0b00000000,magn_ADD_W);//0b00001111);
writeRegister(LSM303_IRA_REG_M,0b01001000,magn_ADD_W);
writeRegister(LSM303_IRB_REG_M,0b00110100,magn_ADD_W);//0b00001111);
writeRegister(LSM303_IRC_REG_M,0b00110011,magn_ADD_W);//0b00001111);
writeRegister(LSM303_CRA_REG_M,0b10011100,magn_ADD_W);//0b00001111);00000x00
writeRegister(LSM303_CRB_REG_M,0b11100000,magn_ADD_W);//0b00001111);
writeRegister(LSM303_MR_REG_M, 0b00000000,magn_ADD_W);//0b00001111);
//writeRegister(L3G_CTRL_REG2,0b00001000);
//writeRegister(L3G_CTRL_REG3,0b00001000);
//writeRegister(L3G_CTRL_REG4,0x20,magn_ADD_W);//0b10110000); //10110000
//writeRegister(L3G_CTRL_REG5,0b00000000);
}
void main()
{
int deneme;
deneme=123;
set_tris_c(0xFE);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_spi(SPI_SS_DISABLED);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
lcd_init();
printf(lcd_putc, "\f");
lcd_gotoxy(0, 1);
printf(lcd_putc, "deneme");
lcd_gotoxy(0, 2);
printf(lcd_putc, "deneme");
lcd_gotoxy(0, 3);
printf(lcd_putc,"\%d",deneme);
lcd_gotoxy(0, 4);
printf(lcd_putc, "6543210987654321");
delay_ms(1000);
init_gyro();
init_acce();
init_magn();
lcd_init();
printf(lcd_putc, "\f");
lcd_gotoxy(1,1);
printf(lcd_putc," imu geliyor"); // l3g4200d
delay_ms(500);
while(1)
{
i2c_start();i2c_write(gyro_ADD_W );i2c_write(L3G_OUT_x_H);
i2c_start();i2c_write(gyro_ADD_R);gyroX=i2c_read();gyroX=i2c_read(0);i2c_stop();
i2c_start();i2c_write(gyro_ADD_W );i2c_write(L3G_OUT_y_H);
i2c_start();i2c_write(gyro_ADD_R);gyroY=i2c_read();i2c_read(0);i2c_stop();
i2c_start();i2c_write(gyro_ADD_W );i2c_write(L3G_OUT_z_H);
i2c_start();i2c_write(gyro_ADD_R);gyroZ=i2c_read();i2c_read(0);i2c_stop();
i2c_start();i2c_write(acce_ADD_W );i2c_write(LSM303_OUT_X_H_A);i2c_start();i2c_write(acce_ADD_R);acceX=i2c_read();acceX=i2c_read(0);i2c_stop();
i2c_start();i2c_write(acce_ADD_W );i2c_write(LSM303_OUT_Y_H_A);i2c_start();i2c_write(acce_ADD_R);acceY=i2c_read();acceY=i2c_read(0);i2c_stop();
i2c_start();i2c_write(acce_ADD_W );i2c_write(LSM303_OUT_Z_H_A);i2c_start();i2c_write(acce_ADD_R);acceZ=i2c_read();acceZ=i2c_read(0);i2c_stop();
i2c_start();i2c_write(magn_ADD_W );i2c_write(LSM303_OUT_X_H_M);i2c_start();i2c_write(magn_ADD_R);magnX=i2c_read();magnX=i2c_read(0);i2c_stop();
i2c_start();i2c_write(magn_ADD_W );i2c_write(LSM303_OUT_Y_H_M);i2c_start();i2c_write(magn_ADD_R);magnY=i2c_read();magnY=i2c_read(0);i2c_stop();
i2c_start();i2c_write(magn_ADD_W );i2c_write(LSM303_OUT_Z_H_M);i2c_start();i2c_write(magn_ADD_R);magnZ=i2c_read();magnZ=i2c_read(0);i2c_stop();
i2c_start();i2c_write(magn_ADD_W );i2c_write(LSM303_TEMP_OUT_H_M);i2c_start();i2c_write(magn_ADD_R);temp=i2c_read();temp=i2c_read(0);i2c_stop();
i2c_start();i2c_write(magn_ADD_W );i2c_write(LSM303_TEMP_OUT_L_M);i2c_start();i2c_write(magn_ADD_R);i2c_read();temp=temp*255+i2c_read(0);i2c_stop();
printf(lcd_putc"\f");
lcd_gotoxy(0, 1); printf(lcd_putc," X");lcd_gotoxy(4, 1); printf(lcd_putc,"Y");lcd_gotoxy(6, 1); printf(lcd_putc,"Z temp= \%Ld",temp/0xf0);
lcd_gotoxy(0, 2); printf(lcd_putc,"a=\%Ld",acceX);lcd_gotoxy(7, 2); printf(lcd_putc," \%Ld",acceY);lcd_gotoxy(12, 2); printf(lcd_putc," \%Ld",acceZ);
lcd_gotoxy(0, 3); printf(lcd_putc,"g=\%Ld",gyroX);lcd_gotoxy(7, 3); printf(lcd_putc," \%Ld",gyroY);lcd_gotoxy(12, 3); printf(lcd_putc," \%Ld",gyroZ);
lcd_gotoxy(0, 4); printf(lcd_putc,"m=\%Ld",magnX);lcd_gotoxy(7, 4); printf(lcd_putc," \%Ld",magnY);lcd_gotoxy(12, 4); printf(lcd_putc," \%Ld",magnZ);
delay_ms(500);
//lcd_gotoxy(0, 4); printf(lcd_putc,"BEKLİYOR");
//delay_ms(500);
}
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Wed May 01, 2013 3:30 am |
|
|
Don't know how this relates to the earlier code, but some comments:
What on earth are you doing with an SSP_ISR present. Get rid of it. You only ever (really) use the ISR on a slave device.
Also Get rid of:
Code: |
setup_spi(SPI_SS_DISABLED);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
|
The SSP is the _same_ peripheral as the I2C (assuming you are using hardware I2C). You are fiddling with it's settings, from those generated by the compiler from the I2C lines. Not surprising it wouldn't then work....
Then if you were using an interrupt, the #INT_SSP line must be the line immediately above the interrupt handler declaration.
Then, assuming you are using the 4550 as listed in the earlier post. does C3 exist?.
Then is HS the correct oscillator fuse for 4MHz?. It _may_ work, but may not.
..... |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed May 01, 2013 5:17 am |
|
|
The code is posted by user 'vrs' without any comments. Is 'vrs' the same person as the original poster or is this posted as a 'working code' example to help the original poster?
As pointed out by Ttelmah there is a huge problem with the SSP so I doubt it was meant as a 'working code'.
Also there is: Quote: | i2c_start();i2c_write(gyro_ADD_R);gyroX=i2c_read();gyroX=i2c_read(0);i2c_stop();
...
i2c_start();i2c_write(gyro_ADD_R);gyroY=i2c_read();i2c_read(0);i2c_stop();
...
i2c_start();i2c_write(gyro_ADD_R);gyroZ=i2c_read();i2c_read(0);i2c_stop(); | The code shown in bold breaks a pattern seen in the other lines. I doubt that line is giving the result as intended. |
|
|
vrs
Joined: 30 Apr 2013 Posts: 18
|
|
Posted: Wed May 01, 2013 6:13 am |
|
|
I do not know English.. I am writing the message using Google Translate.
Using 16F877.
codes are added for illustration.
There are many error codes, reading the wrong value
To read the value from minimu9v2 but.
working.
To Rajm example.
(gyro, acce, temp, magn) will add the complete code for correcting errors.
normally I use pic basic. |
|
|
vrs
Joined: 30 Apr 2013 Posts: 18
|
|
Posted: Wed May 01, 2013 4:48 pm |
|
|
(16f877)
I can read values from minimu9.
Is it wrong to read the values.
Is it enough if I turn to 360 degrees for the division?
Code: | #include "C:\Users\semerci\Desktop\dddd\lcdddd.h"
#include <flexLCD.C>
#include <imu.C>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use i2c(MASTER, SDA=PIN_C4, SCL=PIN_C3,fast)
int8 konum=0, hesapH=0,hesapL=0;//tempH=0,tempL=0,gyroXH=0,gyroYH=0,gyroZH=0,gyroXL=0,gyroYL=0,gyroZL=0,acceXH=0,acceYH=0,acceZH=0,acceXL=0,acceYL=0,acceZL=0,magnXH=0,magnXL=0;//,magnYH=0,magnZH=0,magnYL=0,magnZL=0 ;
int16 hesap=0;//acceX=0,acceY=0,acceZ=0,temp=0,gyroX=0,gyroY=0,gyroZ=0,magnX=0,magnY=0,magnZ=0;
void writeRegister(int8 reg,int8 value,int tur)
{
i2c_start();// lcd_gotoxy(6, 1);printf(lcd_putc, "1");
i2c_write(tur);// lcd_gotoxy(7, 1);printf(lcd_putc, "1");
i2c_write(reg);// lcd_gotoxy(8, 1);printf(lcd_putc, "1");
i2c_write(value);// lcd_gotoxy(9, 1);printf(lcd_putc, "1");
i2c_stop();// lcd_gotoxy(10, 1);printf(lcd_putc, "1");
//delay_ms(10);// lcd_gotoxy(0, 1);printf(lcd_putc, "dışarıda");
}
void init_gyro()
{
writeRegister(L3G_CTRL_REG1,0b11101111,gyro_ADD_W);
writeRegister(L3G_CTRL_REG2,0b00000000,gyro_ADD_W);
//writeRegister(L3G_CTRL_REG3,0b00001000,gyro_ADD_W);
writeRegister(L3G_CTRL_REG4,0b0010000,gyro_ADD_W);
//writeRegister(L3G_CTRL_REG5,0b00000000,gyro_ADD_W);
}
void init_acce()
{
writeRegister(LSM303_CTRL_REG1_A,0x47,acce_ADD_W);
//writeRegister(L3G_CTRL_REG2,0b00001000,acce_ADD_W);
//writeRegister(L3G_CTRL_REG3,0b00001000,acce_ADD_W);
writeRegister(LSM303_CTRL_REG4_A,0b00101000,acce_ADD_W);
//writeRegister(L3G_CTRL_REG5,0b00000000,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)
{
int i;a=1;int b=0;char c;
for ( i=40;i<46;i+=2)
{
b=i;
if (adresR==magn_ADD_R)
{
konum=2;
b=i-37;
c="m";
}
i2c_start();i2c_write(adresW );i2c_write(b);i2c_start();i2c_write(adresR);hesapH=i2c_read(),i2c_read(0);i2c_stop();
i2c_start();i2c_write(adresW );i2c_write(b+1);i2c_start();i2c_write(adresR);hesapL=i2c_read(),i2c_read(0);i2c_stop();
hesap=make16(hesapH,hesapL);
if (adresR==acce_ADD_R)
{
konum=3;
hesap=hesap>>4;
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_gotoxy(a, konum); printf(lcd_putc,"\%Ld",hesap/10);
a=a+6;
}
}
void main()
{
set_tris_c(0xFE);
/*setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_spi(SPI_SS_DISABLED);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);*/
lcd_init();
printf(lcd_putc, "\f");
lcd_gotoxy(1, 1);
printf(lcd_putc, "minimu9 v2");
lcd_gotoxy(1, 3);
printf(lcd_putc, "KARAMAN/ERMENEK");
lcd_gotoxy(1, 2);
printf(lcd_putc, "pic 16f877");
delay_ms(1000);
init_gyro();
init_acce();
//init_magn();
lcd_init();
while(1)
{
hesapla_yaz(gyro_ADD_R,gyro_ADD_W);
hesapla_yaz(acce_ADD_R,acce_ADD_W);
init_magn();
hesapla_yaz(magn_ADD_R,magn_ADD_W);
delay_ms(100);
printf(lcd_putc"\f");
}
} |
|
|
|
|
|
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
|