2023-11-13
▼LED制御回路をPICで作成します。


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

▼ソースファイルです。
- /*
- * File: main.c
- * エンジン発光 LED高速明滅 3LED。 連続点灯 2LED。
- * PIC12F1822
- * Author:
- * Created on 2023/09/05, 13:25
- */
- // CONFIG1
- #pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
- #pragma config WDTE = OFF // Watchdog Timer Enable (WDT enabled)
- #pragma config PWRTE = ON // Power-up Timer Enable (PWRT disabled)
- #pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
- #pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
- #pragma config CPD = OFF // Data Memory Code Protection (Data memory code protection is disabled)
- #pragma config BOREN = OFF // Brown-out Reset Enable (Brown-out Reset enabled)
- #pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
- #pragma config IESO = OFF // Internal/External Switchover (Internal/External Switchover mode is enabled)
- #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
- // CONFIG2
- #pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
- #pragma config PLLEN = OFF // PLL Enable (4x PLL enabled)
- #pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
- #pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
- #pragma config LVP = OFF // Low-Voltage Programming Enable (Low-voltage programming enabled)
- #include <xc.h>
- #define _XTAL_FREQ 8000000
- void main(void) {
- OSCCON = 0b01110010; //内部クロック8MHz 4MHz 0b01101010
- ANSELA = 0b00000000; //アナログは使用しない(すべてデジタルI/Oに割り当てる)
- TRISA = 0b00001000; //RA3だけ入力その他のピンは出力に割当てる(RA3は入力専用)
- PORTA = 0; //出力ピンの初期化(全てLOWにする)
- //------------変数の宣言------------
- //ED明滅のための変数
- char zentime = 65;
- char ontime = 20;
- char ima = 1;
- char fugou =2;
- while(1){
- //明滅 RA0、RA1、RA2。 連続点灯 RA4、RA5
- if(ima < ontime){
- PORTA = 0b00110111;
- }
- else{
- PORTA = 0b00110000;
- }
- //明滅ロジック
- ima++;
- if(ima > zentime){
- ima = 1;
- ontime = ontime + fugou; //点灯している時間を徐々に増減
- if(ontime > zentime){
- fugou = -1;
- }
- else{
- if(ontime < 20){
- fugou = 1;
- }
- }
- }
- __delay_us(4);
- }//End of while
- return;
- }//End of main
▼電飾のテスト動画です。
ミレニアムファルコン TEST
次は塗装です。
今回は発光ユニットを組込んでしまっているので、マスキングして塗装します。
今回は発光ユニットを組込んでしまっているので、マスキングして塗装します。
※コメント投稿者のブログIDはブログ作成者のみに通知されます