Line 1... |
Line -... |
1 |
|
- |
|
- |
|
1 |
//RONĀ“s RGB teplomer |
2 |
#include "main.h" |
2 |
#include "main.h" |
3 |
|
3 |
|
4 |
#define LED1 PIN_A2 |
4 |
#define LED1 PIN_A2 // LED B |
5 |
#define LED2 PIN_A3 // LEDky |
5 |
#define LED2 PIN_A3 // LED G |
6 |
#define LED3 PIN_A5 |
6 |
#define LED3 PIN_A5 // LED R |
7 |
#define CIDLO 8 // Port A/D prevodniku |
7 |
#define CIDLO 8 // Port A/D prevodniku (Vstup RA_O) |
8 |
#define TAD 8 // Doba na prevod jednoho bitu |
8 |
#define TAD 8 // Doba na prevod jednoho bitu |
9 |
|
9 |
|
10 |
void main() |
10 |
void main() |
11 |
{ |
11 |
{ |
12 |
int8 t; // Promenna pro nacteni hodnoty z cidla |
12 |
int8 t; // Promenna pro nacteni hodnoty z cidla |
13 |
|
13 |
|
14 |
setup_adc_ports(AN0); // Povolime analogovy vstup 0 |
14 |
setup_adc_ports(AN0); // Povolime analogovy vstup 0 |
15 |
setup_adc(ADC_CLOCK_DIV_8); // Delicka hodin pro prevodnik |
15 |
setup_adc(ADC_CLOCK_DIV_8); // Delicka hodin pro prevodnik |
16 |
// setup_psp(PSP_DISABLED); // Tento HW ma pouze PIC16F877A |
- |
|
17 |
setup_spi(SPI_SS_DISABLED); |
16 |
setup_spi(SPI_SS_DISABLED); |
18 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
17 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
19 |
setup_timer_1(T1_DISABLED); |
18 |
setup_timer_1(T1_DISABLED); |
20 |
setup_timer_2(T2_DISABLED,0,1); |
19 |
setup_timer_2(T2_DISABLED,0,1); |
21 |
setup_comparator(NC_NC_NC_NC); |
20 |
setup_comparator(NC_NC_NC_NC); |
Line 25... |
Line 24... |
25 |
delay_us(20); // Pockame na nabiti kapacit po prepnuti |
24 |
delay_us(20); // Pockame na nabiti kapacit po prepnuti |
26 |
|
25 |
|
27 |
|
26 |
|
28 |
|
27 |
|
29 |
while(TRUE){ |
28 |
while(TRUE){ |
30 |
t=read_adc(); // Prvni precteni cidla |
29 |
t=read_adc(); // prvni precteni cidla |
31 |
//printf("%d\n\r",t); |
- |
|
- |
|
30 |
|
32 |
|
31 |
|
33 |
if(t>00&&t<40){ |
32 |
if(t>00&&t<40){ |
34 |
output_low(LED2); |
33 |
output_low(LED2); // zhasni |
35 |
output_low(LED3); |
34 |
output_low(LED3); // zhasni |
36 |
output_high(LED1); |
35 |
output_high(LED1); // rozsvit |
37 |
//rozsvit modrou |
36 |
//rozsvit modrou |
38 |
} |
37 |
} |
39 |
else if(t>39&&t<60){ |
38 |
else if(t>39&&t<60){ |
40 |
output_low(LED3); |
39 |
output_low(LED3); |
41 |
output_high (LED1); // Zhasneme LED |
40 |
output_high (LED1); // rozsvit |
42 |
delay_us(100); |
41 |
delay_us(100); |
43 |
output_low (LED1); // Rozsvitime LED |
42 |
output_low (LED1); // zhasni |
44 |
delay_us(100); |
43 |
delay_us(100); |
45 |
output_low (LED2); // Rozsvitime LED |
44 |
output_low (LED2); // zhasni |
46 |
delay_us(100); |
45 |
delay_us(100); |
47 |
output_high (LED2); // Zhasneme LED |
46 |
output_high (LED2); // rozsvit |
48 |
delay_us(100); |
47 |
delay_us(100); |
49 |
//rozsvit modrou+zelenou |
48 |
//rozsvit modrou+zelenou |
50 |
} |
49 |
} |
51 |
else if(t>59&&t<80){ |
50 |
else if(t>59&&t<80){ |
52 |
output_low(LED3); |
51 |
output_low(LED3); // zhasni |
53 |
output_low(LED1); |
52 |
output_low(LED1); // zhasni |
54 |
output_high(LED2); |
53 |
output_high(LED2); // rozsvit |
55 |
//rozvit zelenou |
54 |
//rozsvit zelenou |
56 |
} |
55 |
} |
57 |
else if(t>79&&t<100){ |
56 |
else if(t>79&&t<100){ |
58 |
output_low(LED1); |
57 |
output_low(LED1); |
59 |
output_high (LED3); // Zhasneme LED |
58 |
output_high (LED3); // rozsvit |
60 |
delay_us(100); |
59 |
delay_us(100); |
61 |
output_low (LED3); // Rozsvitime LED |
60 |
output_low (LED3); // zhasni |
62 |
delay_us(100); |
61 |
delay_us(100); |
63 |
output_low (LED2); // Rozsvitime LED |
62 |
output_low (LED2); // zhasni |
64 |
delay_us(100); |
63 |
delay_us(100); |
65 |
output_high (LED2); // Zhasneme LED |
64 |
output_high (LED2); // rozsvit |
66 |
delay_us(100); |
65 |
delay_us(100); |
67 |
//rozsvit zelenou+cervenou |
66 |
//rozsvit zelenou+cervenou |
68 |
} |
67 |
} |
69 |
else if(t>99){ |
68 |
else if(t>99){ |
70 |
output_low(LED1); |
69 |
output_low(LED1); |