|
本帖最後由 boy978880 於 2010-12-13 14:42 編輯
試了很多種方法 包括把RB的VC++使用2008與2005版本
winio那些檔案也都有放在執行檔同一個資料夾,官網上的範例程式也不能執行
找步道有什麼問題,當然G145的電源,街角都已經有確認過沒問題也有通電!
請問各位還有什麼方法幫我解答@@
不然一直被BOSS問說買了那顆都沒看過再使用!
我新增了照片 麻煩各位有使用過的幫我看一下有錯誤嗎?!
程式碼:
- #include <stdio.h>
- #include <conio.h>
- #include <dos.h>
- #include <roboard.h>
- int main(void){
- unsigned char d1,d2,d3,d4,d5,d6;
- unsigned long i2c_clock = 400000L;
- unsigned int i2c_address = 0x3C;
- if (i2c_Initialize(I2CIRQ_DISABLE) == false)
- {
- printf("FALSE!! %s\n", roboio_GetErrMsg());
- return -1;
- }
- i2c0_SetSpeed(I2CMODE_FAST, i2c_clock);
- i2c0master_StartN(i2c_address >> 1,I2C_WRITE,2);//write 2 byte
- i2c0master_WriteN(0x02); //mode register
- i2c0master_WriteN(0x00); //continue-measureture mode
- delay(100);
- do
- {
- i2c0master_StartN(i2c_address >> 1, I2C_WRITE, 1);
- i2c0master_SetRestartN(I2C_READ, 6);
- i2c0master_WriteN(0x03); //Read from data register (Address : 0x03)
- d1 = i2c0master_ReadN();//X MSB
- d2 = i2c0master_ReadN();//X LSB
- d3 = i2c0master_ReadN();//Y MSB
- d4 = i2c0master_ReadN();//Y LSB
- d5 = i2c0master_ReadN();//Z MSB
- d6 = i2c0master_ReadN();//Z LSB
- //Data : 16bits
- printf("X axis :%d\n", ((d1 & 0xF0) > 0) ? ~(0xFFFF ^ (d1*256+d2)): d1*256+d2);
- printf("Y axis :%d\n", ((d3 & 0xF0) > 0) ? ~(0xFFFF ^ (d3*256+d4)): d3*256+d4);
- printf("Z axis :%d\n", ((d5 & 0xF0) > 0) ? ~(0xFFFF ^ (d5*256+d6)): d5*256+d6);
- delay(100);
- }while(getch() != 27);
- i2c_Close();
- return 0;
- }
複製代碼 |
|