|
|
|
LEDの点滅をOffにする
|
MLAのデモソフトを使うと、Lチカになるピンが出ます。それを消すために、"app_led_usb_status.c"のLED_On(LED_USB_DEVICE_STATE)
LED_Off(LED_USB_DEVICE_STATE)
を全部コメントアウトしました。でも点滅は止まらず、"leds.c"の
void LED_Toggle(LED led)
bool LED_Get(LED led)
void LED_Enable(LED led)
の中身を全部コメントアウトしてみたら止まりました。
これをしないとサーボモーターが変に動くのです。 |
|
|
USB-PICが受け取る文字と実行されるもの
|
基本的な動作は下記の文字で操作します。
A: PIC3に60秒間隔で撮像開始(全景画像用)
B: PIC2に10秒間隔で撮像開始(クライマックスC2前、C3後)
C: PIC2に1.5秒間隔で撮像開始(ダイヤモンドリングとコロナ)
D: PIC1に撮像開始(偏光撮像)
E: D7200で1/500秒で15秒間連写し1/8000秒にSSを増速
F: D7200で1/8000秒から1/500秒にSSを減速し15秒間連写
G: D7200で1/8000秒から1/2秒迄2EV間隔7段の多段階撮像
H: D7200で1/2秒から1/8000秒迄2EV間隔7段の多段階撮像
I : 太陽フィルター×3開
J: 太陽フィルター×3閉
K: D7200のSSを1/2秒から1/8000秒まで増速
他にサポートするコンポーネントとして
撮像サブルーチン
増速サブルーチン
減速サブルーチン
緊急時のためのファームはE, F, G, H, Kを基本にしてシャッターを切った後の遅延を調整したものを作ります。 |
void PIC3Start()
void PIC2_Int()
void PIC2_Cont()
void PIC1_Start()
void USB_PIC_Cont_1st()
void USB_PIC_Cont_2nd()
void USB_PIC_BKT_Down()
void USB_PIC_BKT_Up()
void Filter_Open()
void Filter_Close(
void SS_UpTo_8000()
void Captor()
void SpeedUp()
void SpeedDown() |
|
|
下記は「app_device_cdc_basic.c」の中身・ダウンロードはこちらから |
USB-PICに書き込むファームウェア |
1 /*******************************************************************************
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 @microchip
18
19
20
21
22
23 #include "system.h"
24
25 #include <stdint.h>
26 #include <string.h>
27 #include <stddef.h>
28
29 #include "usb.h"
30
31 #include "app_led_usb_status.h"
32 #include "app_device_cdc_basic.h"
33 #include "usb_config.h"
34
35 #define _XTAL_FREQ 48000000
36
37
38
39
40 \r\n
41 static uint8_t readBuffer[CDC_DATA_OUT_EP_SIZE];
42 static uint8_t writeBuffer[CDC_DATA_IN_EP_SIZE];
43
44 void PIC3Start();
45 void PIC2_Int();
46 void PIC2_Cont();
47 void PIC1_Start();
48 void USB_PIC_Cont_1st();
49 void USB_PIC_Cont_2nd();
50 void USB_PIC_BKT_Down();
51 void USB_PIC_BKT_Up();
52 void Filter_Open();
53 void Filter_Close();
54 void SS_UpTo_8000();
55 void Captor();
56 void SpeedUp();
57 void SpeedDown();
58
59 void USB_PIC_Cont_1st2();
60 void USB_PIC_Cont_2nd2();
61 void USB_PIC_BKT_Down2();
62 void USB_PIC_BKT_Up2();
63
64
65
66
67
68
69
70
71
72
73
74
75 void APP_DeviceCDCBasicDemoInitialize()
76 {
77 line_coding.bCharFormat = 0;
78 line_coding.bDataBits = 8;
79 line_coding.bParityType = 0;
80 line_coding.dwDTERate = 9600;
81
82
83 }
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99 void APP_DeviceCDCBasicDemoTasks()
100 {
101 TRISB = 0b00000000;
102 TRISC = 0b00000000;
103 PORTB = 0b00000000;
104 PORTC = 0b00000000;
105
106
107 char Commander;
108 int i;
109 RA3 = 1;
110
111
112
113 if( USBGetDeviceState() < CONFIGURED_STATE )
114 {
115 return;
116 }
117
118
119
120
121
122 if( USBIsDeviceSuspended()== true )
123 {
124 return;
125 }
126
127
128
129
130 if(BUTTON_IsPressed(BUTTON_DEVICE_CDC_BASIC_DEMO) == true)
131 {
132
133
134
135
136 {
137
138
139 if(mUSBUSARTIsTxTrfReady() == true)
140 {
141
142
143 }
144 }
145 }
146 else
147 {
148
149
150
151
152 }
153
154
155
156
157 if( USBUSARTIsTxTrfReady() == true)
158 {
159 uint8_t i;
160 uint8_t numBytesRead;
161
162 numBytesRead = getsUSBUSART(readBuffer, sizeof(readBuffer));
163
164
165 for(i=0; i<numBytesRead; i++)
166 {
167 switch(readBuffer[i])
168 {
169
170
171
172 case 0x0A:
173 case 0x0D:
174
175
176
177
178
179
180
181
182 default:
183 writeBuffer[i] = readBuffer[i];
184
185
186
187
188 Commander = readBuffer[0];
189
190 if(Commander=='A')
191 {
192 PIC3Start();
193
194
195 }
196 elseif(Commander=='B')
197 {
198 PIC2_Int();
199
200
201 }
202 elseif(Commander=='C')
203 {
204 PIC2_Cont();
205
206
207 }
208 elseif(Commander == 'D')
209 {
210 PIC1_Start();
211 }
212 elseif(Commander=='E')
213 {
214 USB_PIC_Cont_1st();
215
216
217 }
218 elseif(Commander=='F')
219 {
220 USB_PIC_Cont_2nd();
221
222
223 }
224 elseif(Commander=='G')
225 {
226 USB_PIC_BKT_Down();
227
228
229 }
230 elseif(Commander=='H')
231 {
232 USB_PIC_BKT_Up();
233
234
235 }
236 elseif(Commander=='I')
237 {
238 Filter_Open();
239 }
240 elseif(Commander=='J')
241 {
242 Filter_Close();
243 }
244 elseif(Commander=='K')
245 {
246 SS_UpTo_8000();
247
248
249 }
250 break;
251 }
252 if(numBytesRead > 0)
253 {
254
255
256
257 putUSBUSART(writeBuffer,numBytesRead);
258 }
259
260
261 }
262 }
263 if(RA3 == 0) //緊急時処理(仮)
264 {
265 PIC2_Int();
266 for(i=1; i<=2; i++)
267 {
268 __delay_ms(1000);
269 }
270 Filter_Open();
271 PIC2_Cont();
272 USB_PIC_Cont_1st2();
273 PIC1_Start();
274 for(i=1; i<=7; i++)
275 {
276 USB_PIC_BKT_Down2();
277 USB_PIC_BKT_Up2();
278 }
279 USB_PIC_Cont_2nd2();
280 Filter_Close();
281 PIC2_Int();
282
283 }
284 CDCTxService();
285 }
286
287 void PIC3Start()
288 {
289 int i;
290 LATCbits.LATC5 = 0;
291 LATCbits.LATC6 = 0;
292 __delay_ms(10);
293 LATCbits.LATC5 = 1;
294 for(i=1; i<=13; i++)
295 {
296 __delay_ms(100);
297 }
298 LATCbits.LATC5 = 0;
299 }
300
301 void PIC2_Int()
302 {
303 int i;
304 LATCbits.LATC3 = 0;
305 LATCbits.LATC4 = 0;
306 __delay_ms(10);
307 LATCbits.LATC3 = 1;
308 for(i=1; i<=13; i++)
309 {
310 __delay_ms(100);
311 }
312 LATCbits.LATC3 = 0;
313
314 return;
315 }
316
317 void PIC2_Cont()
318 {
319 int i;
320 LATCbits.LATC3 = 0;
321 LATCbits.LATC4 = 0;
322 __delay_ms(10);
323 LATCbits.LATC4 = 1;
324 for(i=1; i<=13; i++)
325 {
326 __delay_ms(100);
327 }
328 LATCbits.LATC4 = 0;
329
330 return;
331 }
332
333 void PIC1_Start()
334 {
335 LATCbits.LATC7=0;
336
337 LATCbits.LATC7=1;
338 __delay_ms(50);
339 LATCbits.LATC7=0;
340
341 return;
342 }
343
344 void USB_PIC_Cont_1st()
345 {
346 int i;
347
348 LATBbits.LATB6=0;
349 LATBbits.LATB7=0;
350 __delay_ms(20);
351 LATBbits.LATB6 = 1;
352 __delay_ms(20);
353 LATBbits.LATB7 = 1;
354 for(i=1; i<=150;i++)
355 {
356 __delay_ms(100);
357 }
358 LATBbits.LATB7 = 0;
359 __delay_ms(20);
360 LATBbits.LATB6 = 0;
361 __delay_ms(20);
362 SpeedUp();
363 SpeedUp();
364
365 return;
366 }
367
368 void USB_PIC_Cont_2nd()
369 {
370 int i;
371
372 SpeedDown();
373 SpeedDown();
374
375 LATBbits.LATB6=0;
376 LATBbits.LATB7=0;
377 __delay_ms(20);
378 LATBbits.LATB6 = 1;
379 __delay_ms(20);
380 LATBbits.LATB7 = 1;
381 for(i=1; i<=150;i++)
382 {
383 __delay_ms(100);
384 }
385 LATBbits.LATB7 = 0;
386 __delay_ms(20);
387 LATBbits.LATB6 = 0;
388 __delay_ms(20);
389 return;
390 }
391
392 void USB_PIC_BKT_Down()
393 {
394 int i;
395
396 for(i=1 ;i<=2 ; i++)
397 {
398 Captor();
399 __delay_ms(800);
400 SpeedDown();
401 __delay_ms(30);
402
403 }
404 for(i=1 ;i<=2 ; i++)
405 {
406 Captor();
407 __delay_ms(950);
408 SpeedDown();
409 __delay_ms(30);
410 }
411 for(i=1 ;i<=2 ; i++)
412 {
413 Captor();
414 __delay_ms(950);
415 SpeedDown();
416 __delay_ms(30);
417 }
418 Captor();
419 __delay_ms(1000);
420
421 return;
422 }
423
424 void USB_PIC_BKT_Up()
425 {
426 int i;
427
428 Captor();
429 __delay_ms(950);
430 for(i=1 ;i<=2 ; i++)
431 {
432 SpeedUp();
433 __delay_ms(30);
434 Captor();
435 __delay_ms(950);
436 }
437 for(i=1 ;i<=2 ; i++)
438 {
439 SpeedUp();
440 __delay_ms(30);
441 Captor();
442 __delay_ms(950);
443
444 }
445 for(i=1 ;i<=2 ; i++)
446 {
447 SpeedUp();
448 __delay_ms(30);
449 Captor();
450 __delay_ms(800);
451 }
452 SpeedUp();
453 __delay_ms(100);
454 return;
455 }
456
457 void Filter_Open()
458 {
459 int k, b;
460
461 for(k=0; k<20; k++)
462 {
463 LATCbits.LATC2 = 1;
464 {
465 __delay_us(1500);
466 }
467 LATCbits.LATC2 = 0;
468 for(b=1; b<=37; b++)
469 {
470 __delay_us(500);
471 }
472 }
473 __delay_ms(200);
474 for(k=0; k<20; k++)
475 {
476 LATCbits.LATC1 = 1;
477 {
478 __delay_us(1500);
479 }
480 LATCbits.LATC1 = 0;
481 for(b=1; b<=37; b++)
482 {
483 __delay_us(500);
484 }
485 }
486 __delay_ms(200);
487 for(k=0; k<20; k++)
488 {
489 LATCbits.LATC0 = 1;
490 {
491 __delay_us(1500);
492 }
493 LATCbits.LATC0 = 0;
494 for(b=1; b<=37; b++)
495 {
496 __delay_us(500);
497 }
498 }
499 __delay_ms(200);
500
501 return;
502 }
503
504 void Filter_Close()
505 {
506 int k, b;
507
508 for(k=0; k<25; k++)
509 {
510 LATCbits.LATC2 = 1;
511 {
512 __delay_us(100);
513 }
514 LATCbits.LATC2 = 0;
515 __delay_us(400);
516 for(b=1; b<=39; b++)
517 {
518 __delay_us(500);
519 }
520 }
521 __delay_ms(200);
522 for(k=0; k<25; k++)
523 {
524 LATCbits.LATC1 = 1;
525 {
526 __delay_us(100);
527 }
528 LATCbits.LATC1 = 0;
529 __delay_us(400);
530 for(b=1; b<=39; b++)
531 {
532 __delay_us(500);
533 }
534 }
535 __delay_ms(200);
536 for(k=0; k<25; k++)
537 {
538 LATCbits.LATC0 = 1;
539 {
540 __delay_us(100);
541 }
542 LATCbits.LATC0 = 0;
543 __delay_us(400);
544 for(b=1; b<=39; b++)
545 {
546 __delay_us(500);
547 }
548 }
549 __delay_ms(200);
550
551 return;
552 }
553
554 void SS_UpTo_8000()
555 {
556 int i;
557
558 for(i=1; i<=7; i++)
559 {
560 SpeedUp();
561 }
562
563 return;
564 }
565
566 void SS_Down_To_500()
567 {
568 int i;
569
570 for(i=1; i<=2; i++)
571 {
572 SpeedDown();
573 }
574
575 return;
576 }
577
578 void Captor()
579 {
580 LATBbits.LATB6=0;
581 LATBbits.LATB7=0;
582
583 LATBbits.LATB6 = 1;
584 __delay_ms(20);
585 LATBbits.LATB7 = 1;
586 __delay_ms(40);
587 LATBbits.LATB7 = 0;
588 __delay_ms(20);
589 LATBbits.LATB6 = 0;
590 __delay_ms(20);
591
592 return;
593 }
594
595 void SpeedDown()
596 {
597 int i;
598
599 LATBbits.LATB4 = 0;
600 LATBbits.LATB5 = 0;
601
602 for(i=1; i<=4; i++)
603 {
604 LATBbits.LATB4=1;
605 __delay_ms(25);
606 LATBbits.LATB5=1;
607 __delay_ms(25);
608 LATBbits.LATB4=0;
609 __delay_ms(25);
610 LATBbits.LATB5=0;
611 __delay_ms(25);
612 }
613
614 return;
615 }
616
617 void SpeedUp()
618 {
619 int i;
620
621 LATBbits.LATB4 = 0;
622 LATBbits.LATB5 = 0;
623
624 for(i=1; i<=4; i++)
625 {
626 LATBbits.LATB5=1;
627 __delay_ms(25);
628 LATBbits.LATB4=1;
629 __delay_ms(25);
630 LATBbits.LATB5=0;
631 __delay_ms(25);
632 LATBbits.LATB4=0;
633 __delay_ms(25);
634 }
635
636 return;
637 }
638 void USB_PIC_BKT_Down2()
639 {
640 int i;
641
642 Captor();
643 __delay_ms(800);
644 SpeedDown();
645 __delay_ms(30);
646
647 for(i=1 ;i<=5 ; i++)
648 {
649 Captor();
650 __delay_ms(950);
651 SpeedDown();
652 __delay_ms(30);
653 }
654 SpeedDown();
655 __delay_ms(30);
656 Captor();
657 __delay_ms(2400);
658
659 return;
660 }
661
662 void USB_PIC_BKT_Up2()
663 {
664 int i;
665
666 Captor();
667 __delay_ms(2400);
668
669 for(i=1 ;i<=5 ; i++)
670 {
671 SpeedUp();
672 __delay_ms(30);
673 Captor();
674 __delay_ms(950);
675 }
676
677 SpeedUp();
678 __delay_ms(30);
679 Captor();
680 __delay_ms(800);
681
682
683
684 return;
685 }
686 void USB_PIC_Cont_1st2()
687 {
688 int i;
689
690 LATBbits.LATB6=0;
691 LATBbits.LATB7=0;
692 __delay_ms(20);
693 LATBbits.LATB6 = 1;
694 __delay_ms(20);
695 LATBbits.LATB7 = 1;
696 for(i=1; i<=15;i++)
697 {
698 __delay_ms(1000);
699 }
700 LATBbits.LATB7 = 0;
701 __delay_ms(20);
702 LATBbits.LATB6 = 0;
703 __delay_ms(20);
704
705 return;
706 }
707
708 void USB_PIC_Cont_2nd2()
709 {
710 int i;
711
712 SpeedDown();
713
714 LATBbits.LATB6=0;
715 LATBbits.LATB7=0;
716 __delay_ms(20);
717 LATBbits.LATB6 = 1;
718 __delay_ms(20);
719 LATBbits.LATB7 = 1;
720 for(i=1; i<=15;i++)
721 {
722 __delay_ms(1000);
723 }
724 LATBbits.LATB7 = 0;
725 __delay_ms(20);
726 LATBbits.LATB6 = 0;
727 __delay_ms(20);
728 return;
729 }
730
|