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  
31  
32  
33  
34 i2c_start(); //blockdatacontrol
35 I2C_Write(0xAA);
36 I2C_write(0x61);
37 i2c_start();
38 I2C_Write(0xAA);
39 i2c_write(0x00);
40 i2c_stop();
41 delay_ms (1);
42  
43  
44 i2c_start();//dataflashclass
45 I2C_Write(0xAA);
46 I2C_write(0x3e);
47  
48 i2c_start();
49 I2C_Write(0xAA);
50 i2c_write(0x40);
51 i2c_stop();
52 delay_ms (1);
53  
54  
55 i2c_start();//dataflashblock
56 I2C_Write(0xAA);
57 I2C_write(0x3f);
58  
59 i2c_start();
60 I2C_Write(0xAA);
61 I2C_write(0x00);
62 i2c_stop();
63  
64 delay_ms (1);
65  
66 i2c_start();//blockdata
67 I2C_Write(0xAA);
68 I2C_write(0x44);
69  
70 i2c_start();
71 I2C_Write(0xAB);
72 ZK=I2C_read(0);
73 i2c_stop();
74  
75 delay_ms (1);
76  
77 printf("LED %lX \r\n", ZK);
78  
79 if(ZK==0x73)
80 {
81 LSB=LSB-1;
82 printf("Vysledne LSB %lX \r\n", LSB);
83 while(TRUE)
84 {
85 }
86 }
87  
88 else
89 {
90 i2c_start();//blockdata
91 I2C_Write(0xAA);
92 I2C_write(0x44);
93  
94 i2c_start();
95 I2C_Write(0xAA);
96 I2C_write(0x73); //pro 5LED 0x53 pro 7led 0x73
97 i2c_stop();
98  
99  
100 int i=64;
101 SOUCET=0;
102 SOUCET1=0;
103  
104 /*
105 for (i=64;i<96;++i)
106 {
107 printf("%u\r\n",i);
108 i2c_stop();
109  
110 i2c_start();//blockdata
111 I2C_Write(0xAA);
112 I2C_write(i);
113  
114 i2c_start();
115 I2C_Write(0xAB);
116 STAV1=I2C_read(0);
117 i2c_stop();
118  
119 printf("STAV %lX \r\n", STAV1);
120 SOUCET=SOUCET+STAV1;
121  
122  
123  
124  
125  
126 }
127 printf("SOUCET: %lX (procenta)\r\n", SOUCET);
128 SOUCET1=SOUCET;
129 SOUCET1=SOUCET1>>8;
130 printf("Deleno 256: %lX (procenta)\r\n", SOUCET1);
131 SOUCET1=SOUCET-SOUCET1;
132 printf("Soucet - soucet/256: %lX \r\n", SOUCET1);
133 LSB=(unsigned int8)SOUCET1;
134 printf("LSB: %lX\r\n", LSB);
135 //printf("Stav: %X (procenta)\r\n", STAV2);
136 */
137  
138 i2c_start();//blockdata
139 I2C_Write(0xAA);
140 I2C_write(0x60);
141  
142 i2c_start();
143 I2C_Write(0xAA);
144 I2C_write(LSB);
145 i2c_stop();
146  
147 }
148  
149 LSB=LSB+1;
150  
151 delay_ms (100);
152 }
153 }