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