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