日食撮像システム 2019年 Ver.
USB-PIC:ファームウェア3歩目
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」の中身・ダウンロードはこちらからD.L.
USB-PICに書き込むファームウェア
   1 /*******************************************************************************
  2   Copyright 2016 MicrochipTechnologyInc. (www.microchip.com)
  3 
  4     LicensedundertheApacheLicense, Version 2.0 (the "License");
  5            youmaynotusethisfileexceptincompliancewiththeLicense.
  6         YoumayobtainacopyoftheLicenseat
  7 
  8     http://www.apache.org/licenses/LICENSE-2.0
  9 
 10          Unlessrequiredbyapplicablelaworagreedtoinwriting, software
 11         distributedundertheLicenseisdistributedonan "ASIS" BASIS,
 12          WITHOUTWARRANTIESORCONDITIONSOFANYKIND, eitherexpressorimplied.
 13          SeetheLicenseforthespecificlanguagegoverningpermissionsand
 14    limitationsundertheLicense.
 15 
 16          TorequesttolicensethecodeundertheMLAlicense (www.microchip.com/mla_license), 
 17   pleasecontactmla_licensing@microchip.com
 18  * 
 19     FirmwarehasmodifiedbyM_shi_Lab
 20 *******************************************************************************/
 21 
 22  /**INCLUDES *******************************************************/
 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  /**VARIABLES ******************************************************/
 38 
 39   //staticboolbuttonPressed;
 40    //staticcharbuttonMessage[] = "Buttonpressed.\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();           //A
 45 void PIC2_Int();            //B
 46 void PIC2_Cont();           //C
 47 void PIC1_Start();          //D
 48 void USB_PIC_Cont_1st();   //E
 49 void USB_PIC_Cont_2nd();   //F
 50 void USB_PIC_BKT_Down();   //G
 51 void USB_PIC_BKT_Up();     //H
 52 void Filter_Open();        //I
 53 void Filter_Close();       //J
 54 void SS_UpTo_8000();       //K
 55 void Captor();
 56 void SpeedUp();
 57 void SpeedDown();
 58 //Emmergency
 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  * Function: voidAPP_DeviceCDCBasicDemoInitialize(void);
 65 *
 66    * Overview: Initializesthedemocode
 67 *
 68 * PreCondition: None
 69 *
 70 * Input: None
 71 *
 72 * Output: None
 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     //buttonPressed = false;
 83 }
 84 
 85 /*********************************************************************
 86  * Function: voidAPP_DeviceCDCBasicDemoTasks(void);
 87 *
 88    * Overview: Keepsthedemorunning.
 89 *
 90         * PreCondition: Thedemoshouldhavebeeninitializedandstartedvia
 91   * theAPP_DeviceCDCBasicDemoInitialize() andAPP_DeviceCDCBasicDemoStart() demos
 92 * respectively.
 93 *
 94 * Input: None
 95 *
 96 * Output: None
 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                /*IftheUSBdeviceisn'tconfiguredyet, wecan'treallydoanything
111                     * elsesincewedon'thaveahosttotalkto.Sojumpbacktothe
112           * topofthewhileloop.*/
113     if( USBGetDeviceState() < CONFIGURED_STATE )
114     {
115         return;
116     }
117 
118                  /*Ifwearecurrentlysuspended, thenweneedtoseeifweneedto
119                * issuearemotewakeup.Ineithercase, weshouldn'tprocessany
120               * keyboardcommandssincewearen'tcurrentlycommunicatingtothehost
121                 * thusjustcontinuebacktothestartofthewhileloop.*/
122     if( USBIsDeviceSuspended()== true )
123     {
124         return;
125     }
126         
127                 /*Iftheuserhaspressedthebuttonassociatedwiththisdemo, thenwe
128              * aregoingtosenda "ButtonPressed" messagetotheterminal.
129      */
130     if(BUTTON_IsPressed(BUTTON_DEVICE_CDC_BASIC_DEMO) == true)
131     {
132                      /*Makesurethatweonlysendthemessageonceperbuttonpressand
133                * notcontinuouslyasthebuttonisheld.
134          */
135         //if(buttonPressed == false)
136         {
137                        /*MakesurethattheCDCdriverisreadyforatransmission.
138              */
139             if(mUSBUSARTIsTxTrfReady() == true)
140             {
141                 //putrsUSBUSART(buttonMessage);
142                 //buttonPressed = true;
143             }
144         }
145     }
146     else
147     {
148                      /*Ifthebuttonisreleased, wecanthenallowanewmessagetobe
149                 * sentthenexttimethebuttonispressed.
150          */
151         //buttonPressed = false;
152     }
153 
154                 /*Checktoseeifthereisatransmissioninprogress, ifthereisn't, then
155                * wecanseeaboutperforminganechoresponsetodatareceived.
156      */
157     if( USBUSARTIsTxTrfReady() == true)
158     {
159         uint8_t i;
160         uint8_t numBytesRead;
161 
162         numBytesRead = getsUSBUSART(readBuffer, sizeof(readBuffer));
163 
164                /*Foreverybytethatwasread...*/
165         for(i=0; i<numBytesRead; i++)
166         {
167             switch(readBuffer[i])
168             {
169                           /*Ifwereceivenewlineorlinefeedcommands, justecho
170                   * themdirect.
171                  */
172                 case 0x0A:
173                 case 0x0D:
174                     //writeBuffer[i] = readBuffer[i];
175                     //break;
176 
177                          /*Ifwereceivesomethingelse, thenechoitplusone
178                         * sothatifwereceive 'a', weecho 'b' sothatthe
179                           * userknowsthatitisn'ttheechoenabledontheir
180                   * terminalprogram.
181                  */
182                 default:
183                     writeBuffer[i] = readBuffer[i];
184                 //break;
185             
186             //default:
187             
188                 Commander = readBuffer[0];
189 
190                 if(Commander=='A')
191                 {
192                     PIC3Start();
193                     //numBytesRead = 10;
194                     //writeBuffer[10]=('A','5','0','0','0',' ','S','t','a','r','t'); 
195                 }
196                  elseif(Commander=='B')
197                 {
198                     PIC2_Int();
199                     //numBytesRead = 13;
200                     //writeBuffer[13]=('I','n','t',' ','S','t','a','r','t');
201                 }
202                   elseif(Commander=='C')
203                 {
204                     PIC2_Cont();
205                     //numBytesRead = 14;
206                     //writeBuffer[14]=('C','o','n','t',' ','S','t','a','r','t');
207                 }
208                  elseif(Commander == 'D')
209                 {
210                     PIC1_Start();
211                 }
212                  elseif(Commander=='E')
213                 {
214                     USB_PIC_Cont_1st();
215                     //numBytesRead = 8;
216                     //writeBuffer[8]=('D','.','L','.',' ','E','N','D');
217                 }
218                  elseif(Commander=='F')
219                 {
220                     USB_PIC_Cont_2nd();
221                     //numBytesRead = 8;
222                     //writeBuffer[8]=('D','.','L','.',' ','E','N','D');
223                 }
224                  elseif(Commander=='G')
225                 {
226                     USB_PIC_BKT_Down();
227                     //numBytesRead = 12;
228                     //writeBuffer[12]=('B','K','T',' ','D','o','w','n',' ','E','N','D');
229                 }
230                   elseif(Commander=='H')
231                 {
232                     USB_PIC_BKT_Up();
233                     //numBytesRead = 10;
234                     //writeBuffer[10]=('B','K','T',' ','U','p',' ','E','N','D');
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                      //numBytesRead = 9;
248                      //writeBuffer[9]=('S','S','=','1','/','8','0','0','0');
249                 }
250                 break;
251             }
252             if(numBytesRead > 0)
253             {
254                            /*Afterprocessingallofthereceiveddata, weneedtosendout
255                   * the "echo" datanow.
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     //SpeedUp();
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     SpeedUp();
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 

        
inserted by FC2 system