Rev Author Line No. Line
1045 jacho 1 #include "C:\Users\Honza\Documents\pic\I2C_bat_pam\Cteni\main.h"
2  
3  
4 #define EEPROM_SDA PIN_B0
5 #define EEPROM_SCL PIN_B1
6 #use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)
7 #use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B2,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(0x50);
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(0x02);
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(VH==0x00)
102 {
103 LSB=LSB-1;
104 printf("Vysledne LSB %lX \r\n", LSB);
105 while(TRUE)
106 {
107 }
108 }
109  
110 else
111 {
112  
113  
114 i2c_start();//blockdata
115 I2C_Write(0xAA);
116 I2C_write(0x45);
117  
118 i2c_start();
119 I2C_Write(0xAA);
120 I2C_write(0x00);
121 i2c_stop();
122  
123  
124  
125  
126  
127  
128 }
129  
130 i2c_start();//blockdata
131 I2C_Write(0xAA);
132 I2C_write(0x60);
133  
134 i2c_start();
135 I2C_Write(0xAA);
136 I2C_write(LSB);
137 i2c_stop();
138  
139 LSB=LSB+1;
140  
141 delay_ms (100);
142  
143 }
144  
145 }
146