160 |
krcmar |
1 |
|
165 |
krcmar |
2 |
#include "main.h" |
160 |
krcmar |
3 |
|
165 |
krcmar |
4 |
#define LED1 PIN_A2 |
|
|
5 |
#define LED2 PIN_A3 // LEDky |
|
|
6 |
#define LED3 PIN_A5 |
|
|
7 |
#define CIDLO 8 // Port A/D prevodniku |
|
|
8 |
#define TAD 8 // Doba na prevod jednoho bitu |
160 |
krcmar |
9 |
|
165 |
krcmar |
10 |
void main() |
|
|
11 |
{ |
|
|
12 |
int8 t; // Promenna pro nacteni hodnoty z cidla |
|
|
13 |
|
|
|
14 |
setup_adc_ports(AN0); // Povolime analogovy vstup 0 |
|
|
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); |
|
|
18 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
|
|
19 |
setup_timer_1(T1_DISABLED); |
|
|
20 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
21 |
setup_comparator(NC_NC_NC_NC); |
|
|
22 |
setup_vref(FALSE); |
|
|
23 |
|
|
|
24 |
set_adc_channel(CIDLO); // Pripojime cidlo na A/D prevodnik |
|
|
25 |
delay_us(20); // Pockame na nabiti kapacit po prepnuti |
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
while(TRUE){ |
|
|
30 |
t=read_adc(); // Prvni precteni cidla |
|
|
31 |
//printf("%d\n\r",t); |
|
|
32 |
|
|
|
33 |
if(t>00&&t<40){ |
|
|
34 |
output_low(LED2); |
|
|
35 |
output_low(LED3); |
|
|
36 |
output_high(LED1); |
|
|
37 |
//rozsvit modrou |
|
|
38 |
} |
188 |
krcmar |
39 |
else if(t>39&&t<60){ |
165 |
krcmar |
40 |
output_low(LED3); |
|
|
41 |
output_high (LED1); // Zhasneme LED |
|
|
42 |
delay_us(100); |
|
|
43 |
output_low (LED1); // Rozsvitime LED |
|
|
44 |
delay_us(100); |
|
|
45 |
output_low (LED2); // Rozsvitime LED |
|
|
46 |
delay_us(100); |
|
|
47 |
output_high (LED2); // Zhasneme LED |
|
|
48 |
delay_us(100); |
|
|
49 |
//rozsvit modrou+zelenou |
|
|
50 |
} |
188 |
krcmar |
51 |
else if(t>59&&t<80){ |
165 |
krcmar |
52 |
output_low(LED3); |
|
|
53 |
output_low(LED1); |
|
|
54 |
output_high(LED2); |
|
|
55 |
//rozvit zelenou |
|
|
56 |
} |
188 |
krcmar |
57 |
else if(t>79&&t<100){ |
165 |
krcmar |
58 |
output_low(LED1); |
|
|
59 |
output_high (LED3); // Zhasneme LED |
|
|
60 |
delay_us(100); |
|
|
61 |
output_low (LED3); // Rozsvitime LED |
|
|
62 |
delay_us(100); |
|
|
63 |
output_low (LED2); // Rozsvitime LED |
|
|
64 |
delay_us(100); |
|
|
65 |
output_high (LED2); // Zhasneme LED |
|
|
66 |
delay_us(100); |
|
|
67 |
//rozsvit zelenou+cervenou |
|
|
68 |
} |
188 |
krcmar |
69 |
else if(t>99){ |
165 |
krcmar |
70 |
output_low(LED1); |
|
|
71 |
output_low(LED2); |
|
|
72 |
output_high(LED3); |
|
|
73 |
//rozsvit cervenou |
|
|
74 |
} |
|
|
75 |
}} |
|
|
76 |
|
|
|
77 |
|