2953 |
jacho |
1 |
#include "C:\Users\Honza\Documents\pic\I2C_bat_pam\Min_V_cl\main.h" |
|
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
#define EEPROM_SDA PIN_C4 |
|
|
6 |
#define EEPROM_SCL PIN_C3 |
|
|
7 |
#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL) |
|
|
8 |
#use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8) //rcv TXD xmit RXD |
|
|
9 |
|
|
|
10 |
|
|
|
11 |
void main() |
|
|
12 |
{ |
|
|
13 |
|
|
|
14 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
|
|
15 |
setup_adc(ADC_CLOCK_DIV_2); |
|
|
16 |
setup_spi(SPI_SS_DISABLED); |
|
|
17 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
|
|
18 |
setup_timer_1(T1_DISABLED); |
|
|
19 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
20 |
setup_ccp1(CCP_OFF); |
|
|
21 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
|
|
22 |
|
|
|
23 |
printf("Simple Thermomether \r\n",); |
|
|
24 |
unsigned int8 STAV1,STAV2; |
|
|
25 |
|
|
|
26 |
unsigned int16 SOUCET, SOUCET1; |
|
|
27 |
unsigned int8 LSB=0,ZK,k=0,VH,VL; |
|
|
28 |
//unsigned int8 |
|
|
29 |
|
|
|
30 |
while(TRUE) |
|
|
31 |
{ |
|
|
32 |
|
|
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
|
36 |
i2c_start(); //blockdatacontrol |
|
|
37 |
I2C_Write(0xAA); |
|
|
38 |
I2C_write(0x61); |
|
|
39 |
i2c_start(); |
|
|
40 |
I2C_Write(0xAA); |
|
|
41 |
i2c_write(0x00); |
|
|
42 |
i2c_stop(); |
|
|
43 |
delay_ms (1); |
|
|
44 |
|
|
|
45 |
|
|
|
46 |
i2c_start();//dataflashclass |
|
|
47 |
I2C_Write(0xAA); |
|
|
48 |
I2C_write(0x3e); |
|
|
49 |
|
|
|
50 |
i2c_start(); |
|
|
51 |
I2C_Write(0xAA); |
|
|
52 |
i2c_write(0x50); |
|
|
53 |
i2c_stop(); |
|
|
54 |
delay_ms (1); |
|
|
55 |
|
|
|
56 |
|
|
|
57 |
i2c_start();//dataflashblock |
|
|
58 |
I2C_Write(0xAA); |
|
|
59 |
I2C_write(0x3f); |
|
|
60 |
|
|
|
61 |
i2c_start(); |
|
|
62 |
I2C_Write(0xAA); |
|
|
63 |
I2C_write(0x02); |
|
|
64 |
i2c_stop(); |
|
|
65 |
|
|
|
66 |
delay_ms (1); |
|
|
67 |
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
i2c_start();//blockdata horni bit |
|
|
72 |
I2C_Write(0xAA); |
|
|
73 |
I2C_write(0x43); |
|
|
74 |
|
|
|
75 |
i2c_start(); |
|
|
76 |
I2C_Write(0xAB); |
|
|
77 |
VH=I2C_read(0); |
|
|
78 |
|
|
|
79 |
i2c_stop(); |
|
|
80 |
|
|
|
81 |
i2c_start();//blockdata |
|
|
82 |
I2C_Write(0xAA); |
|
|
83 |
I2C_write(0x44); |
|
|
84 |
|
|
|
85 |
i2c_start(); |
|
|
86 |
I2C_Write(0xAB); |
|
|
87 |
|
|
|
88 |
VL=I2C_read(0); |
|
|
89 |
i2c_stop(); |
|
|
90 |
|
|
|
91 |
|
|
|
92 |
delay_ms (1); |
|
|
93 |
|
|
|
94 |
printf("VL %lX \r\n", VL); |
|
|
95 |
printf("LH %lX \r\n", VH); |
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
if(VH==0x0A) |
|
|
103 |
{ |
|
|
104 |
LSB=LSB-1; |
|
|
105 |
printf("Vysledne LSB %lX \r\n", LSB); |
|
|
106 |
while(TRUE) |
|
|
107 |
{ |
|
|
108 |
} |
|
|
109 |
} |
|
|
110 |
|
|
|
111 |
else |
|
|
112 |
{ |
|
|
113 |
|
|
|
114 |
|
|
|
115 |
i2c_start();//blockdata |
|
|
116 |
I2C_Write(0xAA); |
|
|
117 |
I2C_write(0x43); |
|
|
118 |
|
|
|
119 |
i2c_start(); |
|
|
120 |
I2C_Write(0xAA); |
|
|
121 |
I2C_write(0x0A); |
|
|
122 |
i2c_stop(); |
|
|
123 |
|
|
|
124 |
i2c_start();//blockdata |
|
|
125 |
I2C_Write(0xAA); |
|
|
126 |
I2C_write(0x44); |
|
|
127 |
|
|
|
128 |
i2c_start(); |
|
|
129 |
I2C_Write(0xAA); |
|
|
130 |
I2C_write(0x5A); |
|
|
131 |
i2c_stop(); |
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
|
|
|
136 |
} |
|
|
137 |
|
|
|
138 |
i2c_start();//blockdata |
|
|
139 |
I2C_Write(0xAA); |
|
|
140 |
I2C_write(0x60); |
|
|
141 |
|
|
|
142 |
i2c_start(); |
|
|
143 |
I2C_Write(0xAA); |
|
|
144 |
I2C_write(LSB); |
|
|
145 |
i2c_stop(); |
|
|
146 |
|
|
|
147 |
LSB=LSB+1; |
|
|
148 |
|
|
|
149 |
delay_ms (100); |
|
|
150 |
|
|
|
151 |
} |
|
|
152 |
|
|
|
153 |
} |
|
|
154 |
|