Line 1... |
Line 1... |
1 |
#include ".\main.h" |
1 |
#include "main.h" |
2 |
|
2 |
|
3 |
// NEPOUZIVAT PINY B6 A B7, JSOU VYHRAZENY PRO SERIOVOU KOMUNIKACI |
3 |
// NEPOUZIVAT PINY B6 A B7, JSOU VYHRAZENY PRO SERIOVOU KOMUNIKACI |
4 |
// BAUD RATE = 9600 |
4 |
// BAUD RATE = 9600 |
5 |
|
5 |
|
6 |
// univerzalni LED diody |
6 |
// univerzalni LED diody |
Line 15... |
Line 15... |
15 |
#define SDIN PIN_D4 // seriovy vstup |
15 |
#define SDIN PIN_D4 // seriovy vstup |
16 |
#define SDOUT input(PIN_B2) // seriovy vystup |
16 |
#define SDOUT input(PIN_B2) // seriovy vystup |
17 |
#define SCLK PIN_D5 // takt |
17 |
#define SCLK PIN_D5 // takt |
18 |
|
18 |
|
19 |
// pro komunikaci s OLSA, prvni se posila LSB |
19 |
// pro komunikaci s OLSA, prvni se posila LSB |
20 |
int main_reset[8]={1,1,0,1,1,0,0,0}; // hlavni reset 0x1B |
20 |
int1 main_reset[8]={1,1,0,1,1,0,0,0}; // hlavni reset 0x1B |
21 |
int set_mode_rg[8]={1,1,1,1,1,0,1,0}; // zapis do MODE registru 0x5F |
21 |
int1 set_mode_rg[8]={1,1,1,1,1,0,1,0}; // zapis do MODE registru 0x5F |
22 |
int clear_mode_rg[8]={0,0,0,0,0,0,0,0}; // nulovani MODE registru 0x00 |
22 |
int1 clear_mode_rg[8]={0,0,0,0,0,0,0,0}; // nulovani MODE registru 0x00 |
23 |
|
23 |
|
24 |
int left_offset[8]={0,0,0,0,0,0,1,0}; // offset leveho segmentu senzoru 0x40 |
24 |
int1 left_offset[8]={0,0,0,0,0,0,1,0}; // offset leveho segmentu senzoru 0x40 |
25 |
int mid_offset[8]={0,1,0,0,0,0,1,0}; // offset prostredniho segmentu senzoru 0x42 |
25 |
int1 mid_offset[8]={0,1,0,0,0,0,1,0}; // offset prostredniho segmentu senzoru 0x42 |
26 |
int right_offset[8]={0,0,1,0,0,0,1,0}; // offset praveho segmentu senzoru 0x44 |
26 |
int1 right_offset[8]={0,0,1,0,0,0,1,0}; // offset praveho segmentu senzoru 0x44 |
27 |
int offset[8]={1,0,0,0,0,0,0,1}; // minus jedna - pouzit pro vsechny segmenty 0x81 |
27 |
int1 offset[8]={1,0,0,0,0,0,0,1}; // minus jedna - pouzit pro vsechny segmenty 0x81 |
28 |
|
28 |
|
29 |
int left_gain[8]={1,0,0,0,0,0,1,0}; // zisk leveho segmentu 0x41 |
29 |
int1 left_gain[8]={1,0,0,0,0,0,1,0}; // zisk leveho segmentu 0x41 |
30 |
int mid_gain[8]={1,1,0,0,0,0,1,0}; // zisk leveho segmentu 0x43 |
30 |
int1 mid_gain[8]={1,1,0,0,0,0,1,0}; // zisk leveho segmentu 0x43 |
31 |
int right_gain[8]={1,0,1,0,0,0,1,0}; // zisk leveho segmentu 0x45 |
31 |
int1 right_gain[8]={1,0,1,0,0,0,1,0}; // zisk leveho segmentu 0x45 |
32 |
int gain[8]={1,0,1,0,0,0,0,0}; // zisk = 5 - pouzit pro vsechny segmenty 0x5 |
32 |
int1 gain[8]={1,0,1,0,0,0,0,0}; // zisk = 5 - pouzit pro vsechny segmenty 0x5 |
33 |
|
33 |
|
34 |
int start_int[8]={0,0,0,1,0,0,0,0}; // zacatek integrace 0x08 |
34 |
int1 start_int[8]={0,0,0,1,0,0,0,0}; // zacatek integrace 0x08 |
35 |
int stop_int[8]={0,0,0,0,1,0,0,0}; // konec integrace 0x10 |
35 |
int1 stop_int[8]={0,0,0,0,1,0,0,0}; // konec integrace 0x10 |
36 |
int readout[8]={0,1,0,0,0,0,0,0}; // cteni senzoru 0x02 |
36 |
int1 readout[8]={0,1,0,0,0,0,0,0}; // cteni senzoru 0x02 |
37 |
|
37 |
|
38 |
int olsa_lseg[51]={0}; // leva cast radky (pixely 0 - 50) |
38 |
int8 olsa_lseg[51]={0}; // leva cast radky (pixely 0 - 50) |
39 |
int olsa_rseg[51]={0}; // prava cast radky (pixely 51 - 101) |
39 |
int8 olsa_rseg[51]={0}; // prava cast radky (pixely 51 - 101) |
40 |
int8 *line_lp=&olsa_lseg; // ukazatel na levou cast radky |
40 |
int8 *line_lp=&olsa_lseg; // ukazatel na levou cast radky |
41 |
int8 *line_rp=&olsa_rseg; // ukazatel na pravou cast radky |
41 |
int8 *line_rp=&olsa_rseg; // ukazatel na pravou cast radky |
42 |
int8 pixel; // dec hodnota jednoho pixelu |
42 |
int8 pixel; // dec hodnota jednoho pixelu |
43 |
int8 rpx; // pocet prectenych pixelu |
43 |
int8 rpx; // pocet prectenych pixelu |
44 |
int8 rbit; |
44 |
int8 rbit; |
Line 85... |
Line 85... |
85 |
output_high(SCLK); |
85 |
output_high(SCLK); |
86 |
delay_us(1); // doba pro ustaleni |
86 |
delay_us(1); // doba pro ustaleni |
87 |
output_low(SCLK); |
87 |
output_low(SCLK); |
88 |
} |
88 |
} |
89 |
|
89 |
|
90 |
void olsa_send(int info[]) // USART komunikace s modulem OLSA01A - poslani zpravy |
90 |
void olsa_send(int1 info[8]) // USART komunikace s modulem OLSA01A - poslani zpravy |
91 |
{ |
91 |
{ |
92 |
int8 *ip=&info; // ukazatel na pole s informaci |
92 |
int8 ip; // ukazatel na pole s informaci |
93 |
int i; // pomocna promenna pro nastaveni 0 nebo 1 na SDIN |
93 |
int1 i; // pomocna promenna pro nastaveni 0 nebo 1 na SDIN |
94 |
|
94 |
|
95 |
output_low(SDIN); // start bit |
95 |
output_low(SDIN); // start bit |
96 |
olsa_pulse(); |
96 |
olsa_pulse(); |
97 |
for(ip=0;ip<8;ip++) // predani informace - 8 bit, LSB prvni > MSB posledni |
97 |
for(ip=0;ip<8;ip++) // predani informace - 8 bit, LSB prvni > MSB posledni |
98 |
{ |
98 |
{ |
Line 146... |
Line 146... |
146 |
olsa_pulses(22); |
146 |
olsa_pulses(22); |
147 |
olsa_send(stop_int); // konec integrace senzoru |
147 |
olsa_send(stop_int); // konec integrace senzoru |
148 |
olsa_pulses(5); |
148 |
olsa_pulses(5); |
149 |
} |
149 |
} |
150 |
|
150 |
|
- |
|
151 |
int1 bity[8] = { 0, 1, 1, 1, 0, 0, 1, 0 }; |
- |
|
152 |
int8 bajt; |
- |
|
153 |
|
- |
|
154 |
void bit_to_bajt() |
- |
|
155 |
{ |
- |
|
156 |
int i; |
- |
|
157 |
|
- |
|
158 |
bajt = 0; |
- |
|
159 |
for (i = 0; i < 8; i++) |
- |
|
160 |
bajt |= bity[i] << i; |
- |
|
161 |
|
- |
|
162 |
printf("bajt: %x\n", bajt); |
- |
|
163 |
} |
- |
|
164 |
|
151 |
void olsa_bit_save() // ukladani jednotlivych bitu pixelu |
165 |
void olsa_bit_save() // ukladani jednotlivych bitu pixelu |
152 |
{ |
166 |
{ |
153 |
t_bit_save: |
167 |
t_bit_save: |
154 |
if(SDOUT==0) // zacatek prenosu |
168 |
if(SDOUT==0) // zacatek prenosu |
155 |
{ |
169 |
{ |
Line 281... |
Line 295... |
281 |
|
295 |
|
282 |
void motor_test() // test motoru |
296 |
void motor_test() // test motoru |
283 |
{ |
297 |
{ |
284 |
int8 i; |
298 |
int8 i; |
285 |
beep(100,200); |
299 |
beep(100,200); |
286 |
printf("TEST MOTORU\n"); |
300 |
printf("TEST MOTORU\r\n"); |
287 |
delay_ms(1000); |
301 |
delay_ms(1000); |
288 |
printf("LEVY MOTOR DOPREDU\n"); |
302 |
printf("LEVY MOTOR DOPREDU\r\n"); |
289 |
for(i=0;i<255;i++) |
303 |
for(i=0;i<255;i++) |
290 |
{ |
304 |
{ |
291 |
l_motor_fwd(i); |
305 |
l_motor_fwd(i); |
292 |
printf("RYCHLOST: %u\n",i); |
306 |
printf("RYCHLOST: %u\r\n",i); |
293 |
delay_ms(5); |
307 |
delay_ms(5); |
294 |
} |
308 |
} |
295 |
for(i=255;i>0;i--) |
309 |
for(i=255;i>0;i--) |
296 |
{ |
310 |
{ |
297 |
l_motor_fwd(i); |
311 |
l_motor_fwd(i); |
298 |
printf("RYCHLOST: %u\n",i); |
312 |
printf("RYCHLOST: %u\r\n",i); |
299 |
delay_ms(5); |
313 |
delay_ms(5); |
300 |
} |
314 |
} |
301 |
printf("LEVY MOTOR DOZADU\n"); |
315 |
printf("LEVY MOTOR DOZADU\r\n"); |
302 |
for(i=0;i<255;i++) |
316 |
for(i=0;i<255;i++) |
303 |
{ |
317 |
{ |
304 |
l_motor_bwd(i); |
318 |
l_motor_bwd(i); |
305 |
printf("RYCHLOST: %u\n",i); |
319 |
printf("RYCHLOST: %u\r\n",i); |
306 |
delay_ms(5); |
320 |
delay_ms(5); |
307 |
} |
321 |
} |
308 |
for(i=255;i>0;i--) |
322 |
for(i=255;i>0;i--) |
309 |
{ |
323 |
{ |
310 |
l_motor_bwd(i); |
324 |
l_motor_bwd(i); |
311 |
printf("RYCHLOST: %u\n",i); |
325 |
printf("RYCHLOST: %u\r\n",i); |
312 |
delay_ms(5); |
326 |
delay_ms(5); |
313 |
} |
327 |
} |
314 |
printf("PRAVY MOTOR DOPREDU\n"); |
328 |
printf("PRAVY MOTOR DOPREDU\r\n"); |
315 |
for(i=0;i<255;i++) |
329 |
for(i=0;i<255;i++) |
316 |
{ |
330 |
{ |
317 |
r_motor_fwd(i); |
331 |
r_motor_fwd(i); |
318 |
printf("RYCHLOST: %u\n",i); |
332 |
printf("RYCHLOST: %u\r\n",i); |
319 |
delay_ms(5); |
333 |
delay_ms(5); |
320 |
} |
334 |
} |
321 |
for(i=255;i>0;i--) |
335 |
for(i=255;i>0;i--) |
322 |
{ |
336 |
{ |
323 |
r_motor_fwd(i); |
337 |
r_motor_fwd(i); |
324 |
printf("RYCHLOST: %u\n",i); |
338 |
printf("RYCHLOST: %u\r\n",i); |
325 |
delay_ms(5); |
339 |
delay_ms(5); |
326 |
} |
340 |
} |
327 |
printf("PRAVY MOTOR DOZADU\n"); |
341 |
printf("PRAVY MOTOR DOZADU\r\n"); |
328 |
for(i=0;i<255;i++) |
342 |
for(i=0;i<255;i++) |
329 |
{ |
343 |
{ |
330 |
r_motor_bwd(i); |
344 |
r_motor_bwd(i); |
331 |
printf("RYCHLOST: %u\n",i); |
345 |
printf("RYCHLOST: %u\r\n",i); |
332 |
delay_ms(5); |
346 |
delay_ms(5); |
333 |
} |
347 |
} |
334 |
for(i=255;i>0;i--) |
348 |
for(i=255;i>0;i--) |
335 |
{ |
349 |
{ |
336 |
r_motor_bwd(i); |
350 |
r_motor_bwd(i); |
337 |
printf("RYCHLOST: %u\n",i); |
351 |
printf("RYCHLOST: %u\r\n",i); |
338 |
delay_ms(5); |
352 |
delay_ms(5); |
339 |
} |
353 |
} |
340 |
printf("KONEC TESTU MOTORU \N"); |
354 |
printf("KONEC TESTU MOTORU\r\n"); |
341 |
} |
355 |
} |
342 |
|
356 |
|
343 |
void diagnostika() // diagnostika - vypis senzoru s moznosti prepnuti na test motoru |
357 |
void diagnostika() // diagnostika - vypis senzoru s moznosti prepnuti na test motoru |
344 |
{ |
358 |
{ |
345 |
read_blue_sensors(); |
359 |
read_blue_sensors(); |
Line 347... |
Line 361... |
347 |
delay_ms(10); |
361 |
delay_ms(10); |
348 |
printf("PRAVA: %u \t",line_r); |
362 |
printf("PRAVA: %u \t",line_r); |
349 |
delay_ms(10); |
363 |
delay_ms(10); |
350 |
printf("L_NARAZ: %u \t",BUMPL); |
364 |
printf("L_NARAZ: %u \t",BUMPL); |
351 |
delay_ms(10); |
365 |
delay_ms(10); |
352 |
printf("P_NARAZ: %u \n",BUMPR); |
366 |
printf("P_NARAZ: %u \r\n",BUMPR); |
353 |
delay_ms(10); |
367 |
delay_ms(10); |
354 |
if(BUMPL&&BUMPR) // po zmacknuti stran narazniku spusti test motoru |
368 |
if(BUMPL&&BUMPR) // po zmacknuti stran narazniku spusti test motoru |
355 |
{ |
369 |
{ |
356 |
motor_test(); |
370 |
motor_test(); |
357 |
} |
371 |
} |
Line 359... |
Line 373... |
359 |
|
373 |
|
360 |
// HLAVNI SMYCKA |
374 |
// HLAVNI SMYCKA |
361 |
void main() |
375 |
void main() |
362 |
{ |
376 |
{ |
363 |
|
377 |
|
364 |
printf("POWER ON \n"); |
378 |
printf("POWER ON \r\n"); |
365 |
// NASTAVENI > provede se pouze pri zapnuti |
379 |
// NASTAVENI > provede se pouze pri zapnuti |
366 |
setup_adc_ports(sAN0-sAN1-sAN2); |
380 |
setup_adc_ports(sAN0-sAN1-sAN2); |
367 |
setup_adc(ADC_CLOCK_INTERNAL); // interni hodniny pro AD prevodnik |
381 |
setup_adc(ADC_CLOCK_INTERNAL); // interni hodniny pro AD prevodnik |
368 |
setup_spi(SPI_SS_DISABLED); |
382 |
setup_spi(SPI_SS_DISABLED); |
369 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
383 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
Line 378... |
Line 392... |
378 |
olsa_reset(); // reset logiky radkoveho senzoru |
392 |
olsa_reset(); // reset logiky radkoveho senzoru |
379 |
olsa_setup(); // nastaveni segmentu radkoveho senzoru (offset a zisk) |
393 |
olsa_setup(); // nastaveni segmentu radkoveho senzoru (offset a zisk) |
380 |
output_high(LED1); // zhasne LED1 |
394 |
output_high(LED1); // zhasne LED1 |
381 |
output_high(LED2); // zhasne LED2 |
395 |
output_high(LED2); // zhasne LED2 |
382 |
beep(500,200); // pipni pri startu |
396 |
beep(500,200); // pipni pri startu |
383 |
printf("OK! \n"); |
397 |
printf("OK! \r\n"); |
384 |
delay_ms(500); |
398 |
delay_ms(500); |
385 |
printf("VYBRAT MOD... \n"); |
399 |
printf("VYBRAT MOD... \r\n"); |
386 |
|
400 |
|
387 |
while(true) |
401 |
while(true) |
388 |
{ |
402 |
{ |
- |
|
403 |
diagnostika(); |
389 |
} |
404 |
} |
390 |
} |
405 |
} |