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  
54  
55 i2c_start();
56 I2C_Write(0xE0);
57  
58 I2C_write(0x80);
59 i2c_stop();
60  
61 i2c_start();
62 I2C_Write(0xE1);
63 XH=i2c_read();
64 i2c_stop();
65  
66 delay_ms(1000);
67  
68  
69 //printf("Stav: %d (procenta)\r\n", ack);
70  
71 printf("Stavx: %X(procenta)\r\n", XH);
72  
73  
74  
75  
76  
77  
78 i2c_start();
79 I2C_Write(0xE0);
80  
81 I2C_write(0x70);
82 i2c_stop();
83  
84 i2c_start();
85 I2C_Write(0xE1);
86 XH=i2c_read();
87 i2c_stop();
88  
89  
90  
91  
92 printf("Stavx: %X(procenta)\r\n", XH);
93  
94 i2c_start();
95 I2C_Write(0xAA);
96 I2C_write(0x0c);
97  
98 i2c_start();
99 I2C_Write(0xAB);
100 INTEP=i2c_read(0);
101 i2c_stop();
102  
103 i2c_start();
104 I2C_Write(0xAA);
105 I2C_write(0x0d);
106 i2c_start();
107 I2C_Write(0xAB);
108 INTEP1=i2c_read(0);
109 i2c_stop();
110  
111 i2c_start();
112 I2C_Write(0xAA);
113 I2C_write(0x08);
114 i2c_stop();
115 i2c_start();
116 I2C_Write(0xAB);
117 NAP=i2c_read(0);
118 i2c_stop();
119  
120 i2c_start();
121 I2C_Write(0xAA);
122 I2C_write(0x09);
123 i2c_stop();
124 i2c_start();
125 I2C_Write(0xAB);
126 NAP1=i2c_read(0);
127 i2c_stop();
128  
129 i2c_start();
130 I2C_Write(0xAA);
131 I2C_write(0x0a);
132 i2c_stop();
133 i2c_start();
134 I2C_Write(0xAB);
135 PROUD=i2c_read(0);
136 i2c_stop();
137  
138 i2c_start();
139 I2C_Write(0xAA);
140 I2C_write(0x0b);
141 i2c_stop();
142 i2c_start();
143 I2C_Write(0xAB);
144 PROUD1=i2c_read(0);
145 i2c_stop();
146  
147  
148 i2c_start();
149 I2C_Write(0xAA);
150 I2C_write(0x04);
151 i2c_stop();
152 i2c_start();
153 I2C_Write(0xAB);
154 KAPZ=i2c_read(0);
155 i2c_stop();
156  
157 i2c_start();
158 I2C_Write(0xAA);
159 I2C_write(0x05);
160 i2c_stop();
161 i2c_start();
162 I2C_Write(0xAB);
163 KAPZ1=i2c_read(0);
164 i2c_stop();
165  
166  
167 i2c_start();
168 I2C_Write(0xAA);
169 I2C_write(0x06);
170 i2c_stop();
171 i2c_start();
172 I2C_Write(0xAB);
173 KAPC=i2c_read(0);
174 i2c_stop();
175  
176 i2c_start();
177 I2C_Write(0xAA);
178 I2C_write(0x07);
179 i2c_stop();
180 i2c_start();
181 I2C_Write(0xAB);
182 KAPC1=i2c_read(0);
183 i2c_stop();
184  
185 i2c_start();
186 I2C_Write(0xAA);
187 I2C_write(0x02);
188 i2c_stop();
189 i2c_start();
190 I2C_Write(0xAB);
191 STAV=i2c_read(0);
192 i2c_stop();
193  
194 i2c_start();
195 I2C_Write(0xAA);
196 I2C_write(0x03);
197 i2c_stop();
198 i2c_start();
199 I2C_Write(0xAB);
200 STAV1=i2c_read(0);
201 i2c_stop();
202  
203  
204 data4 = (((unsigned int16) INTEP1 << 8) + INTEP );
205 data4 = (data4/10)-273;
206 data5 = (((unsigned int16) NAP1 << 8) + NAP );
207 data6 = (((unsigned int16) PROUD1 << 8) + PROUD );
208 data7 = (((unsigned int16) KAPZ1 << 8) + KAPZ );
209 data8 = (((unsigned int16) KAPC1 << 8) + KAPC );
210 data9 = (((unsigned int16) STAV1 << 8) + STAV );
211  
212  
213  
214  
215  
216 printf("Teplota uvnitr io: %Ld C\r\n", data4);
217 printf("Napeti clanku: %Ld mV \r\n", data5);
218 printf("Proud: %Ld mA \r\n", data6);
219 printf("Kapacita zbytek: %Ld mAh\r\n", data7);
220 printf("Kapacita max: %Ld mAh\r\n", data8);
221 printf("Stav: %Ld (procenta)\r\n", data9);
222  
223  
224 delay_ms (2000);
225  
226  
227  
228 }
229 }
230