Professional Documents
Culture Documents
*
1
* MA 02110-1301, USA.
*
*
*/
10
// Lcd pinout settings
sbit LCD_RS at RD1_bit;
11
12
13
// Pin direction
sbit LCD_RS_Direction at TRISD1_bit;
14
15
17
char salida1[7];
I2C1_Wr(0b11010010);
//send START
//Write device address to bus for Write mode ACCEL_ADDR from
Arduino ex
20
I2C1_Wr(reg);
//Write desired address bits x axis MSB with 7th bit set to enable
multi-byte read
I2C1_Start();
21
I2C1_Wr(0b11010011);
I2C example
22
ACC_data[0]=I2C1_Rd(0);
//Read in data from register master ack after each byte read except
24
ACC_data[5]=I2C1_Rd(0); //Read in data from register, the last byte read should not acknowledge
Ax_raw = (int)(((ACC_Data[1] << 8) + ACC_Data[0]) >> 4);
25
I2C1_Stop();
26
//send STOP
return ACC_data[0];
27
28 void main(){
char salida[7];
29 //
30
31
TRISD = 0x00;
//Puerto D salida
PORTD = 0x00;
PORTD.RD2 = 0;
ADCON1 = 0x0F;
32
PORTB = 0;
TRISB = 0;
33
Lcd_Init();
Delay_ms(500);
34
35
36
I2C1_Init(100000);
I2C1_Start();
I2C1_Wr(MPU6050_W);
I2C1_Wr(0x6B);
I2C1_Wr(0x02);
I2C1_Stop();
37
38
I2C1_Start();
I2C1_Wr(MPU6050_W);
I2C1_Wr(0x6C);
I2C1_Wr(0x00);
I2C1_Stop();
39
40
I2C1_Start();
I2C1_Wr(MPU6050_W);
I2C1_Wr(0x1C);
I2C1_Wr(0x00);
41
I2C1_Stop();
//////////////////start configuration///////////////////
42
I2C1_Start();
43
I2C1_Wr(MPU6050_W);
I2C1_Wr(MPU6050_RA_WHO_AM_I);
I2C1_Start();
44
I2C1_Wr(MPU6050_R);
high = I2C1_Rd(0);
I2C1_Stop();
45
ShortToHex(high, salida);
Lcd_Out(1, 1, salida);
46
while(1){
high = I2C_read_Accelerometer(0x3B);
47
low = I2C_read_Accelerometer(0x3C);
IntToStr((signed int)(high <<8) | low, salida1);
48
Lcd_Out(1, 7, salida1);
high = I2C_read_Accelerometer(0x3D);
low = I2C_read_Accelerometer(0x3E);
49
50
low = I2C_read_Accelerometer(0x40);
IntToStr((signed int)(high <<8) | low, salida1);
51
Lcd_Out(2, 7, salida1);
Delay_ms(400);}}
52
}
}
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133