Rev Author Line No. Line
188 krcmar 1 //RONĀ“s RGB teplomer
160 krcmar 2 #include "main.h"
3  
188 krcmar 4 #define LED1 PIN_A2 // LED B
5 #define LED2 PIN_A3 // LED G
6 #define LED3 PIN_A5 // LED R
7 #define CIDLO 8 // Port A/D prevodniku (Vstup RA_O)
160 krcmar 8 #define TAD 8 // Doba na prevod jednoho bitu
9  
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_spi(SPI_SS_DISABLED);
17 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
18 setup_timer_1(T1_DISABLED);
19 setup_timer_2(T2_DISABLED,0,1);
20 setup_comparator(NC_NC_NC_NC);
21 setup_vref(FALSE);
22  
23 set_adc_channel(CIDLO); // Pripojime cidlo na A/D prevodnik
24 delay_us(20); // Pockame na nabiti kapacit po prepnuti
25  
26  
27  
28 while(TRUE){
188 krcmar 29 t=read_adc(); // prvni precteni cidla
30  
160 krcmar 31  
165 krcmar 32 if(t>00&&t<40){
188 krcmar 33 output_low(LED2); // zhasni
34 output_low(LED3); // zhasni
35 output_high(LED1); // rozsvit
160 krcmar 36 //rozsvit modrou
37 }
165 krcmar 38 else if(t>39&&t<60){
160 krcmar 39 output_low(LED3);
188 krcmar 40 output_high (LED1); // rozsvit
160 krcmar 41 delay_us(100);
188 krcmar 42 output_low (LED1); // zhasni
160 krcmar 43 delay_us(100);
188 krcmar 44 output_low (LED2); // zhasni
160 krcmar 45 delay_us(100);
188 krcmar 46 output_high (LED2); // rozsvit
160 krcmar 47 delay_us(100);
48 //rozsvit modrou+zelenou
49 }
165 krcmar 50 else if(t>59&&t<80){
188 krcmar 51 output_low(LED3); // zhasni
52 output_low(LED1); // zhasni
53 output_high(LED2); // rozsvit
54 //rozsvit zelenou
160 krcmar 55 }
165 krcmar 56 else if(t>79&&t<100){
160 krcmar 57 output_low(LED1);
188 krcmar 58 output_high (LED3); // rozsvit
160 krcmar 59 delay_us(100);
188 krcmar 60 output_low (LED3); // zhasni
160 krcmar 61 delay_us(100);
188 krcmar 62 output_low (LED2); // zhasni
160 krcmar 63 delay_us(100);
188 krcmar 64 output_high (LED2); // rozsvit
160 krcmar 65 delay_us(100);
66 //rozsvit zelenou+cervenou
67 }
165 krcmar 68 else if(t>99){
160 krcmar 69 output_low(LED1);
70 output_low(LED2);
71 output_high(LED3);
72 //rozsvit cervenou
73 }
74 }}
75  
76