Line 8... |
Line 8... |
8 |
//#include <rtctimer.c> //library for time.h that uses timer2 as time base |
8 |
//#include <rtctimer.c> //library for time.h that uses timer2 as time base |
9 |
|
9 |
|
10 |
//#include <stdlib.h> |
10 |
//#include <stdlib.h> |
11 |
//#include <input.c> //needed for the rs232 input routines |
11 |
//#include <input.c> //needed for the rs232 input routines |
12 |
|
12 |
|
13 |
|
- |
|
14 |
int16 count=0xA5A5; |
- |
|
15 |
const int8 buf_len=8; |
13 |
const int8 buf_len=8; |
16 |
|
14 |
|
17 |
int8 buffer[buf_len]; // I2C buffer |
15 |
int8 buffer[buf_len]; // I2C buffer |
18 |
|
16 |
|
19 |
int8 address=0; |
17 |
int8 address=0; |
20 |
|
18 |
|
21 |
#include "..\common\dbloader.h" |
19 |
#include "..\common\dbloader.h" |
22 |
|
20 |
|
23 |
unsigned int16 timer0_overflow_count; |
21 |
unsigned int16 timer0_overflow_count; |
24 |
float anemo=0; |
22 |
unsigned int16 anemo=0; |
25 |
unsigned int8 rain; |
23 |
unsigned int16 rain=0; |
26 |
|
24 |
|
27 |
//we are using the rtctimer.c library, in which a counter is incremented |
25 |
//we are using the rtctimer.c library, in which a counter is incremented |
28 |
//every time the timer2 interrupt occurs (timer2 overflow). the time math |
26 |
//every time the timer2 interrupt occurs (timer2 overflow). the time math |
29 |
//needs to know what rate the timer2 interrupt occurs. this definition |
27 |
//needs to know what rate the timer2 interrupt occurs. this definition |
30 |
//must match the rate the timer2 is configured for. |
28 |
//must match the rate the timer2 is configured for. |
Line 42... |
Line 40... |
42 |
if(state == 1) //First received byte is address |
40 |
if(state == 1) //First received byte is address |
43 |
{ |
41 |
{ |
44 |
address = incoming; |
42 |
address = incoming; |
45 |
if (incoming == 2) |
43 |
if (incoming == 2) |
46 |
{ |
44 |
{ |
47 |
buffer[0]=make8(count,0); |
45 |
buffer[0]=make8(anemo,0); |
48 |
buffer[1]=make8(count,1); |
46 |
buffer[1]=make8(anemo,1); |
- |
|
47 |
buffer[2]=make8(rain,0); |
- |
|
48 |
buffer[3]=make8(rain,1); |
49 |
} |
49 |
} |
50 |
} |
50 |
} |
51 |
if(state == 2) //Second received byte is data |
51 |
if(state == 2) //Second received byte is data |
52 |
buffer[address] = incoming; |
52 |
buffer[address] = incoming; |
53 |
} |
53 |
} |
Line 60... |
Line 60... |
60 |
|
60 |
|
61 |
#int_TIMER1 |
61 |
#int_TIMER1 |
62 |
void TIMER1_isr(void) |
62 |
void TIMER1_isr(void) |
63 |
{ |
63 |
{ |
64 |
// 32.768 kHz krystal pro timer1 oscilátor |
64 |
// 32.768 kHz krystal pro timer1 oscilátor |
65 |
anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(0xFFFF/32768.0); // pocet pulzu za 1s |
65 |
anemo = ((timer0_overflow_count * 0xFF) + get_timer0()); // pocet pulzu za 1s |
66 |
|
66 |
|
67 |
timer0_overflow_count=0; //nulovani |
67 |
timer0_overflow_count=0; //nulovani |
68 |
set_timer0(0); |
68 |
set_timer0(0); |
69 |
set_timer1(0); |
69 |
set_timer1(0); |
70 |
output_toggle(PIN_E0); |
70 |
output_toggle(PIN_E0); |
Line 171... |
Line 171... |
171 |
|
171 |
|
172 |
|
172 |
|
173 |
set_timer0(0); |
173 |
set_timer0(0); |
174 |
set_timer1(0); |
174 |
set_timer1(0); |
175 |
timer0_overflow_count=0; |
175 |
timer0_overflow_count=0; |
176 |
rain=0; |
- |
|
177 |
|
176 |
|
178 |
buffer[2]=0; |
177 |
buffer[2]=0; |
179 |
buffer[3]=0; |
178 |
buffer[3]=0; |
180 |
buffer[4]=0; |
179 |
buffer[4]=0; |
181 |
buffer[5]=0; |
180 |
buffer[5]=0; |
182 |
|
181 |
|
183 |
|
- |
|
184 |
welcome(); |
182 |
welcome(); |
185 |
|
183 |
|
186 |
set_timer1(0); |
- |
|
187 |
|
- |
|
188 |
while(true) |
184 |
while(true) |
189 |
{ |
185 |
{ |
190 |
printf("count: %X %X %X %X\r\n", buffer[0],buffer[1],buffer[2],buffer[3]); |
186 |
printf("count: %X %X %X %X\r\n", buffer[0],buffer[1],buffer[2],buffer[3]); |
191 |
printf("%6.1f %u \n\r", anemo, rain); |
187 |
printf("%Lu %Lu \n\r", anemo, rain); |
192 |
|
188 |
|
193 |
delay_ms(1000); |
189 |
delay_ms(1000); |
194 |
|
190 |
|
195 |
} |
191 |
} |
196 |
} |
192 |
} |