Rev Author Line No. Line
2953 jacho 1 //#include "C:\Users\Honza\Documents\pic\I2C_bat_pam\main.h"
2 #define EEPROM_SDA PIN_B0
3 #define EEPROM_SCL PIN_B1
4 #use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)
5 #use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B2,bits=8) //rcv TXD xmit RXD
6 #include "main.h"
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 STAV1,STAV2;
22  
23 unsigned int16 SOUCET, SOUCET1;
24 unsigned int8 LSB=0,ZK,k=0;
25 //unsigned int8
26  
27 while(TRUE)
28 {
29  
30  
31  
32  
33 i2c_start(); //blockdatacontrol
34 I2C_Write(0xAA);
35 I2C_write(0x61);
36 i2c_start();
37 I2C_Write(0xAA);
38 i2c_write(0x00);
39 i2c_stop();
40 delay_ms (1);
41  
42  
43 i2c_start();//dataflashclass
44 I2C_Write(0xAA);
45 I2C_write(0x3e);
46  
47 i2c_start();
48 I2C_Write(0xAA);
49 i2c_write(0x40);
50 i2c_stop();
51 delay_ms (1);
52  
53  
54 i2c_start();//dataflashblock
55 I2C_Write(0xAA);
56 I2C_write(0x3f);
57  
58 i2c_start();
59 I2C_Write(0xAA);
60 I2C_write(0x00);
61 i2c_stop();
62  
63 delay_ms (1);
64  
65 i2c_start();//blockdata
66 I2C_Write(0xAA);
67 I2C_write(0x44);
68  
69 i2c_start();
70 I2C_Write(0xAB);
71 ZK=I2C_read(0);
72 i2c_stop();
73  
74 delay_ms (1);
75  
76 printf("LED %lX \r\n", ZK);
77  
78 if(ZK==0x73)
79 {
80 LSB=LSB-1;
81 printf("Vysledne LSB %lX \r\n", LSB);
82 while(TRUE)
83 {
84 }
85 }
86  
87 else
88 {
89 i2c_start();//blockdata
90 I2C_Write(0xAA);
91 I2C_write(0x44);
92  
93 i2c_start();
94 I2C_Write(0xAA);
95 I2C_write(0x73); //pro 5LED 0x53 pro 7led 0x73
96 i2c_stop();
97  
98  
99 int i=64;
100 SOUCET=0;
101 SOUCET1=0;
102  
103 /*
104 for (i=64;i<96;++i)
105 {
106 printf("%u\r\n",i);
107 i2c_stop();
108  
109 i2c_start();//blockdata
110 I2C_Write(0xAA);
111 I2C_write(i);
112  
113 i2c_start();
114 I2C_Write(0xAB);
115 STAV1=I2C_read(0);
116 i2c_stop();
117  
118 printf("STAV %lX \r\n", STAV1);
119 SOUCET=SOUCET+STAV1;
120  
121  
122  
123  
124  
125 }
126 printf("SOUCET: %lX (procenta)\r\n", SOUCET);
127 SOUCET1=SOUCET;
128 SOUCET1=SOUCET1>>8;
129 printf("Deleno 256: %lX (procenta)\r\n", SOUCET1);
130 SOUCET1=SOUCET-SOUCET1;
131 printf("Soucet - soucet/256: %lX \r\n", SOUCET1);
132 LSB=(unsigned int8)SOUCET1;
133 printf("LSB: %lX\r\n", LSB);
134 //printf("Stav: %X (procenta)\r\n", STAV2);
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 }
147  
148 LSB=LSB+1;
149  
150 delay_ms (100);
151 }
152 }