Rev Author Line No. Line
1045 jacho 1 #include "C:\Users\Honza\Documents\pic\I2C_bat_pam\Q_MAX\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(0x52);
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(0x00);
64 i2c_stop();
65  
66 delay_ms (1);
67  
68  
69  
70  
71 i2c_start();//blockdata
72 I2C_Write(0xAA);
73 I2C_write(0x40);
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(0x41);
84  
85 i2c_start();
86 I2C_Write(0xAB);
87  
88 VL=I2C_read(0);
89 i2c_stop();
90  
91  
92 delay_ms (10);
93  
94 printf("VL %lX \r\n", VL);
95 printf("LH %lX \r\n", VH);
96  
97 if(VL==0x48)
98 {
99 LSB=LSB-1;
100 printf("Vysledne LSB %lX \r\n", LSB);
101 while(TRUE)
102 {
103 }
104 }
105  
106 else
107 {
108 i2c_start();//blockdata
109 I2C_Write(0xAA);
110 I2C_write(0x40);
111  
112 i2c_start();
113 I2C_Write(0xAA);
114 I2C_write(0x0D);
115 i2c_stop();
116  
117 i2c_start();//blockdata
118 I2C_Write(0xAA);
119 I2C_write(0x41);
120  
121 i2c_start();
122 I2C_Write(0xAA);
123 I2C_write(0x48);
124 i2c_stop();
125  
126  
127  
128  
129  
130  
131 }
132  
133 i2c_start();//blockdata
134 I2C_Write(0xAA);
135 I2C_write(0x60);
136  
137 i2c_start();
138 I2C_Write(0xAA);
139 I2C_write(LSB);
140 i2c_stop();
141  
142 LSB=LSB+1;
143  
144 delay_ms (100);
145  
146  
147  
148  
149  
150  
151  
152  
153 }
154  
155 }
156