160 |
krcmar |
1 |
/**** Analog to Digital Converter ****/ |
|
|
2 |
#include "main.h" |
|
|
3 |
|
|
|
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 |
|
|
9 |
|
|
|
10 |
void main() |
|
|
11 |
{ |
|
|
12 |
int8 t; // Promenna pro nacteni hodnoty z potenciometru |
|
|
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 |
//t=read_adc(); // Prvni precteni cidla |
|
|
27 |
|
|
|
28 |
while(TRUE){ |
|
|
29 |
t=read_adc(); // Prvni precteni cidla |
|
|
30 |
|
|
|
31 |
|
|
|
32 |
if(t>00&&t<50){ |
|
|
33 |
output_high(LED1); |
|
|
34 |
//rozsvit modrou |
|
|
35 |
} |
|
|
36 |
else if(t>50&&t<80){ |
|
|
37 |
output_high (LED1); // Zhasneme LED |
|
|
38 |
delay_us(100); |
|
|
39 |
output_low (LED1); // Rozsvitime LED |
|
|
40 |
delay_us(100); |
|
|
41 |
output_low (LED2); // Rozsvitime LED |
|
|
42 |
delay_us(100); |
|
|
43 |
output_high (LED2); // Zhasneme LED |
|
|
44 |
delay_us(100); |
|
|
45 |
//rozsvit modrou+zelenou |
|
|
46 |
} |
|
|
47 |
else if(t>80&&t<120){ |
|
|
48 |
//output_high(LED2); |
|
|
49 |
//rozvit zelenou |
|
|
50 |
output_low (LED2); // Rozsvitime LED |
|
|
51 |
delay_us(100); |
|
|
52 |
output_high (LED2); // Zhasneme LED |
|
|
53 |
delay_us(100); |
|
|
54 |
} |
|
|
55 |
else if(t>120&&t<160){ |
|
|
56 |
output_high (LED3); // Zhasneme LED |
|
|
57 |
delay_us(100); |
|
|
58 |
output_low (LED3); // Rozsvitime LED |
|
|
59 |
delay_us(100); |
|
|
60 |
output_low (LED2); // Rozsvitime LED |
|
|
61 |
delay_us(100); |
|
|
62 |
output_high (LED2); // Zhasneme LED |
|
|
63 |
delay_us(100); |
|
|
64 |
//rozsvit zelenou+cervenou |
|
|
65 |
} |
|
|
66 |
else if(t>160){ |
|
|
67 |
output_high(LED3); |
|
|
68 |
//rozsvit cervenou |
|
|
69 |
} |
|
|
70 |
|
|
|
71 |
}} |
|
|
72 |
|
|
|
73 |
|