Line 52... |
Line 52... |
52 |
output_toggle(BEEP); |
52 |
output_toggle(BEEP); |
53 |
delay_us(1/frequency); |
53 |
delay_us(1/frequency); |
54 |
} |
54 |
} |
55 |
} |
55 |
} |
56 |
|
56 |
|
- |
|
57 |
#define TRESHOLD_setup 1 |
- |
|
58 |
#define INTERVAL_setup 0 |
- |
|
59 |
|
- |
|
60 |
|
57 |
void main() |
61 |
void main() |
58 |
{ |
62 |
{ |
59 |
unsigned int16 integration_time=60; |
63 |
unsigned int16 integration_time=60; |
60 |
unsigned int16 time; |
64 |
unsigned int16 time; |
61 |
unsigned int16 last_timer; // promena pro praskani |
65 |
unsigned int16 last_timer; // promena pro praskani |
62 |
unsigned int1 button_press,voltage_setup,time_setup; // semafor pro cteni tlacitek |
66 |
unsigned int1 button_press,setup_mode=INTERVAL_setup; // semafor pro cteni tlacitek |
63 |
unsigned int16 measurement_number=0; |
67 |
unsigned int16 measurement_number=0; |
- |
|
68 |
unsigned int8 treshold=6; |
64 |
|
69 |
|
65 |
setup_adc_ports(sAN0|VSS_VDD); |
70 |
setup_adc_ports(sAN0|VSS_VDD); |
66 |
setup_adc(ADC_CLOCK_DIV_32); |
71 |
setup_adc(ADC_CLOCK_DIV_32); |
67 |
setup_spi(SPI_SS_DISABLED); |
72 |
setup_spi(SPI_SS_DISABLED); |
68 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); |
73 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256); |
Line 80... |
Line 85... |
80 |
output_high(LED3); |
85 |
output_high(LED3); |
81 |
output_high(LED4); |
86 |
output_high(LED4); |
82 |
output_low(BEEP); |
87 |
output_low(BEEP); |
83 |
|
88 |
|
84 |
setup_comparator(CP2_A0_VREF|CP2_OUT_ON_A5); // sets two comparators(A1 and VR and A2 as the output) |
89 |
setup_comparator(CP2_A0_VREF|CP2_OUT_ON_A5); // sets two comparators(A1 and VR and A2 as the output) |
85 |
setup_vref(VREF_HIGH|6); //sets 3.6(vdd *value/32 +vdd/4) if vdd is 5.0V |
90 |
setup_vref(VREF_HIGH|treshold); //sets 3.6(vdd *value/32 +vdd/4) if vdd is 5.0V |
86 |
enable_interrupts(INT_COMP); //enables the comparator interrupt |
91 |
enable_interrupts(INT_COMP); //enables the comparator interrupt |
87 |
enable_interrupts(INT_RTCC); |
92 |
enable_interrupts(INT_RTCC); |
88 |
enable_interrupts(INT_TIMER1); |
93 |
enable_interrupts(INT_TIMER1); |
89 |
enable_interrupts(INT_TIMER2); |
94 |
enable_interrupts(INT_TIMER2); |
90 |
enable_interrupts(GLOBAL); |
95 |
enable_interrupts(GLOBAL); |
Line 118... |
Line 123... |
118 |
lcd_gotoxy(1,1); // prepsani dat na displeje |
123 |
lcd_gotoxy(1,1); // prepsani dat na displeje |
119 |
printf(lcd_putc,"Count:%lu ",pulse_count); |
124 |
printf(lcd_putc,"Count:%lu ",pulse_count); |
120 |
} |
125 |
} |
121 |
|
126 |
|
122 |
lcd_gotoxy(1,2); |
127 |
lcd_gotoxy(1,2); |
123 |
printf(lcd_putc,"T:%lu ",time); |
128 |
printf(lcd_putc,"T:%3lu I:%3lu U:%2u ",time,integration_time,treshold); |
124 |
lcd_gotoxy(9,2); |
- |
|
125 |
printf(lcd_putc,"I:%lu ", integration_time); |
129 |
// printf(lcd_putc,"I:%4lu ", integration_time); |
126 |
|
130 |
|
127 |
if(time == 0) // po uplynuti mereneho intervalu vypis na seriovku |
131 |
if(time == 0) // po uplynuti mereneho intervalu vypis na seriovku |
128 |
{ |
132 |
{ |
129 |
set_timer0(0); |
133 |
set_timer0(0); |
130 |
time_overflow_count=0; |
134 |
time_overflow_count=0; |
Line 141... |
Line 145... |
141 |
{ |
145 |
{ |
142 |
delay_ms(20); |
146 |
delay_ms(20); |
143 |
if(!input(S1)) |
147 |
if(!input(S1)) |
144 |
{ |
148 |
{ |
145 |
button_press=true; |
149 |
button_press=true; |
146 |
if(time_setup==TRUE) |
- |
|
147 |
{ |
- |
|
148 |
sound_beep(100,700); |
150 |
sound_beep(100,700); |
- |
|
151 |
switch (setup_mode) |
- |
|
152 |
{ |
- |
|
153 |
case INTERVAL_setup: |
149 |
if(integration_time < 0xfffa ) integration_time+=5; |
154 |
if(integration_time < 0xfffa ) integration_time+=5; |
- |
|
155 |
break; |
- |
|
156 |
|
- |
|
157 |
case TRESHOLD_setup: |
- |
|
158 |
if(treshold < 0x0a ) treshold +=5; |
- |
|
159 |
setup_vref(VREF_HIGH|treshold); //sets 3.6(vdd *value/32 +vdd/4) if vdd is 5.0V |
- |
|
160 |
break; |
150 |
} |
161 |
} |
151 |
} |
162 |
} |
152 |
} |
163 |
} |
153 |
|
164 |
|
154 |
if(!input(S2)) |
165 |
if(!input(S2)) |
155 |
{ |
166 |
{ |
156 |
delay_ms(20); |
167 |
delay_ms(20); |
157 |
if(!input(S2)) |
168 |
if(!input(S2)) |
158 |
{ |
169 |
{ |
159 |
button_press=true; |
170 |
button_press=true; |
160 |
if(time_setup==TRUE) |
- |
|
161 |
{ |
- |
|
162 |
sound_beep(100,600); |
171 |
sound_beep(100,600); |
- |
|
172 |
switch (setup_mode) |
- |
|
173 |
{ |
- |
|
174 |
case INTERVAL_setup: |
163 |
if(integration_time > 0x0005 ) integration_time-=5; |
175 |
if(integration_time > 0x0005 ) integration_time-=5; |
164 |
|
- |
|
165 |
set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka |
176 |
set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka |
166 |
time_overflow_count=0; |
177 |
time_overflow_count=0; |
167 |
set_timer1(0); |
178 |
set_timer1(0); |
168 |
overflow_count=0; |
179 |
overflow_count=0; |
- |
|
180 |
break; |
- |
|
181 |
case TRESHOLD_setup: |
- |
|
182 |
if(treshold > 0x05 ) treshold +=5; |
- |
|
183 |
setup_vref(VREF_HIGH|treshold); //sets 3.6(vdd *value/32 +vdd/4) if vdd is 5.0V |
- |
|
184 |
break; |
169 |
} |
185 |
} |
170 |
} |
186 |
} |
171 |
} |
187 |
} |
172 |
|
188 |
|
173 |
if(!input(S3)) |
189 |
if(!input(S3)) |
174 |
{ |
190 |
{ |
175 |
delay_ms(20); |
191 |
delay_ms(20); |
176 |
if(!input(S3)) |
192 |
if(!input(S3)) |
177 |
{ |
193 |
{ |
178 |
button_press=true; |
194 |
button_press=true; |
179 |
if(time_setup==TRUE) |
- |
|
180 |
{ |
- |
|
181 |
sound_beep(100,500); |
195 |
sound_beep(100,500); |
- |
|
196 |
switch (setup_mode) |
- |
|
197 |
{ |
- |
|
198 |
case INTERVAL_setup: |
182 |
if(integration_time < 0xffff ) integration_time++; |
199 |
if(integration_time < 0xffff ) integration_time++; |
- |
|
200 |
break; |
- |
|
201 |
|
- |
|
202 |
case TRESHOLD_setup: |
- |
|
203 |
if(treshold < 0x0F ) treshold ++; |
- |
|
204 |
setup_vref(VREF_HIGH|treshold); //sets 3.6(vdd *value/32 +vdd/4) if vdd is 5.0V |
- |
|
205 |
break; |
183 |
} |
206 |
} |
184 |
} |
207 |
} |
185 |
} |
208 |
} |
186 |
|
209 |
|
187 |
if(!input(S4)) |
210 |
if(!input(S4)) |
188 |
{ |
211 |
{ |
189 |
delay_ms(20); |
212 |
delay_ms(20); |
190 |
if(!input(S4)) |
213 |
if(!input(S4)) |
191 |
{ |
214 |
{ |
192 |
button_press=true; |
215 |
button_press=true; |
193 |
if(time_setup==TRUE) |
- |
|
194 |
{ |
- |
|
195 |
sound_beep(100,400); |
216 |
sound_beep(100,400); |
- |
|
217 |
switch (setup_mode) |
- |
|
218 |
{ |
- |
|
219 |
case INTERVAL_setup: |
- |
|
220 |
|
196 |
if(integration_time > 0x0001 ) integration_time--; |
221 |
if(integration_time > 0x0001 ) integration_time--; |
197 |
|
222 |
|
198 |
set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka |
223 |
set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka |
199 |
time_overflow_count=0; |
224 |
time_overflow_count=0; |
200 |
set_timer1(0); |
225 |
set_timer1(0); |
201 |
overflow_count=0; |
226 |
overflow_count=0; |
- |
|
227 |
break; |
- |
|
228 |
case TRESHOLD_setup: |
- |
|
229 |
if(treshold > 0x01 ) treshold--; |
- |
|
230 |
setup_vref(VREF_HIGH|treshold); //sets 3.6(vdd *value/32 +vdd/4) if vdd is 5.0V |
- |
|
231 |
break; |
202 |
} |
232 |
} |
203 |
if(time_setup==TRUE) |
- |
|
204 |
{ |
- |
|
205 |
} |
233 |
} |
206 |
} |
234 |
} |
207 |
|
235 |
|
208 |
if(!input(S5)) // prepnuti na nastavovani casu |
236 |
if(!input(S5)) // prepnuti na nastavovani casu |
209 |
{ |
237 |
{ |
210 |
delay_ms(20); |
238 |
delay_ms(20); |
211 |
if(!input(S5)) |
239 |
if(!input(S5)) |
212 |
{ |
240 |
{ |
213 |
button_press=true; |
241 |
button_press=true; |
214 |
sound_beep(100,800); |
242 |
sound_beep(100,800); |
215 |
voltage_setup=FALSE; |
243 |
setup_mode=INTERVAL_setup; |
- |
|
244 |
lcd_gotoxy(16,1); // prepsani dat na displeje |
216 |
time_setup=TRUE; |
245 |
printf(lcd_putc,"I"); |
217 |
} |
246 |
} |
218 |
} |
247 |
} |
219 |
|
248 |
|
220 |
if(!input(S6)) // prepnuti na nastavovani napeti |
249 |
if(!input(S6)) // prepnuti na nastavovani napeti |
221 |
{ |
250 |
{ |
222 |
delay_ms(20); |
251 |
delay_ms(20); |
223 |
if(!input(S6)) |
252 |
if(!input(S6)) |
224 |
{ |
253 |
{ |
225 |
button_press=true; |
254 |
button_press=true; |
226 |
sound_beep(100,800); |
255 |
sound_beep(100,800); |
227 |
voltage_setup=TRUE; |
256 |
setup_mode=TRESHOLD_setup; |
- |
|
257 |
lcd_gotoxy(16,1); // prepsani dat na displeje |
228 |
time_setup=FALSE; |
258 |
printf(lcd_putc,"U"); |
229 |
} |
259 |
} |
230 |
} |
260 |
} |
231 |
} |
261 |
} |
232 |
|
262 |
|
233 |
if ( input(S1) && input(S2) && input(S3) && input(S4) && input(S5) && input(S6)) // detekce pustenych tlacitek |
263 |
if ( input(S1) && input(S2) && input(S3) && input(S4) && input(S5) && input(S6)) // detekce pustenych tlacitek |