Rev Author Line No. Line
1045 jacho 1 #include "C:\Users\Honza\Documents\pic\I2C_HUB\main.h"
2  
3  
4 //For AKCE
5 //ADRESA pro èteni 0xE1
6 //pro zápis 0xE0
7  
8  
9 #define EEPROM_SDA PIN_C4
10 #define EEPROM_SCL PIN_C3
11 #use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)
12 #use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8) //rcv TXD xmit RXD
13  
14  
15  
16 void main()
17 {
18  
19 setup_adc_ports(NO_ANALOGS|VSS_VDD);
20 setup_adc(ADC_CLOCK_DIV_2);
21 setup_spi(SPI_SS_DISABLED);
22 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
23 setup_timer_1(T1_DISABLED);
24 setup_timer_2(T2_DISABLED,0,1);
25 setup_ccp1(CCP_OFF);
26 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
27  
28 printf("Simple Thermomether \r\n",);
29  
30 unsigned int8 INTEP,INTEP1, NAP,NAP1, PROUD,PROUD1,KAPZ,KAPZ1,KAPC,KAPC1, STAV,STAV1;
31  
32  
33  
34 int16 data4;
35 int16 data5;
36 int16 data6;
37 int16 data7;
38 int16 data8;
39 int16 data9;
40  
41 byte XH;
42  
43  
44  
45  
46  
47 while(TRUE)
48 {
49  
50  
51  
52  
53 //akcelerometr
54 int1 ack;
55 i2c_start(); // If the write command is acknowledged,
56 ack = i2c_write(0xE1);//hen the device is ready.
57 i2c_stop();
58 ack=!ack;
59  
60  
61 i2c_start();
62 I2C_Write(0xE0);
63  
64 I2C_write(0x80);
65 i2c_stop();
66  
67 i2c_start();
68 I2C_Write(0xE1);
69 XH=i2c_read();
70 i2c_stop();
71  
72 delay_ms(1000);
73  
74  
75 //printf("Stav: %d (procenta)\r\n", ack);
76  
77 printf("Stavx: %X(procenta)\r\n", XH);
78  
79  
80  
81  
82  
83  
84 i2c_start();
85 I2C_Write(0xE0);
86  
87 I2C_write(0x01);
88 i2c_stop();
89  
90  
91  
92  
93  
94  
95  
96 i2c_start();
97 I2C_Write(0xAA);
98 I2C_write(0x0c);
99  
100 i2c_start();
101 I2C_Write(0xAB);
102 INTEP=i2c_read(0);
103 i2c_stop();
104  
105 i2c_start();
106 I2C_Write(0xAA);
107 I2C_write(0x0d);
108 i2c_start();
109 I2C_Write(0xAB);
110 INTEP1=i2c_read(0);
111 i2c_stop();
112  
113 i2c_start();
114 I2C_Write(0xAA);
115 I2C_write(0x08);
116 i2c_stop();
117 i2c_start();
118 I2C_Write(0xAB);
119 NAP=i2c_read(0);
120 i2c_stop();
121  
122 i2c_start();
123 I2C_Write(0xAA);
124 I2C_write(0x09);
125 i2c_stop();
126 i2c_start();
127 I2C_Write(0xAB);
128 NAP1=i2c_read(0);
129 i2c_stop();
130  
131 i2c_start();
132 I2C_Write(0xAA);
133 I2C_write(0x0a);
134 i2c_stop();
135 i2c_start();
136 I2C_Write(0xAB);
137 PROUD=i2c_read(0);
138 i2c_stop();
139  
140 i2c_start();
141 I2C_Write(0xAA);
142 I2C_write(0x0b);
143 i2c_stop();
144 i2c_start();
145 I2C_Write(0xAB);
146 PROUD1=i2c_read(0);
147 i2c_stop();
148  
149  
150 i2c_start();
151 I2C_Write(0xAA);
152 I2C_write(0x04);
153 i2c_stop();
154 i2c_start();
155 I2C_Write(0xAB);
156 KAPZ=i2c_read(0);
157 i2c_stop();
158  
159 i2c_start();
160 I2C_Write(0xAA);
161 I2C_write(0x05);
162 i2c_stop();
163 i2c_start();
164 I2C_Write(0xAB);
165 KAPZ1=i2c_read(0);
166 i2c_stop();
167  
168  
169 i2c_start();
170 I2C_Write(0xAA);
171 I2C_write(0x06);
172 i2c_stop();
173 i2c_start();
174 I2C_Write(0xAB);
175 KAPC=i2c_read(0);
176 i2c_stop();
177  
178 i2c_start();
179 I2C_Write(0xAA);
180 I2C_write(0x07);
181 i2c_stop();
182 i2c_start();
183 I2C_Write(0xAB);
184 KAPC1=i2c_read(0);
185 i2c_stop();
186  
187 i2c_start();
188 I2C_Write(0xAA);
189 I2C_write(0x02);
190 i2c_stop();
191 i2c_start();
192 I2C_Write(0xAB);
193 STAV=i2c_read(0);
194 i2c_stop();
195  
196 i2c_start();
197 I2C_Write(0xAA);
198 I2C_write(0x03);
199 i2c_stop();
200 i2c_start();
201 I2C_Write(0xAB);
202 STAV1=i2c_read(0);
203 i2c_stop();
204  
205  
206 data4 = (((unsigned int16) INTEP1 << 8) + INTEP );
207 data4 = (data4/10)-273;
208 data5 = (((unsigned int16) NAP1 << 8) + NAP );
209 data6 = (((unsigned int16) PROUD1 << 8) + PROUD );
210 data7 = (((unsigned int16) KAPZ1 << 8) + KAPZ );
211 data8 = (((unsigned int16) KAPC1 << 8) + KAPC );
212 data9 = (((unsigned int16) STAV1 << 8) + STAV );
213  
214  
215  
216  
217  
218 printf("Teplota uvnitr io: %Ld C\r\n", data4);
219 printf("Napeti clanku: %Ld mV \r\n", data5);
220 printf("Proud: %Ld mA \r\n", data6);
221 printf("Kapacita zbytek: %Ld mAh\r\n", data7);
222 printf("Kapacita max: %Ld mAh\r\n", data8);
223 printf("Stav: %Ld (procenta)\r\n", data9);
224  
225  
226 delay_ms (2000);
227  
228  
229  
230 }
231 }
232