Rev Author Line No. Line
1045 jacho 1 #include "C:\Users\Honza\Documents\pic\I2C_magnetometr\main.h"
2 #define EEPROM_SDA PIN_C4
3 #define EEPROM_SCL PIN_C3
4 #use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)
5 #use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8) //rcv TXD xmit RXD
6  
7  
8 void main()
9 {
10  
11 setup_adc_ports(NO_ANALOGS|VSS_VDD);
12 setup_adc(ADC_CLOCK_DIV_2);
13 setup_spi(SPI_SS_DISABLED);
14 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
15 setup_timer_1(T1_DISABLED);
16 setup_timer_2(T2_DISABLED,0,1);
17 setup_ccp1(CCP_OFF);
18 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
19  
20 printf("Simple Thermomether \r\n",);
21 unsigned int8 INTEP,INTEP1, NAP,NAP1, PROUD,PROUD1,KAPZ,KAPZ1,KAPC,KAPC1, STAV,STAV1;
22  
23  
24  
25 int16 data4;
26 int16 data5;
27 int16 data6;
28 int16 data7;
29 int16 data8;
30 int16 data9;
31  
32 while(TRUE)
33 {
34  
35  
36  
37 i2c_start();
38 I2C_Write(0xAA);
39 I2C_write(0x0c);
40  
41 i2c_start();
42 I2C_Write(0xAB);
43 INTEP=i2c_read(0);
44 i2c_stop();
45  
46 i2c_start();
47 I2C_Write(0xAA);
48 I2C_write(0x0d);
49 i2c_start();
50 I2C_Write(0xAB);
51 INTEP1=i2c_read(0);
52 i2c_stop();
53  
54 i2c_start();
55 I2C_Write(0xAA);
56 I2C_write(0x08);
57 i2c_stop();
58 i2c_start();
59 I2C_Write(0xAB);
60 NAP=i2c_read(0);
61 i2c_stop();
62  
63 i2c_start();
64 I2C_Write(0xAA);
65 I2C_write(0x09);
66 i2c_stop();
67 i2c_start();
68 I2C_Write(0xAB);
69 NAP1=i2c_read(0);
70 i2c_stop();
71  
72 i2c_start();
73 I2C_Write(0xAA);
74 I2C_write(0x0a);
75 i2c_stop();
76 i2c_start();
77 I2C_Write(0xAB);
78 PROUD=i2c_read(0);
79 i2c_stop();
80  
81 i2c_start();
82 I2C_Write(0xAA);
83 I2C_write(0x0b);
84 i2c_stop();
85 i2c_start();
86 I2C_Write(0xAB);
87 PROUD1=i2c_read(0);
88 i2c_stop();
89  
90  
91 i2c_start();
92 I2C_Write(0xAA);
93 I2C_write(0x04);
94 i2c_stop();
95 i2c_start();
96 I2C_Write(0xAB);
97 KAPZ=i2c_read(0);
98 i2c_stop();
99  
100 i2c_start();
101 I2C_Write(0xAA);
102 I2C_write(0x05);
103 i2c_stop();
104 i2c_start();
105 I2C_Write(0xAB);
106 KAPZ1=i2c_read(0);
107 i2c_stop();
108  
109  
110 i2c_start();
111 I2C_Write(0xAA);
112 I2C_write(0x06);
113 i2c_stop();
114 i2c_start();
115 I2C_Write(0xAB);
116 KAPC=i2c_read(0);
117 i2c_stop();
118  
119 i2c_start();
120 I2C_Write(0xAA);
121 I2C_write(0x07);
122 i2c_stop();
123 i2c_start();
124 I2C_Write(0xAB);
125 KAPC1=i2c_read(0);
126 i2c_stop();
127  
128 i2c_start();
129 I2C_Write(0xAA);
130 I2C_write(0x02);
131 i2c_stop();
132 i2c_start();
133 I2C_Write(0xAB);
134 STAV=i2c_read(0);
135 i2c_stop();
136  
137 i2c_start();
138 I2C_Write(0xAA);
139 I2C_write(0x03);
140 i2c_stop();
141 i2c_start();
142 I2C_Write(0xAB);
143 STAV1=i2c_read(0);
144 i2c_stop();
145  
146  
147 data4 = (((unsigned int16) INTEP1 << 8) + INTEP );
148 data4 = (data4/10)-273;
149 data5 = (((unsigned int16) NAP1 << 8) + NAP );
150 data6 = (((unsigned int16) PROUD1 << 8) + PROUD );
151 data7 = (((unsigned int16) KAPZ1 << 8) + KAPZ );
152 data8 = (((unsigned int16) KAPC1 << 8) + KAPC );
153 data9 = (((unsigned int16) STAV1 << 8) + STAV );
154  
155  
156  
157  
158  
159 printf("Teplota uvnitr io: %Ld C\r\n", data4);
160 printf("Napeti clanku: %Ld mV \r\n", data5);
161 printf("Proud: %Ld mA \r\n", data6);
162 printf("Kapacita zbytek: %Ld mAh\r\n", data7);
163 printf("Kapacita max: %Ld mAh\r\n", data8);
164 printf("Stav: %Ld (procenta)\r\n", data9);
165  
166  
167  
168  
169 }
170 }