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