macsbug

Just another WordPress.com site

Monitor Circuit Program for Arduino

leave a comment »

Monitor Circuit Program                                                       2014.09.21

// 1. XXX-XXX A429 ALTITUDE RECEIVER
// 2. XXX-XXX A429 FLAG WORD RECEIVER
// 3. DC MONITOR
//                  ORG 2010.03.27  s.mac
//                  REV 2014.09.09  s.mac
//========================================// ===========================
// EXTERNAL SPEAKER         <- Arduino PD4 : DC VOLTAGE WARNING OUTPUT
// LRA900 RX DISABLE(A5TP11)-> Arduino PD4 : 16 : NULL=0
// A429A : T1203 429 OUTPUT -> Arduino PD3 :  8 : 16+8=24 = "1"
// A429B : T1203 429 OUTPUT -> Arduino PD2 :  4 : 16+4=20 = "0"
// USB SERIAL TX DATA       <- Arduino PD1 : SERIAL Tx
// USB SERIAL Rx DATA       -> Arduino PD0 : SERIAL Rx
// VOLUME                   -> Arduino A1  : MONITOR VOLTAGE SET
// DC MONITOR VOLTAGE       -> Arduino A0  :
//========================================// ===========================
//                   _______________      <--- 10.16msec
// __________________|             |_____ RX DISABLE(16),LRA-900 A5TP11
//       _______          _______         <---  2.56msec
// ______|||||||__________|||||||________ A429 32bit
//                        FLAG WORD DATA
//              ________                  <--- 40usec
// _____________|  24  |_________________ A429A(8)
//      0   16    16+8        ________    <--- 40usec
// ___________________________| 16+4 |___ A429B(4)
//========================================// ===========================

int    mon;                               // analog in A0 monitor input
int    ref;                               // analog in A1 volume
int    mode;                              // 1=ALT,2=FLAG WORD,3=DC MON
int    data;                              // buffer of read data
int    m2p5;                              // 2.56msec
byte   mask=B00001100;                    // 8="1", 4="1"
String L164="01110100";                   // LABEL 164 BNR, 01 110 100
String L165="01110101";                   // LABEL 165 BCD, 01 110 101
String b32="00000000000000000000000000000000"; // A429 32bit  Receive
String nul="00000000000000000000000000000000"; // A429 32bit
String b="000001000";                     // "1" = bit 8
//        012345678

//========================================// ===========================
void setup() {
  Serial.begin(115200);                   // serial bau rate 115270
  delay(500);                             // 0.5SEC DELAY
  mon = analogRead(A0);                   // MODE(VOLUME POSITION) IN
  if ( mon <= 150 ){ mode = 1;            // altitude
       DDRD = DDRD | B00000000;}          // PORT_D ALL INPUT
  if ( (mon>150) && (mon<900)){ mode = 2; // flag word
       DDRD = DDRD | B00000000;}          // PORT_D ALL INPUT   
  if ( mon >= 900 ){ mode = 3;            // dc monitor
       pinMode(4,OUTPUT);                 // PD4 OUTPUT MODE
       digitalWrite(4,LOW);}              // PD4 0 OUTPUT
  delay(1000);                            // 1sec delay
}
//========================================// =========================== 

void loop() {                             //  
  if ( mode == 1 ){ goto altitude;}       // 1 = altitude   mode
  if ( mode == 2 ){ goto flag_word;}      // 2 = flag word  mode
  if ( mode == 3 ){ goto dc_monitor;}     // 3 = dc monitor mode
  goto pass;
//-------------------------------------------------------
altitude:
e: m2p5 = 100;                            // 2.56ms null ck
f: data = PIND & mask;                    // read & mask
   if ( data == 0 && m2p5 < 0){ goto g;}  // no data & 2.5ms null ok
   m2p5 = m2p5 - 1;                       // decrement time
   goto f;                                // loop
//----------------------------------------// 32bit Read
g: rx();                                  // 1ST 32bit Read
   for ( int i=0; i<8; i=i++ ){           // LABEL 164 ck, 0-7 8bit
    if ( b32[i] != L164[i]){ goto e;}     // LABEL 164 ck
   }                                      // END LABEL 164 ok  
   rx();                                  // 2st 32bit Read
   for ( int i=0; i<8; i=i++ ){           // LABEL 165 ck,0-7 8bit
    if ( b32[i] != L165[i]){ goto e;}     // LABEL 165 ck
   }                                      // END LABEL 164 ok
   Serial.print(b32);                     // 165 ALTITUDE output
   goto pass;
//========================================// =========================== 
flag_word:                                // port D Serial TX(p1),RX(p0)
 d: data = PIND & B00010000;              // rx disable read
    if ( data == 0 ){ goto d;}            // rx disable check
 for ( int i=0; i<32; i++){               // read 32bit set
 z: data = PIND & B00011100;              // read FLAG WORD data  
    if ( data == 16 ){ goto z;}           // A429 pin 4,3 "0" loop
    b32[i] = b[data];                     // A429A "1" store
 p: data = PIND & B00011100;              // read FLAG WORD data   
    if ( data > 16 ){ goto p;}            // A429 pin 4 or 3 "1" loop
 }
  Serial.println(b32);                    // Flag Word output            
  goto pass;
//========================================// ===========================  
dc_monitor:
   mon = analogRead(A0);                  // dc Analog input
   ref = analogRead(A1);                  // Volume
   if ( mon < ref ){digitalWrite(4,HIGH);}// worning output on
               else{digitalWrite(4,LOW);} // worning output off
   Serial.println(mon);                   // dc mon output  
   goto pass;
//========================================// ===========================
pass:
   b32 = nul;
}
//========================================// ===========================
void rx(){                                // 32bit Receive
  for ( int i=0; i<32; i++ ){             // read 32bit set
r:  data = PIND & B00001100;              // read 429 & mask(PD4,PD3)
    if ( data == 0 ){ goto r;}            // pin 4 &  3 "0" loop
    b32[i] = b[data];                     // "1/0" store: 8->"1",4->"0"
s:  data = PIND & B00001100;              // read 429 & mask(PD4,PD3)   
    if ( data >= 4 ){ goto s;}            // pin 4 or 3 "1" loop
  }                                       // END 32bit Receive
}                                         //
//========================================// =========================== 

Written by macsbug

9月 21, 2014 @ 2:46 am

カテゴリー: Arduino

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト / 変更 )

Twitter 画像

Twitter アカウントを使ってコメントしています。 ログアウト / 変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト / 変更 )

Google+ フォト

Google+ アカウントを使ってコメントしています。 ログアウト / 変更 )

%s と連携中

%d人のブロガーが「いいね」をつけました。