コミケで頒布した信号機のプログラム

大変遅くなりました。

コミケで頒布した信号機のプログラムです。
プログラムをgitに載せようとしたのですが、準備が全然進まなかったので追記という形式で全文を書きます。

基本はC言語ですし、MPLAB X があれば動くはずです。
えーっと、あとは使用しているICがPICの16F1823だったような。

果たして、組み立てることができた人は居たのだろうか。。。。

//======================================================================
//Project Name : 3灯式信号機
//
//Copyright © <2017> hozulab. All rights reserved.
//
//This source code or any portion thereof must not be
//reproduced or used in any manner whatsoever.
//======================================================================


#include "xc.h"

#define _XTAL_FREQ 4000000


#pragma config FOSC = INTOSC // INTOSCIO oscillator:
#pragma config PWRTE = ON // PWRT enabled
#pragma config WDTE = OFF // WDT disabled
#pragma config PLLEN = OFF //
#pragma config BOREN = OFF // BOR disabled
#pragma config BORV = LO // BOR voltage
#pragma config MCLRE = OFF,LVP = OFF

// 2-4 common
#define ModeSW RA5
#define Sensor RA4
#define LinkIn1 RA3
#define LinkIn2 RC5
#define LinkIn3 RC4
#define LinkOut1 RC3


#define SignalR RA0
#define SignalY1 RA1
#define SignalY2 RA2
#define SignalG RC0
#define LinkOut3 RC1
#define LinkOut2 RC2
//#define LED1 LATC2
//#define TRIS_LED TRISC2
int timer = 0 ;
//color_set_timer
int signal_R = 100 ;
int signal_YY = 500 ;
int signal_Y = 1000 ;
int signal_YG = 1500 ;
int signal_G = 2000 ;

int Signal = 0; //0=R,1=YY,2=Y,3=YG,4=G,5=GG
int Train = 0 ; //train_on/off 0=off,1=on
int Train_mae = 0 ; //train_mae on/off 0=off,1=on
int Train_mae_sensor = 0 ; //train mae sensor on/off 0=off,1=0n

int main(void) {

// ????
OSCCON = 0b01101000; // bit7: SPLLEN = OFF
// bit6-3: 4MHz

//nWPUEN = 0; // Weak pull-ups are enabled

// ????????
TRISA = 0b111000;
TRISC = 0b110000;
ANSELA =0;
ANSELC =0;

//Start

SignalR = 1; // LED OFF
SignalY1 = 1; // LED OFF
SignalY2 = 1; // LED OFF
SignalG = 1; // LED OFF



//start
SignalR = 0; // LED ON
__delay_ms(100);
SignalR = 1; // LED OFF
__delay_ms(100);

/*SignalY1 = 0; // LED ON
__delay_ms(100);
SignalY1 = 1; // LED OFF
__delay_ms(100);
*/
SignalY2 = 0; // LED ON
__delay_ms(100);
SignalY2 = 1; // LED OFF
__delay_ms(100);

SignalG = 0; // LED ON
__delay_ms(100);
SignalG = 1; // LED OFF
__delay_ms(100);


// roop
while(1){


if(ModeSW==0){
//SensorMode

//Input

if(LinkIn1==0){
if(LinkIn2==1){
if(LinkIn3==0){
Signal = 4;//GG
Train_mae = 0;
}
}
}
if(LinkIn1==0){
if(LinkIn2==1){
if(LinkIn3==1){
Signal = 4;//G
Train_mae = 0;
}
}
}
if(LinkIn1==1){
if(LinkIn2==0){
if(LinkIn3==0){
Signal = 4;//YG
Train_mae = 0;
}
}
}
if(LinkIn1==1){
if(LinkIn2==0){
if(LinkIn3==1){
Signal = 4;//Y
Train_mae = 0;
}
}
}
if(LinkIn1==1){
if(LinkIn2==1){
if(LinkIn3==0){
Signal = 2;//YY
Train_mae = 0;
}
}
}
if(LinkIn1==1){
if(LinkIn2==1){
if(LinkIn3==1){
Signal = 2;//R
Train_mae = 1;
}
}
}




if(Train_mae == 0){
//mae ni train ga inai toki




}
if(Train_mae == 1 ){
//mae ni train ga iru toki
Train = 0;
}


//Sensor
if(Sensor==0){
Signal = 0;
}


if(Train == 0){
//signal
if(Signal == 5){
SignalR = 1; //off
SignalY1 = 1; //off
SignalY2 = 1; //off
SignalG = 0; //on



LinkOut1 = 0;
LinkOut2 = 1;
LinkOut3 = 1;
}
if(Signal == 4){
SignalR = 1; //off
SignalY1 = 1; //off
SignalY2 = 1; //off
SignalG = 0; //on

LinkOut1 = 0;
LinkOut2 = 1;
LinkOut3 = 1;
}

//signal_YG*/
if(Signal == 3){
SignalR = 1; //off
SignalY1 = 0; //on
SignalY2 = 1; //off
SignalG = 0; //on

LinkOut1 = 1;
LinkOut2 = 0;
LinkOut3 = 0;
}
//signal_Y
if(Signal == 2){
SignalR = 1; //off
SignalY1 = 1; //off
SignalY2 = 0; //on
SignalG = 1; //off

LinkOut1 = 1;
LinkOut2 = 0;
LinkOut3 = 1;
}

//signal_YY
if(Signal == 1){
SignalR = 1; //off
SignalY1 = 0; //on
SignalY2 = 0; //off
SignalG = 1; //on

LinkOut1 = 1;
LinkOut2 = 1;
LinkOut3 = 0;
}
//signal_R
if(Signal == 0){
SignalR = 0; //on
SignalY1 = 1; //off
SignalY2 = 1; //off
SignalG = 1; //off

LinkOut1 = 1;
LinkOut2 = 1;
LinkOut3 = 1;
Train = 1;
}

}




}else{

//TimerMode




__delay_ms(4); // 10msec
timer=timer+1;

//Sensor
if(Sensor==0){
timer = 0;
}

if(timer>signal_G){
timer=signal_G;
}

//signal_G
if(timer==signal_G){
SignalR = 1; //off
SignalY1 = 1; //off
SignalY2 = 1; //off
SignalG = 0; //on

LinkOut1 = 0;
LinkOut2 = 1;
LinkOut3 = 1;
}
/*
//signal_YG
if(timer==signal_YG){
SignalR = 1; //off
SignalY1 = 0; //on
SignalY2 = 1; //off
SignalG = 0; //on

LinkOut1 = 1;
LinkOut2 = 0;
LinkOut3 = 0;
}*/
//signal_Y
if(timer==signal_Y){
SignalR = 1; //off
SignalY1 = 1; //off
SignalY2 = 0; //on
SignalG = 1; //off

LinkOut1 = 1;
LinkOut2 = 0;
LinkOut3 = 1;
}
/*
//signal_G
if(timer==signal_YY){
SignalR = 1; //off
SignalY1 = 0; //on
SignalY2 = 0; //off
SignalG = 1; //on

LinkOut1 = 1;
LinkOut2 = 1;
LinkOut3 = 0;
}*/
//signal_R
if(timer<=signal_R){
SignalR = 0; //off
SignalY1 = 1; //on
SignalY2 = 1; //off
SignalG = 1; //on

LinkOut1 = 1;
LinkOut2 = 1;
LinkOut3 = 1;
}





}//TimerMode



}//while

return (0);
}

スポンサーサイト

2017-09-03 23:34 : Pontekia : コメント : 0 : トラックバック : 0 :
コメントの投稿
非公開コメント

« next  ホーム  prev »

プロフィール

HozuLab(ほずらぼ)

Author:HozuLab(ほずらぼ)

ClariSのBGMが流れている時だけテンションが余計に上がる。
ちょっと違う思考の持ち主

最新トラックバック

検索フォーム

ブロとも申請フォーム

この人とブロともになる

QRコード

QR