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, EX: PIN_A5 |
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, EX: PIN_A5 |
5 |
#define LED3 PIN_C4 //CHANGE PIN_XX TO YOUR LED PIN NUMBER |
5 |
#define LED3 PIN_C4 // pulse detect |
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_C2 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 |
8 |
#define S1 PIN_C2 // raw up |
9 |
#define S2 PIN_C3 //CHANGE PIN_XX TO YOUR LED PIN NUMBER, EX: PIN_A5 |
9 |
#define S2 PIN_C3 // raw down |
10 |
#define S3 PIN_D0 //CHANGE PIN_XX TO YOUR LED PIN NUMBER |
10 |
#define S3 PIN_D0 // fine up |
11 |
#define S4 PIN_D1 //CHANGE PIN_XX TO YOUR LED PIN NUMBER |
11 |
#define S4 PIN_D1 // fine down |
- |
|
12 |
#define S5 PIN_B1 // time setup |
- |
|
13 |
#define S6 PIN_B2 // treshold setup |
12 |
|
14 |
|
13 |
#define BEEP PIN_D2 //piezo beeper |
15 |
#define BEEP PIN_D2 //piezo beeper |
14 |
|
16 |
|
15 |
#define LCD_ENABLE_PIN PIN_E0 //// |
17 |
#define LCD_ENABLE_PIN PIN_E0 //// |
16 |
#define LCD_RS_PIN PIN_E1 //// |
18 |
#define LCD_RS_PIN PIN_E1 //// |
Line 55... |
Line 57... |
55 |
void main() |
57 |
void main() |
56 |
{ |
58 |
{ |
57 |
unsigned int16 integration_time=60; |
59 |
unsigned int16 integration_time=60; |
58 |
unsigned int16 time; |
60 |
unsigned int16 time; |
59 |
unsigned int16 last_timer; // promena pro praskani |
61 |
unsigned int16 last_timer; // promena pro praskani |
60 |
unsigned int1 button_press; // semafor pro cteni tlacitek |
62 |
unsigned int1 button_press,voltage_setup,time_setup; // semafor pro cteni tlacitek |
61 |
unsigned int16 measurement_number=0; |
63 |
unsigned int16 measurement_number=0; |
62 |
|
64 |
|
63 |
setup_adc_ports(sAN0|VSS_VDD); |
65 |
setup_adc_ports(sAN0|VSS_VDD); |
64 |
setup_adc(ADC_CLOCK_DIV_32); |
66 |
setup_adc(ADC_CLOCK_DIV_32); |
65 |
setup_spi(SPI_SS_DISABLED); |
67 |
setup_spi(SPI_SS_DISABLED); |
Line 95... |
Line 97... |
95 |
|
97 |
|
96 |
lcd_putc("\f"); |
98 |
lcd_putc("\f"); |
97 |
printf("\r\n"); |
99 |
printf("\r\n"); |
98 |
|
100 |
|
99 |
set_timer1(0); |
101 |
set_timer1(0); |
- |
|
102 |
|
- |
|
103 |
lcd_gotoxy(1,1); // vypsani hodnoty count, abz byla na LCD hned od zapnuti |
- |
|
104 |
printf(lcd_putc,"Count:%lu ",pulse_count); |
100 |
|
105 |
|
101 |
while(true) |
106 |
while(true) |
102 |
{ |
107 |
{ |
103 |
pulse_count = get_timer1() + (0xffff * overflow_count); |
108 |
pulse_count = get_timer1() + (0xffff * overflow_count); // compute pulse count |
104 |
time = integration_time + 1 - (time_overflow_count * 0.0327) ; |
109 |
time = integration_time + 1 - (time_overflow_count * 0.0327); // compute time interval |
105 |
|
110 |
|
106 |
if(get_timer1() != last_timer) |
111 |
if(get_timer1() != last_timer) // timer count increment detection |
107 |
{ |
112 |
{ |
108 |
output_toggle(BEEP); |
113 |
output_toggle(BEEP); |
- |
|
114 |
delay_ms(1); |
- |
|
115 |
output_toggle(BEEP); |
- |
|
116 |
output_toggle(LED3); |
109 |
last_timer=get_timer1(); |
117 |
last_timer=get_timer1(); |
- |
|
118 |
lcd_gotoxy(1,1); // prepsani dat na displeje |
- |
|
119 |
printf(lcd_putc,"Count:%lu ",pulse_count); |
110 |
} |
120 |
} |
111 |
|
121 |
|
112 |
lcd_gotoxy(1,1); |
- |
|
113 |
printf(lcd_putc,"Count:%lu ",pulse_count); |
- |
|
114 |
lcd_gotoxy(1,2); |
122 |
lcd_gotoxy(1,2); |
115 |
printf(lcd_putc,"T:%lu ",time); |
123 |
printf(lcd_putc,"T:%lu ",time); |
116 |
lcd_gotoxy(9,2); |
124 |
lcd_gotoxy(9,2); |
117 |
printf(lcd_putc,"I:%lu ", integration_time); |
125 |
printf(lcd_putc,"I:%lu ", integration_time); |
118 |
|
126 |
|
119 |
if(time == 0) |
127 |
if(time == 0) // po uplynuti mereneho intervalu vypis na seriovku |
120 |
{ |
128 |
{ |
121 |
set_timer0(0); |
129 |
set_timer0(0); |
122 |
time_overflow_count=0; |
130 |
time_overflow_count=0; |
123 |
sound_beep(1000,700); |
131 |
sound_beep(1000,700); |
124 |
printf("$GMC1.0 %lu %lu %lu \r\n", measurement_number, integration_time, pulse_count); |
132 |
printf("$GMC1.0 %lu %lu %lu \r\n", measurement_number, integration_time, pulse_count); |
Line 133... |
Line 141... |
133 |
{ |
141 |
{ |
134 |
delay_ms(20); |
142 |
delay_ms(20); |
135 |
if(!input(S1)) |
143 |
if(!input(S1)) |
136 |
{ |
144 |
{ |
137 |
button_press=true; |
145 |
button_press=true; |
- |
|
146 |
if(time_setup==TRUE) |
- |
|
147 |
{ |
138 |
sound_beep(100,700); |
148 |
sound_beep(100,700); |
139 |
if(integration_time < 0xfffa ) integration_time+=5; |
149 |
if(integration_time < 0xfffa ) integration_time+=5; |
140 |
|
150 |
} |
141 |
} |
151 |
} |
142 |
} |
152 |
} |
143 |
|
153 |
|
144 |
if(!input(S2)) |
154 |
if(!input(S2)) |
145 |
{ |
155 |
{ |
146 |
delay_ms(20); |
156 |
delay_ms(20); |
147 |
if(!input(S2)) |
157 |
if(!input(S2)) |
148 |
{ |
158 |
{ |
149 |
button_press=true; |
159 |
button_press=true; |
- |
|
160 |
if(time_setup==TRUE) |
- |
|
161 |
{ |
150 |
sound_beep(100,600); |
162 |
sound_beep(100,600); |
151 |
if(integration_time < 0xfffa ) integration_time-=5; |
163 |
if(integration_time > 0x0005 ) integration_time-=5; |
152 |
|
164 |
|
153 |
set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka |
165 |
set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka |
154 |
time_overflow_count=0; |
166 |
time_overflow_count=0; |
155 |
set_timer1(0); |
167 |
set_timer1(0); |
156 |
overflow_count=0; |
168 |
overflow_count=0; |
- |
|
169 |
} |
157 |
} |
170 |
} |
158 |
} |
171 |
} |
159 |
|
172 |
|
160 |
if(!input(S3)) |
173 |
if(!input(S3)) |
161 |
{ |
174 |
{ |
162 |
delay_ms(20); |
175 |
delay_ms(20); |
163 |
if(!input(S3)) |
176 |
if(!input(S3)) |
164 |
{ |
177 |
{ |
165 |
button_press=true; |
178 |
button_press=true; |
- |
|
179 |
if(time_setup==TRUE) |
- |
|
180 |
{ |
166 |
sound_beep(100,500); |
181 |
sound_beep(100,500); |
167 |
if(integration_time < 0xffff ) integration_time++; |
182 |
if(integration_time < 0xffff ) integration_time++; |
- |
|
183 |
} |
168 |
} |
184 |
} |
169 |
} |
185 |
} |
170 |
|
186 |
|
171 |
if(!input(S4)) |
187 |
if(!input(S4)) |
172 |
{ |
188 |
{ |
173 |
delay_ms(20); |
189 |
delay_ms(20); |
174 |
if(!input(S4)) |
190 |
if(!input(S4)) |
175 |
{ |
191 |
{ |
176 |
button_press=true; |
192 |
button_press=true; |
- |
|
193 |
if(time_setup==TRUE) |
- |
|
194 |
{ |
177 |
sound_beep(100,400); |
195 |
sound_beep(100,400); |
178 |
if(integration_time < 0xffff ) integration_time--; |
196 |
if(integration_time > 0x0001 ) integration_time--; |
179 |
|
197 |
|
180 |
set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka |
198 |
set_timer0(0); // vynulovani pocitadel, kdyz uzivatel sahne na tlacitka |
181 |
time_overflow_count=0; |
199 |
time_overflow_count=0; |
182 |
set_timer1(0); |
200 |
set_timer1(0); |
183 |
overflow_count=0; |
201 |
overflow_count=0; |
- |
|
202 |
} |
- |
|
203 |
if(time_setup==TRUE) |
- |
|
204 |
{ |
- |
|
205 |
} |
- |
|
206 |
} |
- |
|
207 |
|
- |
|
208 |
if(!input(S5)) // prepnuti na nastavovani casu |
- |
|
209 |
{ |
- |
|
210 |
delay_ms(20); |
- |
|
211 |
if(!input(S5)) |
- |
|
212 |
{ |
- |
|
213 |
button_press=true; |
- |
|
214 |
sound_beep(100,800); |
- |
|
215 |
voltage_setup=FALSE; |
- |
|
216 |
time_setup=TRUE; |
- |
|
217 |
} |
- |
|
218 |
} |
- |
|
219 |
|
- |
|
220 |
if(!input(S6)) // prepnuti na nastavovani napeti |
- |
|
221 |
{ |
- |
|
222 |
delay_ms(20); |
- |
|
223 |
if(!input(S6)) |
- |
|
224 |
{ |
- |
|
225 |
button_press=true; |
- |
|
226 |
sound_beep(100,800); |
- |
|
227 |
voltage_setup=TRUE; |
- |
|
228 |
time_setup=FALSE; |
184 |
} |
229 |
} |
185 |
} |
230 |
} |
186 |
} |
231 |
} |
187 |
|
232 |
|
188 |
if ( input(S1) && input(S2) && input(S3) && input(S4) ) |
233 |
if ( input(S1) && input(S2) && input(S3) && input(S4) && input(S5) && input(S6)) // detekce pustenych tlacitek |
189 |
{ |
234 |
{ |
190 |
button_press=false; |
235 |
button_press=false; |
191 |
} |
236 |
} |
192 |
} |
237 |
} |
193 |
|
- |
|
194 |
} |
238 |
} |