goo blog サービス終了のお知らせ 

Ganponブログ

趣味の模型作り、ドライブ、旅行など
since Mar.2017

1/350 バンダイ ミレニアムファルコン 製作(その3)

2023-11-13 13:49:10 | STAR WARS
2023-11-13
▼LED制御回路をPICで作成します。

▼ヘッドライトとコックピットの発光はPIC12F1822出力でなくても良いのですが、
後にプログラムでコントロールできるようにしておきます。
▼ソースファイルです。

  1. /*
  2.  * File: main.c
  3.  * エンジン発光 LED高速明滅 3LED。 連続点灯 2LED。
  4.  * PIC12F1822
  5.  * Author:
  6.  * Created on 2023/09/05, 13:25
  7.  */
  8.  
  9. // CONFIG1
  10. #pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
  11. #pragma config WDTE = OFF // Watchdog Timer Enable (WDT enabled)
  12. #pragma config PWRTE = ON // Power-up Timer Enable (PWRT disabled)
  13. #pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
  14. #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
  15. #pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
  16. #pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset enabled)
  17. #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
  18. #pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is enabled)
  19. #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
  20.  
  21. // CONFIG2
  22. #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
  23. #pragma config PLLEN = OFF // PLL Enable (4x PLL enabled)
  24. #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
  25. #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
  26. #pragma config LVP = OFF // Low-Voltage Programming Enable (Low-voltage programming enabled)
  27.  
  28. #include <xc.h>
  29. #define _XTAL_FREQ 8000000
  30.  
  31. void main(void) {
  32.  
  33.     OSCCON = 0b01110010; //内部クロック8MHz 4MHz 0b01101010
  34.     ANSELA = 0b00000000; //アナログは使用しない(すべてデジタルI/Oに割り当てる)
  35.     TRISA = 0b00001000; //RA3だけ入力その他のピンは出力に割当てる(RA3は入力専用)
  36.     PORTA = 0; //出力ピンの初期化(全てLOWにする)
  37.    
  38. //------------変数の宣言------------
  39. //ED明滅のための変数
  40. char zentime = 65;
  41. char ontime = 20;
  42. char ima = 1;
  43. char fugou =2;
  44.  
  45.  while(1){
  46.  
  47.  //明滅 RA0、RA1、RA2。 連続点灯 RA4、RA5
  48.       if(ima < ontime){
  49.          PORTA = 0b00110111;
  50.          }
  51.       else{
  52.          PORTA = 0b00110000;
  53.          }
  54.  
  55. //明滅ロジック
  56.  ima++;
  57.  if(ima > zentime){
  58.      ima = 1;
  59.      ontime = ontime + fugou; //点灯している時間を徐々に増減
  60.      if(ontime > zentime){
  61.             fugou = -1;
  62.             }
  63.             else{
  64.                 if(ontime < 20){
  65.                 fugou = 1;
  66.             }
  67.        }
  68.     }
  69.  
  70.  __delay_us(4);
  71.  
  72. }//End of while
  73. return;
  74. }//End of main
 
▼電飾のテスト動画です。
ミレニアムファルコン TEST
 
次は塗装です。
今回は発光ユニットを組込んでしまっているので、マスキングして塗装します。



コメントを投稿

サービス終了に伴い、10月1日にコメント投稿機能を終了させていただく予定です。