| Line 1... |
Line -... |
| 1 |
//#include "C:\Users\Honza\Documents\pic\I2C_HUB\main.h" |
- |
|
| 2 |
|
- |
|
| 3 |
#include "main.h" |
1 |
#include "main.h" |
| 4 |
//I2CHUB |
2 |
//I2CHUB |
| 5 |
//ADRESA pro èteni 0xE1 |
3 |
//ADRESA pro èteni 0xE1 |
| 6 |
//pro zápis 0xE0 |
4 |
//pro zápis 0xE0 |
| 7 |
|
5 |
|
| Line 54... |
Line 52... |
| 54 |
i2c_start(); |
52 |
i2c_start(); |
| 55 |
I2C_Write(0xE0); |
53 |
I2C_Write(0xE0); |
| 56 |
|
54 |
|
| 57 |
I2C_write(d); |
55 |
I2C_write(d); |
| 58 |
i2c_stop(); |
56 |
i2c_stop(); |
| 59 |
|
- |
|
| 60 |
|
- |
|
| 61 |
|
- |
|
| 62 |
|
57 |
|
| 63 |
} |
58 |
} |
| 64 |
|
59 |
|
| 65 |
|
60 |
|
| 66 |
void main() |
61 |
void main() |
| Line 75... |
Line 70... |
| 75 |
setup_ccp1(CCP_OFF); |
70 |
setup_ccp1(CCP_OFF); |
| 76 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
71 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
| 77 |
|
72 |
|
| 78 |
printf("I2CHUB \r\n",); |
73 |
printf("I2CHUB \r\n",); |
| 79 |
printf("(c)MLAB 2013 JACHO \r\n",); |
74 |
printf("(c)MLAB 2013 JACHO \r\n",); |
| 80 |
unsigned int8 INTEP,INTEP1, NAP,NAP1, PROUD,PROUD1,KAPZ,KAPZ1,KAPC,KAPC1, STAV,STAV1; |
- |
|
| 81 |
|
- |
|
| 82 |
|
- |
|
| 83 |
|
- |
|
| 84 |
int16 data4; |
- |
|
| 85 |
int16 data5; |
- |
|
| 86 |
int16 data6; |
- |
|
| 87 |
int16 data7; |
- |
|
| 88 |
int16 data8; |
- |
|
| 89 |
int16 data9; |
- |
|
| 90 |
|
- |
|
| 91 |
byte XH; |
- |
|
| 92 |
|
- |
|
| 93 |
|
- |
|
| 94 |
|
- |
|
| 95 |
|
- |
|
| 96 |
|
75 |
|
| 97 |
while(TRUE) |
76 |
while(TRUE) |
| 98 |
{ |
77 |
{ |
| 99 |
|
- |
|
| 100 |
|
- |
|
| 101 |
|
- |
|
| 102 |
|
- |
|
| 103 |
//akcelerometr |
- |
|
| 104 |
int1 ack; |
- |
|
| 105 |
i2c_start(); // If the write command is acknowledged, |
- |
|
| 106 |
ack = i2c_write(0xE1);//hen the device is ready. |
78 |
setHUB(3); //pripoji prislusnou branu |
| 107 |
i2c_stop(); |
- |
|
| 108 |
ack=!ack; |
- |
|
| 109 |
|
- |
|
| 110 |
|
- |
|
| 111 |
|
- |
|
| 112 |
delay_ms(1000); |
79 |
delay_ms(1000); |
| 113 |
|
- |
|
| 114 |
|
- |
|
| 115 |
//printf("Stav: %d (procenta)\r\n", ack); |
- |
|
| 116 |
|
- |
|
| 117 |
printf("Stavx: %X(procenta)\r\n", XH); |
- |
|
| 118 |
|
- |
|
| 119 |
|
- |
|
| 120 |
|
- |
|
| 121 |
|
- |
|
| 122 |
setHUB(3); |
- |
|
| 123 |
|
- |
|
| 124 |
|
- |
|
| 125 |
|
- |
|
| 126 |
|
- |
|
| 127 |
|
- |
|
| 128 |
|
- |
|
| 129 |
i2c_start(); |
- |
|
| 130 |
I2C_Write(0xAA); |
- |
|
| 131 |
I2C_write(0x0c); |
- |
|
| 132 |
|
- |
|
| 133 |
i2c_start(); |
- |
|
| 134 |
I2C_Write(0xAB); |
- |
|
| 135 |
INTEP=i2c_read(0); |
- |
|
| 136 |
i2c_stop(); |
- |
|
| 137 |
|
- |
|
| 138 |
i2c_start(); |
- |
|
| 139 |
I2C_Write(0xAA); |
- |
|
| 140 |
I2C_write(0x0d); |
- |
|
| 141 |
i2c_start(); |
- |
|
| 142 |
I2C_Write(0xAB); |
- |
|
| 143 |
INTEP1=i2c_read(0); |
- |
|
| 144 |
i2c_stop(); |
- |
|
| 145 |
|
- |
|
| 146 |
i2c_start(); |
- |
|
| 147 |
I2C_Write(0xAA); |
- |
|
| 148 |
I2C_write(0x08); |
- |
|
| 149 |
i2c_stop(); |
- |
|
| 150 |
i2c_start(); |
- |
|
| 151 |
I2C_Write(0xAB); |
- |
|
| 152 |
NAP=i2c_read(0); |
- |
|
| 153 |
i2c_stop(); |
- |
|
| 154 |
|
- |
|
| 155 |
i2c_start(); |
- |
|
| 156 |
I2C_Write(0xAA); |
- |
|
| 157 |
I2C_write(0x09); |
- |
|
| 158 |
i2c_stop(); |
- |
|
| 159 |
i2c_start(); |
- |
|
| 160 |
I2C_Write(0xAB); |
- |
|
| 161 |
NAP1=i2c_read(0); |
- |
|
| 162 |
i2c_stop(); |
- |
|
| 163 |
|
- |
|
| 164 |
i2c_start(); |
- |
|
| 165 |
I2C_Write(0xAA); |
- |
|
| 166 |
I2C_write(0x0a); |
- |
|
| 167 |
i2c_stop(); |
- |
|
| 168 |
i2c_start(); |
- |
|
| 169 |
I2C_Write(0xAB); |
- |
|
| 170 |
PROUD=i2c_read(0); |
- |
|
| 171 |
i2c_stop(); |
- |
|
| 172 |
|
- |
|
| 173 |
i2c_start(); |
- |
|
| 174 |
I2C_Write(0xAA); |
- |
|
| 175 |
I2C_write(0x0b); |
- |
|
| 176 |
i2c_stop(); |
- |
|
| 177 |
i2c_start(); |
- |
|
| 178 |
I2C_Write(0xAB); |
- |
|
| 179 |
PROUD1=i2c_read(0); |
- |
|
| 180 |
i2c_stop(); |
- |
|
| 181 |
|
- |
|
| 182 |
|
- |
|
| 183 |
i2c_start(); |
- |
|
| 184 |
I2C_Write(0xAA); |
- |
|
| 185 |
I2C_write(0x04); |
- |
|
| 186 |
i2c_stop(); |
- |
|
| 187 |
i2c_start(); |
- |
|
| 188 |
I2C_Write(0xAB); |
- |
|
| 189 |
KAPZ=i2c_read(0); |
- |
|
| 190 |
i2c_stop(); |
- |
|
| 191 |
|
- |
|
| 192 |
i2c_start(); |
- |
|
| 193 |
I2C_Write(0xAA); |
- |
|
| 194 |
I2C_write(0x05); |
- |
|
| 195 |
i2c_stop(); |
- |
|
| 196 |
i2c_start(); |
- |
|
| 197 |
I2C_Write(0xAB); |
- |
|
| 198 |
KAPZ1=i2c_read(0); |
- |
|
| 199 |
i2c_stop(); |
- |
|
| 200 |
|
- |
|
| 201 |
|
- |
|
| 202 |
i2c_start(); |
- |
|
| 203 |
I2C_Write(0xAA); |
- |
|
| 204 |
I2C_write(0x06); |
- |
|
| 205 |
i2c_stop(); |
- |
|
| 206 |
i2c_start(); |
- |
|
| 207 |
I2C_Write(0xAB); |
- |
|
| 208 |
KAPC=i2c_read(0); |
- |
|
| 209 |
i2c_stop(); |
- |
|
| 210 |
|
- |
|
| 211 |
i2c_start(); |
- |
|
| 212 |
I2C_Write(0xAA); |
- |
|
| 213 |
I2C_write(0x07); |
- |
|
| 214 |
i2c_stop(); |
- |
|
| 215 |
i2c_start(); |
- |
|
| 216 |
I2C_Write(0xAB); |
- |
|
| 217 |
KAPC1=i2c_read(0); |
- |
|
| 218 |
i2c_stop(); |
- |
|
| 219 |
|
- |
|
| 220 |
i2c_start(); |
- |
|
| 221 |
I2C_Write(0xAA); |
- |
|
| 222 |
I2C_write(0x02); |
- |
|
| 223 |
i2c_stop(); |
- |
|
| 224 |
i2c_start(); |
- |
|
| 225 |
I2C_Write(0xAB); |
- |
|
| 226 |
STAV=i2c_read(0); |
- |
|
| 227 |
i2c_stop(); |
- |
|
| 228 |
|
- |
|
| 229 |
i2c_start(); |
- |
|
| 230 |
I2C_Write(0xAA); |
- |
|
| 231 |
I2C_write(0x03); |
- |
|
| 232 |
i2c_stop(); |
- |
|
| 233 |
i2c_start(); |
- |
|
| 234 |
I2C_Write(0xAB); |
- |
|
| 235 |
STAV1=i2c_read(0); |
- |
|
| 236 |
i2c_stop(); |
- |
|
| 237 |
|
- |
|
| 238 |
|
- |
|
| 239 |
data4 = (((unsigned int16) INTEP1 << 8) + INTEP ); |
- |
|
| 240 |
data4 = (data4/10)-273; |
- |
|
| 241 |
data5 = (((unsigned int16) NAP1 << 8) + NAP ); |
- |
|
| 242 |
data6 = (((unsigned int16) PROUD1 << 8) + PROUD ); |
- |
|
| 243 |
data7 = (((unsigned int16) KAPZ1 << 8) + KAPZ ); |
- |
|
| 244 |
data8 = (((unsigned int16) KAPC1 << 8) + KAPC ); |
- |
|
| 245 |
data9 = (((unsigned int16) STAV1 << 8) + STAV ); |
- |
|
| 246 |
|
- |
|
| 247 |
|
- |
|
| 248 |
|
- |
|
| 249 |
|
- |
|
| 250 |
|
- |
|
| 251 |
printf("Teplota uvnitr io: %Ld C\r\n", data4); |
- |
|
| 252 |
printf("Napeti clanku: %Ld mV \r\n", data5); |
- |
|
| 253 |
printf("Proud: %Ld mA \r\n", data6); |
- |
|
| 254 |
printf("Kapacita zbytek: %Ld mAh\r\n", data7); |
- |
|
| 255 |
printf("Kapacita max: %Ld mAh\r\n", data8); |
- |
|
| 256 |
printf("Stav: %Ld (procenta)\r\n", data9); |
- |
|
| 257 |
|
- |
|
| 258 |
|
- |
|
| 259 |
delay_ms (2000); |
- |
|
| 260 |
|
- |
|
| 261 |
|
- |
|
| 262 |
|
- |
|
| 263 |
} |
80 |
} |
| 264 |
} |
81 |
} |
| 265 |
|
82 |
|