Rev 3305 Rev 3308
Line 32... Line 32...
32 #define DIVISOR 99 // 20 kHz 32 #define DIVISOR 99 // 20 kHz
33 //#define DIVISOR 39 // 50 kHz 33 //#define DIVISOR 39 // 50 kHz
34   34  
35 #define MAX_OUTPUT 1000 35 #define MAX_OUTPUT 1000
36   36  
-   37 unsigned int16 setpoint=43;
-   38 unsigned int16 adc_value;
-   39 int1 output_permit=FALSE;
-   40  
-   41 #INT_AD
-   42 void adc_handler() {
-   43  
-   44 adc_value = read_adc();
-   45 if(output_permit == TRUE)
-   46 {
-   47 if (adc_value <= setpoint)
-   48 {
-   49 set_pwm2_duty((int16)255); // zapnuti menice
-   50 output_low(LED2);
-   51 }
-   52 else // vypnuti menice
-   53 {
-   54 set_pwm2_duty((int16)MAXDUTY);
-   55 output_high(LED2);
-   56 }
-   57  
-   58 }
-   59 else
-   60 {
-   61 set_pwm2_duty((int16)MAXDUTY);
-   62 output_high(LED2);
-   63 }
-   64 }
-   65  
37 void sound_beep( unsigned int lenght, int16 frequency) 66 void sound_beep( unsigned int lenght, int16 frequency)
38 { 67 {
39 unsigned int i; 68 unsigned int i;
40 69
41 for(i=0;i<=lenght;i++) 70 for(i=0;i<=lenght;i++)
Line 44... Line 73...
44 delay_us(1/frequency); 73 delay_us(1/frequency);
45 } 74 }
46 } 75 }
47   76  
48 void main() 77 void main()
49 { 78 {
50 unsigned int16 setpoint=43; -  
51 unsigned int16 napeti; -  
52 unsigned int1 button_press; // semafor pro cteni tlacitek 79 unsigned int1 button_press; // semafor pro cteni tlacitek
53   80  
54 setup_adc_ports(sAN0|VSS_VREF); 81 setup_adc_ports(sAN0|VSS_VREF);
55 setup_adc(ADC_CLOCK_DIV_32); 82 setup_adc(ADC_CLOCK_DIV_32);
56 setup_spi(SPI_SS_DISABLED); 83 setup_spi(SPI_SS_DISABLED);
Line 62... Line 89...
62 set_pwm1_duty(HALFDUTY); 89 set_pwm1_duty(HALFDUTY);
63 set_pwm2_duty(MAXDUTY); 90 set_pwm2_duty(MAXDUTY);
64 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard 91 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
65 setup_oscillator(OSC_8MHZ); 92 setup_oscillator(OSC_8MHZ);
66   93  
-   94 enable_interrupts(INT_AD);
67 // enable_interrupts(GLOBAL); 95 enable_interrupts(GLOBAL);
68   96  
69 output_high(LED1); 97 output_high(LED1);
70 output_high(LED2); 98 output_high(LED2);
71 output_high(LED3); 99 output_high(LED3);
72 output_high(LED4); 100 output_high(LED4);
Line 81... Line 109...
81 lcd_putc(" MLAB.cz"); 109 lcd_putc(" MLAB.cz");
82 Delay_ms(1000); 110 Delay_ms(1000);
83 111
84 lcd_putc("\f"); 112 lcd_putc("\f");
85   113  
86 //read_adc(ADC_START_ONLY); 114 read_adc(ADC_START_ONLY);
87 115
88 while(true) 116 while(true)
89 { 117 {
90 napeti = read_adc(); -  
91 if(input(OUTPUT_ENABLE)) 118 if(input(OUTPUT_ENABLE)) output_permit=TRUE;
92 { -  
93 if (napeti <= setpoint) -  
94 { -  
95 set_pwm2_duty((int16)255); // zapnuti menice -  
96 output_low(LED2); -  
97 } -  
98 else // vypnuti menice -  
99 { -  
100 set_pwm2_duty((int16)MAXDUTY); -  
101 output_high(LED2); 119 else output_permit=FALSE;
102 } -  
103   -  
104 } -  
105 else -  
106 { -  
107 set_pwm2_duty((int16)MAXDUTY); -  
108 output_high(LED2); -  
109 } -  
110 120
111 lcd_gotoxy(1,1); 121 lcd_gotoxy(1,1);
112 printf(lcd_putc,"%4lu",napeti); 122 printf(lcd_putc,"%4lu",adc_value);
113 lcd_gotoxy(1,2); 123 lcd_gotoxy(1,2);
114   124  
115 if(input(OUTPUT_ENABLE))printf(lcd_putc,"Set:%lu "setpoint); 125 if(input(OUTPUT_ENABLE))printf(lcd_putc,"Set:%lu "setpoint);
116 else printf(lcd_putc,"DISABLED"); 126 else printf(lcd_putc,"DISABLED");
117   127