Line 1... |
Line 1... |
1 |
#include "C:\Users\Honza\Documents\pic\I2C_magnetometr\main.h" |
1 |
//#include "C:\Users\Honza\Documents\pic\I2C_magnetometr\main.h" |
- |
|
2 |
#include "main.h" |
2 |
#define EEPROM_SDA PIN_B0 |
3 |
#define EEPROM_SDA PIN_C4 |
3 |
#define EEPROM_SCL PIN_B1 |
4 |
#define EEPROM_SCL PIN_C3 |
4 |
#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL) |
5 |
#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL) |
5 |
#use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B2,bits=8) //rcv TXD xmit RXD |
6 |
#use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8) //rcv TXD xmit RXD |
- |
|
7 |
#include "BQ34Z100.h" |
6 |
|
8 |
|
7 |
|
9 |
|
8 |
void main() |
10 |
void main() |
9 |
{ |
11 |
{ |
10 |
|
12 |
|
Line 15... |
Line 17... |
15 |
setup_timer_1(T1_DISABLED); |
17 |
setup_timer_1(T1_DISABLED); |
16 |
setup_timer_2(T2_DISABLED,0,1); |
18 |
setup_timer_2(T2_DISABLED,0,1); |
17 |
setup_ccp1(CCP_OFF); |
19 |
setup_ccp1(CCP_OFF); |
18 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
20 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
19 |
|
21 |
|
20 |
printf("Simple Thermomether \r\n",); |
22 |
printf("Vycitani zakladnich dat z modulu LION1CELL01B \r\n",); |
21 |
unsigned int8 XH,XL,YH,YL,ZH,ZL,INTEP,INTEP1, NAP,NAP1, PROUD,PROUD1,KAPZ,KAPZ1,KAPC,KAPC1, STAV,STAV1; |
23 |
printf("(c) MLAB 2013 JACHO \r\n",); |
22 |
unsigned int8 XW,YW,ZW,AW; |
24 |
int16 data; |
23 |
|
25 |
|
24 |
int16 data1; |
- |
|
25 |
int16 data2; |
- |
|
26 |
int16 data3; |
- |
|
27 |
int16 data4; |
- |
|
28 |
int16 data5; |
- |
|
29 |
int16 data6; |
- |
|
30 |
int16 data7; |
- |
|
31 |
int16 data8; |
- |
|
32 |
int16 data9; |
- |
|
33 |
|
26 |
|
34 |
while(TRUE) |
27 |
while(TRUE) |
35 |
{ |
28 |
{ |
36 |
XL=0; |
- |
|
37 |
XH= 0; |
- |
|
38 |
YL= 0; |
- |
|
39 |
YH= 0; |
- |
|
40 |
ZL= 0; |
- |
|
41 |
ZH= 0; |
- |
|
42 |
|
- |
|
43 |
i2c_start(); |
- |
|
44 |
I2C_Write(0x3C); |
- |
|
45 |
I2C_write(0x03); |
- |
|
46 |
i2c_stop(); |
- |
|
47 |
i2c_start(); |
- |
|
48 |
I2C_Write(0x3D); |
- |
|
49 |
XH=i2c_read(0); |
- |
|
50 |
i2c_stop(); |
- |
|
51 |
i2c_start(); |
- |
|
52 |
I2C_Write(0x3C); |
- |
|
53 |
I2C_write(0x04); |
- |
|
54 |
i2c_stop(); |
- |
|
55 |
i2c_start(); |
- |
|
56 |
I2C_Write(0x3D); |
- |
|
57 |
XL=i2c_read(0); |
- |
|
58 |
i2c_stop(); |
- |
|
59 |
i2c_start(); |
- |
|
60 |
I2C_Write(0x3C); |
- |
|
61 |
I2C_write(0x05); |
- |
|
62 |
i2c_stop(); |
- |
|
63 |
i2c_start(); |
- |
|
64 |
I2C_Write(0x3D); |
- |
|
65 |
ZH=i2c_read(0); |
- |
|
66 |
i2c_stop(); |
- |
|
67 |
i2c_start(); |
- |
|
68 |
I2C_Write(0x3C); |
- |
|
69 |
I2C_write(0x06); |
- |
|
70 |
i2c_stop(); |
- |
|
71 |
i2c_start(); |
- |
|
72 |
I2C_Write(0x3D); |
- |
|
73 |
ZL=i2c_read(0); |
- |
|
74 |
i2c_stop(); |
- |
|
75 |
i2c_start(); |
- |
|
76 |
I2C_Write(0x3C); |
- |
|
77 |
I2C_write(0x07); |
- |
|
78 |
i2c_stop(); |
- |
|
79 |
i2c_start(); |
- |
|
80 |
I2C_Write(0x3D); |
- |
|
81 |
YH=i2c_read(0); |
- |
|
82 |
i2c_stop(); |
- |
|
83 |
i2c_start(); |
- |
|
84 |
I2C_Write(0x3C); |
- |
|
85 |
I2C_write(0x08); |
- |
|
86 |
i2c_stop(); |
- |
|
87 |
i2c_start(); |
29 |
data=batintT(); |
88 |
I2C_Write(0x3D); |
- |
|
89 |
YL=i2c_read(0); |
- |
|
90 |
i2c_stop(); |
- |
|
91 |
|
- |
|
92 |
Delay_ms(3700); |
- |
|
93 |
|
- |
|
94 |
data1 = (((unsigned int16) XH << 8) + XL ); |
- |
|
95 |
data2 = (((unsigned int16) YH << 8) + YL ); |
- |
|
96 |
data3 = (((unsigned int16) ZH << 8) + ZL ); |
30 |
printf("Teplota baterie: %Ld (°C)\r\n", data); |
97 |
|
- |
|
98 |
i2c_start(); |
- |
|
99 |
I2C_Write(0xAA); |
- |
|
100 |
I2C_write(0x0c); |
- |
|
101 |
|
- |
|
102 |
i2c_start(); |
- |
|
103 |
I2C_Write(0xAB); |
- |
|
104 |
INTEP=i2c_read(0); |
- |
|
105 |
i2c_stop(); |
- |
|
106 |
|
- |
|
107 |
i2c_start(); |
- |
|
108 |
I2C_Write(0xAA); |
- |
|
109 |
I2C_write(0x0d); |
- |
|
110 |
i2c_start(); |
- |
|
111 |
I2C_Write(0xAB); |
- |
|
112 |
INTEP1=i2c_read(0); |
- |
|
113 |
i2c_stop(); |
- |
|
114 |
|
- |
|
115 |
i2c_start(); |
- |
|
116 |
I2C_Write(0xAA); |
- |
|
117 |
I2C_write(0x08); |
- |
|
118 |
i2c_stop(); |
- |
|
119 |
i2c_start(); |
- |
|
120 |
I2C_Write(0xAB); |
- |
|
121 |
NAP=i2c_read(0); |
- |
|
122 |
i2c_stop(); |
- |
|
123 |
|
- |
|
124 |
i2c_start(); |
- |
|
125 |
I2C_Write(0xAA); |
- |
|
126 |
I2C_write(0x09); |
- |
|
127 |
i2c_stop(); |
- |
|
128 |
i2c_start(); |
- |
|
129 |
I2C_Write(0xAB); |
- |
|
130 |
NAP1=i2c_read(0); |
- |
|
131 |
i2c_stop(); |
- |
|
132 |
|
- |
|
133 |
i2c_start(); |
31 |
data=batNAP(); |
134 |
I2C_Write(0xAA); |
- |
|
135 |
I2C_write(0x0a); |
- |
|
136 |
i2c_stop(); |
- |
|
137 |
i2c_start(); |
- |
|
138 |
I2C_Write(0xAB); |
- |
|
139 |
PROUD=i2c_read(0); |
- |
|
140 |
i2c_stop(); |
- |
|
141 |
|
- |
|
142 |
i2c_start(); |
- |
|
143 |
I2C_Write(0xAA); |
- |
|
144 |
I2C_write(0x0b); |
- |
|
145 |
i2c_stop(); |
- |
|
146 |
i2c_start(); |
- |
|
147 |
I2C_Write(0xAB); |
- |
|
148 |
PROUD1=i2c_read(0); |
32 |
printf("Napeti clanku: %Ld (mV)\r\n", data); |
149 |
i2c_stop(); |
- |
|
150 |
|
- |
|
151 |
|
- |
|
152 |
i2c_start(); |
- |
|
153 |
I2C_Write(0xAA); |
- |
|
154 |
I2C_write(0x04); |
- |
|
155 |
i2c_stop(); |
- |
|
156 |
i2c_start(); |
- |
|
157 |
I2C_Write(0xAB); |
- |
|
158 |
KAPZ=i2c_read(0); |
33 |
data=batPROUD(); |
159 |
i2c_stop(); |
- |
|
160 |
|
- |
|
161 |
i2c_start(); |
- |
|
162 |
I2C_Write(0xAA); |
- |
|
163 |
I2C_write(0x05); |
- |
|
164 |
i2c_stop(); |
- |
|
165 |
i2c_start(); |
- |
|
166 |
I2C_Write(0xAB); |
- |
|
167 |
KAPZ1=i2c_read(0); |
- |
|
168 |
i2c_stop(); |
- |
|
169 |
|
- |
|
170 |
|
- |
|
171 |
i2c_start(); |
- |
|
172 |
I2C_Write(0xAA); |
- |
|
173 |
I2C_write(0x06); |
- |
|
174 |
i2c_stop(); |
- |
|
175 |
i2c_start(); |
- |
|
176 |
I2C_Write(0xAB); |
- |
|
177 |
KAPC=i2c_read(0); |
- |
|
178 |
i2c_stop(); |
- |
|
179 |
|
- |
|
180 |
i2c_start(); |
- |
|
181 |
I2C_Write(0xAA); |
- |
|
182 |
I2C_write(0x07); |
- |
|
183 |
i2c_stop(); |
- |
|
184 |
i2c_start(); |
- |
|
185 |
I2C_Write(0xAB); |
- |
|
186 |
KAPC1=i2c_read(0); |
- |
|
187 |
i2c_stop(); |
- |
|
188 |
|
- |
|
189 |
i2c_start(); |
- |
|
190 |
I2C_Write(0xAA); |
- |
|
191 |
I2C_write(0x02); |
- |
|
192 |
i2c_stop(); |
- |
|
193 |
i2c_start(); |
- |
|
194 |
I2C_Write(0xAB); |
- |
|
195 |
STAV=i2c_read(0); |
- |
|
196 |
i2c_stop(); |
- |
|
197 |
|
- |
|
198 |
i2c_start(); |
- |
|
199 |
I2C_Write(0xAA); |
- |
|
200 |
I2C_write(0x03); |
- |
|
201 |
i2c_stop(); |
- |
|
202 |
i2c_start(); |
- |
|
203 |
I2C_Write(0xAB); |
- |
|
204 |
STAV1=i2c_read(0); |
- |
|
205 |
i2c_stop(); |
- |
|
206 |
|
- |
|
207 |
|
- |
|
208 |
data4 = (((unsigned int16) INTEP1 << 8) + INTEP ); |
- |
|
209 |
data4 = (data4/10)-273; |
- |
|
210 |
data5 = (((unsigned int16) NAP1 << 8) + NAP ); |
- |
|
211 |
data6 = (((unsigned int16) PROUD1 << 8) + PROUD ); |
- |
|
212 |
data7 = (((unsigned int16) KAPZ1 << 8) + KAPZ ); |
- |
|
213 |
data8 = (((unsigned int16) KAPC1 << 8) + KAPC ); |
- |
|
214 |
data9 = (((unsigned int16) STAV1 << 8) + STAV ); |
- |
|
215 |
|
- |
|
216 |
|
- |
|
217 |
|
- |
|
218 |
|
- |
|
219 |
|
- |
|
220 |
printf("X %Ld \r\n", data1); |
- |
|
221 |
printf("Y %Ld \r\n", data2); |
34 |
printf("Proud clankem: %Ld (mA)\r\n", data); |
222 |
printf("Z %Ld \r\n", data3); |
35 |
data=batKAPAKT(); |
223 |
printf("Teplota uvnitr io: %Ld C\r\n", data4); |
36 |
printf("Zbyvajici kapacita: %Ld (mAh)\r\n", data); |
224 |
printf("Napeti clanku: %Ld mV \r\n", data5); |
37 |
data=batKAPMAX(); |
225 |
printf("Proud: %Ld mA \r\n", data6); |
38 |
printf("Max. kapacita: %Ld (mAh)\r\n", data); |
226 |
printf("Kapacita zbytek: %Ld mAh\r\n", data7); |
39 |
data=batSTAV(); |
227 |
printf("Kapacita max: %Ld mAh\r\n", data8); |
40 |
printf("Stav baterie: %Ld (procenta)\r\n", data); |
228 |
printf("Stav: %Ld (procenta)\r\n", data9); |
41 |
delay_ms (2000); |
229 |
|
- |
|
230 |
} |
42 |
} |
231 |
} |
43 |
} |