Rev 3301 Rev 3302
Line 1... Line 1...
1 #include ".\main.h" 1 #include ".\main.h"
2   2  
3 #define LED1 PIN_C6 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 3 #define LED1 PIN_C6 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
4 #define LED2 PIN_C5 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 4 #define LED2 PIN_C5 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
5 #define LED3 PIN_C4 //CHANGE PIN_XX TO YOUR LED PIN NUMBER 5 #define LED3 PIN_C4 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
6 #define LED4 PIN_D3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER 6 #define LED4 PIN_D3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER
7   7  
8 #define S1 PIN_B0 //Raw up 8 #define S1 PIN_B0 //Raw up
9 #define S2 PIN_B1 //Raw down 9 #define S2 PIN_B1 //Raw down
Line 30... Line 30...
30 #define HALFDUTY (int16)MAXDUTY/2 30 #define HALFDUTY (int16)MAXDUTY/2
31 //#define DIVISOR 199 // 10 kHz 31 //#define DIVISOR 199 // 10 kHz
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 regreseM (2.02) 35 #define MAX_OUTPUT 706
36 #define regreseN (-451) -  
37   -  
38   -  
39   36  
40 void sound_beep( unsigned int lenght, int16 frequency) 37 void sound_beep( unsigned int lenght, int16 frequency)
41 { 38 {
42 unsigned int i; 39 unsigned int i;
43 40
Line 52... Line 49...
52 { 49 {
53 unsigned int16 setpoint=43; 50 unsigned int16 setpoint=43;
54 unsigned int16 napeti; 51 unsigned int16 napeti;
55 unsigned int1 button_press; // semafor pro cteni tlacitek 52 unsigned int1 button_press; // semafor pro cteni tlacitek
56   53  
57 setup_adc_ports(sAN0|VSS_VDD); 54 setup_adc_ports(sAN0|VSS_VREF);
58 setup_adc(ADC_CLOCK_DIV_2); 55 setup_adc(ADC_CLOCK_DIV_2);
59 setup_spi(SPI_SS_DISABLED); 56 setup_spi(SPI_SS_DISABLED);
60 setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); 57 setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
61 setup_timer_1(T1_DISABLED); 58 setup_timer_1(T1_DISABLED);
62 setup_timer_2(T2_DIV_BY_1,DIVISOR,1); 59 setup_timer_2(T2_DIV_BY_1,DIVISOR,1);
Line 65... Line 62...
65 set_pwm1_duty(HALFDUTY); 62 set_pwm1_duty(HALFDUTY);
66 set_pwm2_duty(MAXDUTY); 63 set_pwm2_duty(MAXDUTY);
67 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard 64 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
68 setup_oscillator(OSC_8MHZ); 65 setup_oscillator(OSC_8MHZ);
69   66  
70 // set_pwm1_duty(0); -  
71 // set_pwm2_duty(0); -  
72   -  
73 output_high(LED1); 67 output_high(LED1);
74 output_high(LED2); 68 output_high(LED2);
75 output_high(LED3); 69 output_high(LED3);
76 output_high(LED4); 70 output_high(LED4);
77 output_low(BEEP); 71 output_low(BEEP);
Line 125... Line 119...
125 delay_ms(20); 119 delay_ms(20);
126 if(!input(S1)) 120 if(!input(S1))
127 { 121 {
128 button_press=true; 122 button_press=true;
129 sound_beep(100,700); 123 sound_beep(100,700);
130 if(setpoint < (1023-5) )setpoint+=5; 124 if(setpoint < (MAX_OUTPUT-5) )setpoint+=5;
131 } 125 }
132 } 126 }
133   127  
134 if(!input(S2)) 128 if(!input(S2))
135 { 129 {
Line 147... Line 141...
147 delay_ms(20); 141 delay_ms(20);
148 if(!input(S3)) 142 if(!input(S3))
149 { 143 {
150 button_press=true; 144 button_press=true;
151 sound_beep(100,500); 145 sound_beep(100,500);
152 if(setpoint < 1023 )setpoint++; 146 if(setpoint < MAX_OUTPUT )setpoint++;
153 } 147 }
154 } 148 }
155   149  
156 if(!input(S4)) 150 if(!input(S4))
157 { 151 {