macsbug

Just another WordPress.com site

32ch Logic Analyzer of Arduino DUE TFT35 Touch

leave a comment »

Arduino DUE 版、32ch(Arinc 429) Logic Analyzer です。

dr

 

 

 

 

 

321

 

 

 

 

 

 

 

 

信号と読み取り。
1. Arinc 429 のデジタル信号の半周期は、40usec である。この為、充分なI/O読み取り速度が必要である。
2. PORT入力の解説:PORTの高速入力方法は、Arduino UNO, MEGA, DUEにてスケッチ方法が異なる。

ポートの分解能力。
MEGAとDUEのポート高速読み取り時間は以下である。
1. MEGA:PORTB _BV(PBx) :   3 CPU CLOCK CYCLE : 187.5 nsec
2. DUE   :*DirectPort Read   : 26 CPU CLOCK CYCLE : 307.7 nsec

DUEの方法。
例:inline Routine PIN を使用する。 スケッチ:ax = PIN(RA); bx = PIN(RB); // 615.4 nsec

*DirectPort Read Routine
  inline int PIN(int pin){                         // PIN:Port INPUT
    return !!(g_APinDescription[pin].pPort ->      // digitalReadDirect
        PIO_PDSR & g_APinDescription[pin].ulPin);  //
  }                                                //

結論:DUEは、約64個の分解能がある。
PORTの値を読む為に、26 CPU CLOCK CYCLE = 307.7 nsec 必要である。
429A と 429B の2つを読む場合は、307.7 x 2 = 615.4 nsec 必要となる。
429信号の半周期は、40usec であるから、40x1000/615.4=64.9個となり、約64個の分解能がある。

まとめ:DUEのPORTの読取分解能は、64個である。
    読取速度は、MEGAより4割程遅いが、デイスプレー表示等の速度は、5倍速い。
    
       LCD TOUCH を使用しテンキー等の操作を増やすと、ほとんどがTouchのスケッチが占めてしまう。
    プログラム容量も多くなり、Arduino uno では、容量が足りず、MEGA か DUE を使用する事になる。

宿題: DUEで、PORTをさらに高速に読む方法はないだろうか?
       ASSEMBLERを調べる必要があるかもしれない。
スケッチ:Download 32ch Logic Analyzer for Arduino DUE
//=========================================================================
// 32ch Logic Analyzer for Arduino DUE
//=========================================================================
// ORG    2013.12.30  32bit ARM Cortex-M3 CPU + TFT + Touch          s.ono
// REV 1  2014.01.01  mode 5        : Maintenance Mode
// REV 2  2014.01.01  mode 6        : Monitor Mode
// REV 3  2014.01.01  MON,BIT       : digitalWrite
// REV 4  2014.01.03  I/O PORT      : digitalWrite(13)
// REV 5  2014.01.10  Receiver      : 8,9 INPUT
// REV 6  2014.01.12  Receiver      : Void LOOP AREA, RE PROGRAMING
// REV 7  2014.01.12  I/O Hi Speed  : DirectPort
// REV 8  2014.01.13  LABEL,MONITOR : LABEL LOCK, Warning
// REV 9  2014.01.16  Null check    : 80nsec null check
//-------------------------------------------------------------------------
// ARINC 429    : 1 Word 32 bit                       : 2.54  msec
// ARINC 429    : 1 cycle                             :  80   usec         
//-------------------------------------------------------------------------
// Arduino DUE  : Atmel SAM3X8E ARM Cortex-M3 CPU     : 32bit 84MHz
// Arduino DUE  : 1 cpu clock cycle : 1sec/84MHz      :  11.9 nsec
// Arduino MEGA : 1 cpu clock cycle : 1sec/16MHz      :  62.5 nsec
//-------------------------------------------------------------------------
// Arduino MEGA : digitalWrite   : 44 CPU CLOCK CYCLE : 2.750 msec
// Arduino MEGA : PORTB _BV(PBx) :  3 CPU CLOCK CYCLE : 187.5 nsec
// Arduino DUE  : digitalWrite   : 44 CPU CLOCK CYCLE : 523.6 nsec
// Arduino DUE  : digitalRead    : 30 CPU CLOCK CYCLE : 357.1 nsec
// Arduino DUE  : DirectPort Read: 26 CPU CLOCK CYCLE : 307.7 nsec
//-------------------------------------------------------------------------
// UNO,MEGA :
// if(bit_is_set(PIND,PIND2)){PORTB=_BV(1)|_BV(2);// D2=HIGH->D9,D10 HIGH
// }else{ PORTB &= ~_BV(1) & ~_BV(2);}        // D2 not HIGH->D9,D10 LOW
// DUE :
// if ( digitalRead(2) == HIGH){ digitalWrite(13,HIGH);}
// Arduino DUE   : Port manipulation PINx commands with Arduino Due
//                 http://forum.arduino.cc/index.php?topic=129868.15
//-------------------------------------------------------------------------
// Arduino MEGA 2560 (16MHz) : Arduino 1.0.5, 1.5.5
// Arduino Due       (84MHz) : Arduino 1.5.2
//-------------------------------------------------------------------------
// 3.5" 480x320 TFT LCD Module, Controller : R61581
// UTFT   Library: http://henningkarlsen.com/electronics/library.php?id=51
// UTouch Library: http://henningkarlsen.com/electronics/library.php?id=55
// UTouch Calibration Data Verification
//               : http://henningkarlsen.com/electronics/t_cal_verify.php
//=========================================================================
// mode 0 : Free RUN  : RECEIVER, LED DISP, DRAW DISP
// mode 1 : PAUSE     : PAUSE ON/OFF
// mode 2 :           :
// mode 3 : LABEL     : 000 to 777
// mode 4 : BIT       : BIT 9 to 32
// mode 5 : DEBUG     : Mode,x pos,LABEL,BIT,MON BIT Display
// mode 6 : MONITOR   : BIT ( 0/1 ) WARNING : OUTPUT Pin 13
//=========================================================================
// Binary sketch size: 53,520 bytes (of a 524,288 byte maximum) - 10% used
//=========================================================================
#include <UTFT.h>                                // UTFT   Routine
#include <UTouch.h>                              // UTouch Routine
extern uint8_t SmallFont[];                      // Small Font
extern uint8_t BigFont[];                        // Big   Font
extern uint8_t SevenSegNumFont[];                // SevenSegNumFont
UTFT   myGLCD(CTE35IPS,38,39,40,41);             // TFT set,Model=CTE35IPS
UTouch myTouch(6,5,4,3,2);                       // Touch setup
//-----------------------------------------------// Receiver
int const RA = 9;                                // 429A input port
int const RB = 8;                                // 429B input port
String n = "00000000000000000000000000000000";   // nul data
String b = "00000000000000000000000000000000";   // Receiver 32bit
String c = "00000000000000000000000000000000";   // 32bit buffer
int ax;                                          // Read 429A data
int bx;                                          // Read 429B data
String LB  = "000";                              // Rx  LABEL
//-----------------------------------------------// Display
String z;                                        // BIT
String m;                                        // MONITOR
int d = 5;                                       // x division
int H;                                           // Hi Level
int L;                                           // Lo Level
int x1 =  60;                                    // Analyzer x start pos
int bk = 200;                                    // background color R.G.B
int L1,L2,L3;                                    // Label data
char r[3];                                       //
int s;                                           // SELECT bit
//-----------------------------------------------// Touch
int mode = 0;                                    // Loop mode:0,1,2,3,4,5,6
String LBL = "000";                              // KEY LABEL
String BIT = "0";                                // BIT
String MON = "1";                                // MONITOR bit
//=========================================================================
inline void POUT(int pin, boolean val){          // POUT:Port OUTPUT
  if(val) g_APinDescription[pin].pPort ->        // digitalWriteDirect
        PIO_SODR = g_APinDescription[pin].ulPin; //
  else    g_APinDescription[pin].pPort ->        //
        PIO_CODR = g_APinDescription[pin].ulPin; //
}                                                //
//=========================================================================
inline int PIN(int pin){                         // PIN:Port INPUT
  return !!(g_APinDescription[pin].pPort ->      // digitalReadDirect
        PIO_PDSR & g_APinDescription[pin].ulPin);//
}                                                //
//=========================================================================
void setup() {                                   //
 //Serial.begin(115200);
 pinMode( 8, INPUT);                             // 429B
 pinMode( 9, INPUT);                             // 429A
 pinMode(10, INPUT);                             // Control
 pinMode(13, OUTPUT);                            // LED 13 OUTPUT
 digitalWrite(13,LOW);                           // Pin 13 LOW
 //----------------------------------------------//
 myGLCD.InitLCD();                               // LCD Initialize
 myGLCD.setFont(SmallFont);                      // Font : smallfont
 myGLCD.clrScr();                                // LCS Clear
 myTouch.InitTouch();                            // Touch Initialize
 myTouch.setPrecision(PREC_EXTREME);             // Touch Sence MAX
 myGLCD.setColor(bk,bk,bk);                      // panel background color
 myGLCD.fillRect(0, 0, 480, 320);                // panel all fill
 myGLCD.setColor(0, 0, 0);                       // moji color=white
 myGLCD.setBackColor(bk,bk,bk);                  // moji background color
 myGLCD.print(" ARINC 429 ANALYZER", LEFT, 1);   // TITLE
 //----------------------------------------------//
 myGLCD.setColor(0, 0, 0);                       // 1/0 info
 myGLCD.print("1",29, 13);                       // 1   info
 myGLCD.print("0",38, 13);                       // 0   info
 myGLCD.setColor(0,0,0);                         // 1/0 FRAME
 myGLCD.fillRect(27, 27, 44, 34);                // 1/0 FRAME
 myGLCD.setColor(255,255,255);                   // 1/0 FRAME shadow
 myGLCD.drawLine(27, 35, 45, 35);                // 1/0 FRAME shadow
 myGLCD.drawLine(45, 35, 45, 27);                // 1/0 FRAME shadow
 myGLCD.setColor(127, 0, 255);                   // 1   color
 myGLCD.fillRect(28, 28, 34, 33);                // 1   fill
 myGLCD.setColor(0, 165, 255);                   // 0   color
 myGLCD.fillRect(36, 28, 43, 33);                // 0   fill
 //----------------------------------------------//
 for (int x=1; x<9; x++){                        // LED 1-8 bit NO
   myGLCD.setColor(0, 0, 0);                     // LED 1-8 bit NO
   myGLCD.printNumI(x, (x*22)+33, 13);           // LED 1-8 bit NO
 }                                               // LED 1-8 bit NO
 myGLCD.print("LABEL", 230, 13);                 // LED "LABEL"
 //----------------------------------------------//
 String bn;                                      // LED 9-32 bit NO
 for (int y=9; y<33; y++){                       // LED 9-32 bit NO
   myGLCD.setColor(0, 0, 0);                     // LED 9-32 bit NO
   bn = " " + String(y);                         // LED 9-32 bit NO
   if (y < 10) { bn = "  "+String(y);}           // LED 9-32 bit NO
   myGLCD.print(bn, LEFT, (y-5)*11);             // LED 9-32 bit NO
 }                                               // LED 9-32 bit NO
  //---------------------------------------------//
  for (int x=50; x<220; x+=22){                  // LED FRAME 1-8
    myGLCD.setColor(0,0,0);                      // LED FRAME 1-8
    myGLCD.fillRect(x, 27, x+14, 34);            // LED FRAME 1-8
    myGLCD.setColor(255,255,255);                // LED FRAME 1-8 shadow
    myGLCD.drawLine(x, 35, x+15, 35);            // LED FRAME 1-8 shadow
    myGLCD.drawLine(x+15, 35, x+15, 27);         // LED FRAME 1-8 shadow
  }                                              // LED FRAME 1-8 shadow
  //---------------------------------------------//
  for (int y=46; y<300; y+=11){                  // LED FRAME 9-32
    myGLCD.setColor(0,0,0);                      // LED FRAME 9-32
    myGLCD.fillRect(27, y, 44, y+7);             // LED FRAME 9-32
    myGLCD.setColor(255,255,255);                // LED FRAME 9-32 shadow
    myGLCD.drawLine(27, y+8, 45, y+8);           // LED FRAME 9-32 shadow
    myGLCD.drawLine(45, y, 45, y+8);             // LED FRAME 9-32 shadow
    myGLCD.drawLine(27, y+9, 46, y+9);           // LED FRAME 9-32 shadow
    myGLCD.drawLine(46, y, 46, y+9);             // LED FRAME 9-32 shadow
  }                                              // LED FRAME 9-32 shadow
  //---------------------------------------------//
  myGLCD.setColor(0,0,0);                        // LA FRAME WHITE shadow
  myGLCD.drawRect(49, 39, 471, 315);             // LA FRAME WHITE shadow
  myGLCD.setColor(255,255,255);                  // LA FRAME shadow
  myGLCD.drawLine(49, 316, 472, 316);            // LA FRAME shadow
  myGLCD.drawLine(472, 316, 472, 39);            // LA FRAME shadow
  //---------------------------------------------//
  myGLCD.setColor(255,255,255);                  // LA BACK GROUND
  myGLCD.fillRect(50, 40, 470, 314);             // LA BACK GROUND
  //---------------------------------------------//
  myGLCD.setColor(0,0,0);                        // SW "LABEL"
  myGLCD.drawRect(300,5,350,35);                 // SW "LABEL"
  myGLCD.print("LABEL",307,15);                  // SW "LABEL"
  myGLCD.setColor(255,255,255);                  // SW "LABEL" shadow
  myGLCD.drawLine(300, 36, 351, 36);             // SW "LABEL" shadow
  myGLCD.drawLine(351, 36, 351, 5);              // SW "LABEL" shadow
  //---------------------------------------------//
  myGLCD.setColor(0,0,0);                        // SW "BIT"
  myGLCD.drawRect(360,5,410,35);                 // SW "BIT"
  myGLCD.print("BIT",375,15);                    // SW "BIT"
  myGLCD.setColor(255,255,255);                  // SW "BIT" shadow
  myGLCD.drawLine(360, 36, 411, 36);             // SW "BIT" shadow
  myGLCD.drawLine(411, 36, 411, 5);              // SW "BIT" shadow
  //---------------------------------------------//
  myGLCD.setColor(0,0,0);                        // SW "MON"
  myGLCD.drawRect(420,5,470,35);                 // SW "MON"
  myGLCD.print("MON",435,15);                    // SW "MON"
  myGLCD.setColor(255,255,255);                  // SW "MON" shadow
  myGLCD.drawLine(420, 36, 471, 36);             // SW "MON" shadow
  myGLCD.drawLine(471, 36, 471, 5);              // SW "MON" shadow
  //---------------------------------------------//
  //for ( int i=0; i<10540; i++ ){                 // 2.54msec null check
  //  ax = PIN(RA);bx = PIN(RB);                   //
  // if (( ax == 1 ) | ( bx == 1 )){ i = 0  ;}     //
  //}                                              //
  //---------------------------------------------//
}
//===============================================//=======================
void loop() {                                    //
 while (myTouch.dataAvailable() == true) {       // interupt Touch
   mode = touch(mode,x1);                        // MODE READ
   if (mode> 10 && mode<120){mode =  key(mode);} // key action
   if (mode>120 && mode<320){mode = bkey(mode);} // bit key action
   if (mode>320            ){mode = mkey(mode);} // mon key action
   delay(150);                                   //
 }                                               //
  //---------------------------------------------// --------------------
 /*
 if (mode==2 | mode==3 | mode==4 | mode==5){     // Maintenance Mode  
  myGLCD.setFont(SevenSegNumFont);               // font
  myGLCD.setColor(255,0,0);                      // color
  myGLCD.printNumI(mode,80,60);                  // mode
  myGLCD.printNumI(x1,80,120);                   // x position
  myGLCD.print(LBL,80,180);                      // LABEL
  myGLCD.print(BIT,80,240);                      // BIT
  myGLCD.print(MON,180,240);                     // MON
 }                                               //
 */
 //----------------------------------------------// --------------------
 //if ( mode == 0 | mode == 5 ){ goto rx;}       // -> Receiver
 if ( mode > 0 ){ goto pass;}                    // -> Pass
 //goto pass;                                    // Pass
 rx: //------------------------------------------//---------------------
 // 32 bit Reciver                               // mode = 0,5 only
 //----------------------------------------------// --------------------
 for ( int i=0; i<166; i++ ){                    // 80 usec null check
    ax = PIN(RA); bx = PIN(RB);                  // 166:min 130
    if (( ax == 1 ) | ( bx == 1 )){ i = 0 ;}     //
 }                                               //
 //----------------------------------------------// --------------------
 b = n;                                          // null set
 for ( int i=0; i<32; i++ ){                     // 32 bit
 p1: ax = PIN(RA); bx = PIN(RB);                 // 429A,B READ
     if (( ax == 0 ) && ( bx == 0 )){ goto p1;}  // 0 LOOP
     if ( ax == 1 ){ b[i] = '1';                 // 1 store
 p2:   if ( PIN(RA) == 1 ){ goto p2;}            // H Level ck
       goto p4;                                  // next
     }                                           //
 p3: if ( PIN(RB) == 1 ){ goto p3;}              // H Level ck
 p4:;                                            // next
  }                                              //
  //---------------------------------------------// --------------------
  L1 = 2*b[0] + b[1] - 144;                      // Label 1
  L2 = 4*b[2] + 2*b[3] + b[4] - 336;             // Label 2
  L3 = 4*b[5] + 2*b[6] + b[7] - 336;             // Label 3
  LB = String(L1) + String(L2) + String(L3);     // bit to String
  //---------------------------------------------// --------------------
  if ( LBL.equals(LB))   { goto disp;}           // LBL Select
  if ( LBL.equals("000")){ goto disp;}           // LBL 000 ALL mode
  goto pass;                                     // display pass
 disp: // 32 bit display-------------------------//---------------------
  myGLCD.setColor(255,255,255);                  // color black
  myGLCD.fillRect(x1,40,x1+d,314);               // Draw Clear bar
  //---------------------------------------------// --------------------
  myGLCD.setColor(0,0,0);                        // LABEL color white
  myGLCD.print(LB, 230, 24);                     // LABEL PRINT
  //---------------------------------------------// --------------------
  for ( int i=0; i<8; i++ ){                     // 32bit=(0)1-(7)8      
    if (b[i] == '1'){myGLCD.setColor(127,0,255);}// LED color green '1'
    if (b[i] == '0'){myGLCD.setColor(0,165,255);}// LED color orange
    myGLCD.fillRect((i*22)+51,28,(i*22)+63,33);  // LED bit fill
  }                                              // end of 0 to 7 bit
  //---------------------------------------------// --------------------
  for ( int i=8; i<32; i++ ){                    // 32bit=(8)9-(31)32
    if (b[i] == '1'){myGLCD.setColor(127,0,255);}// LED color green '1'
    if (b[i] == '0'){myGLCD.setColor(0,165,255);}// LED color orange
    H = 11*i - 41; L = 11*i - 36;                // LA H/L POS
    myGLCD.fillRect(28,H,43,L);                  // LED bit fill
    //-------------------------------------------// --------------------
    myGLCD.setColor(0,0,0);                      // LA bit color white
    BIT.toCharArray(r,3); s = atoi(r) - 1;       // String -> cha -> val
    if ( s == i ){                               // SELECT BIT
     myGLCD.setColor(0,255,0);                   // LA Monitor color RED
     if(MON.equals(String(b[i]))){POUT(13,HIGH);}// LED 13 ON
     else{                        POUT(13, LOW);}// LED 13 OFF
    }                                            // end of select bit
    //-------------------------------------------// --------------------
    if (b[i]!=c[i]){myGLCD.drawLine(x1,L,x1,H);} // LA bit CG V-line
    if (b[i]=='0'){myGLCD.drawLine(x1,L,x1+d,L);}// LA bit 0 level LO
    if (b[i]=='1'){myGLCD.drawLine(x1,H,x1+d,H);}// LA bit 1 level HI
    //-------------------------------------------// --------------------  
    c[i] = b[i];                                 // store bit "0/1"
  }                                              // end of to 32 bit
  x1 = x1 + d;                                   // x inc
  if ( x1 > 460 ){ x1 = 60;}                     // x pos max,start
 pass:;                                          //
}                                                // end of loop
//===============================================//========================
// Touch Routine                                 //
//=========================================================================
int touch(int mode, int x1){                     // Touch
  long xt, yt;                                   // a,y position
  myTouch.read();                                // TOUCH READ
  xt = myTouch.getX();                           // X TOUCH
  yt = myTouch.getY();                           // Y TOUCH
  /*
  // MAINTENANCE ---------------------------------------------------------
  if ( xt>0 & xt<50 & yt>0 & yt<50){             // DEBUG MODE AREA
    if ( mode == 0 ){ mode = 5; goto p2;}        //
    if ( mode == 5 ){ mode = 0; goto p2;}        //
  }                                              //
  p2:                                            //
  */
  // PAUSE ---------------------------------------------------------------
  if ( xt>50 & xt<290 & yt>40 & yt<314){         // PAUSE MODE AREA
    if ( mode == 0 ){                            //
      mode = 1;                                  // MODE 1
      myGLCD.setColor(255,200,200);              // Draw bit Clear
      myGLCD.fillRect(x1,40,x1+5,314);           // Draw bit Clear
      delay(50);                                 // WAIT
    }                                            //
    else{mode = 0;delay(50);}                    // MODE 0, FREE RUN, WAIT
  }                                              //
  //---------------------------------------------//
  if ( mode == 3 ){                              // LABEL
   int k;                                        //
   //     x1       x2       y1       y2          // LABEL KYE AREA
   if (xt>305 & xt<355 & yt>100 & yt<150){k=20;} // 0 = 23
   if (xt>355 & xt<405 & yt>100 & yt<150){k=30;} // 1 = 33
   if (xt>405 & xt<455 & yt>100 & yt<150){k=40;} // 2 = 43
   if (xt>305 & xt<355 & yt>150 & yt<200){k=50;} // 3 = 53
   if (xt>355 & xt<405 & yt>150 & yt<200){k=60;} // 4 = 63
   if (xt>405 & xt<455 & yt>150 & yt<200){k=70;} // 5 = 73
   if (xt>305 & xt<355 & yt>200 & yt<250){k=80;} // 6 = 83
   if (xt>355 & xt<405 & yt>200 & yt<250){k=90;} // 7 = 93
   if (xt>405 & xt<455 & yt>200 & yt<250){k=100;}// E = 103
   mode = mode + k;                              //
  }                                              //
  // LABEL ---------------------------------------------------------------
  if (xt>300 & xt<350 & yt>5 & yt<35){           // LABEL MENU AREA
    mode = 3;                                    //
    int n = 0;                                   //
    myGLCD.setColor(255,0,0);                    // "LABEL"
    myGLCD.fillRect(301,6,349,34);               // "LABEL"
    myGLCD.setFont(SmallFont);                   //
    myGLCD.setFont(SmallFont);                   // Small Font
    myGLCD.setColor(255,255,255);                // "LABEL"
    myGLCD.setBackColor(255,0,0);                // "LABEL"
    myGLCD.print("LABEL",307,15);                // "LABEL"
    //-------------------------------------------//
    myGLCD.setColor(255,255,255);                // Oscillo back clear
    myGLCD.fillRect(300,45,470,314);             // Oscillo back clear
    myGLCD.setColor(0,0,0);                      // FRAME
    myGLCD.drawRect(300,95,460,255);             // FRAME
    myGLCD.setColor(255,255,255);                // FRAME
    myGLCD.fillRect(301,96,459,254);             // FRAME
    //-------------------------------------------//
    int x1=305,y1=100,wd=50,xd=50;               // key pad
    for (int y=0; y<3; y++){                     // key pad
     for (int x=0; x<3; x++ ){                   // key pad
      myGLCD.setColor(255,255,0);                // FRAME
      myGLCD.drawRect(x1+x*xd,y1+y*xd,x1+x*xd+wd,y1+wd+y*xd);
      myGLCD.setColor(100,100,100);              // fill
      myGLCD.fillRect(x1+x*xd+1,y1+1+y*xd,x1+x*xd+wd-1,y1+wd-1+y*xd);
      if ( n<8 ){                                // key = 0 to 7
        myGLCD.setFont(BigFont);                 // Bigfont
        myGLCD.setColor(255,255,255);            //
        myGLCD.setBackColor(100,100,100);        //
        myGLCD.print(String(n),323+x*xd,y1+18+y*xd); // key no
      }                                          //
      if ( n == 8 ){                             // key = ENT
        myGLCD.setFont(BigFont);                 //
        myGLCD.setColor(255,255,255);            //
        myGLCD.setBackColor(100,100,100);        //
        myGLCD.print("ENT",306+x*xd,y1+18+y*xd); //
      }                                          //
      n++;                                       // key no +
     }                                           //
    }                                            //
  }                                              //
  //---------------------------------------------//
  if ( mode == 4 ){                              // BIT
   int k;                                        //
   //     x1       x2       y1       y2          // BIT KEY AREA
   if (xt>305 & xt<355 & yt>100 & yt<150){k=120;}// 0 = 123
   if (xt>355 & xt<405 & yt>100 & yt<150){k=130;}// 1 = 133
   if (xt>405 & xt<455 & yt>100 & yt<150){k=140;}// 2 = 143
   if (xt>305 & xt<355 & yt>150 & yt<200){k=150;}// 3 = 153
   if (xt>355 & xt<405 & yt>150 & yt<200){k=160;}// 4 = 163
   if (xt>405 & xt<455 & yt>150 & yt<200){k=170;}// 5 = 173
   if (xt>305 & xt<355 & yt>200 & yt<250){k=180;}// 6 = 183
   if (xt>355 & xt<405 & yt>200 & yt<250){k=190;}// 7 = 193
   if (xt>405 & xt<455 & yt>200 & yt<250){k=200;}// 8 = 203
   if (xt>305 & xt<355 & yt>250 & yt<300){k=210;}// 9 = 213
   if (xt>355 & xt<405 & yt>250 & yt<300){k=220;}// E = 223
   if (xt>405 & xt<455 & yt>250 & yt<300){k=230;}// E = 233
   mode = mode + k;                              //
  }                                              //
  // BIT ---------------------------------------------------------------
  if ( xt>360 & xt<410 & yt>5 & yt<35){          // BIT MENU AREA
   if ( mode == 0 ){                             // rx mode
     mode = 4;                                   // MODE 4
     int n = 0;                                  // KEY NO
     //------------------------------------------//
     myGLCD.setColor(0,0,0);                     // FRAME
     myGLCD.drawRect(300,95,460,255);            // FRAME
     myGLCD.setColor(255,255,255);               // FRAME
     myGLCD.fillRect(301,96,459,254);            // FRAME
     //------------------------------------------//
     myGLCD.setColor(255,0,0);                   //
     myGLCD.fillRect(361,6,409,34);              //
     myGLCD.setFont(SmallFont);                  // Small Font
     myGLCD.setColor(255,255,255);               // "BIT"
     myGLCD.setBackColor(255,0,0);               // "BIT"
     myGLCD.print("BIT",375,15);                 // "BIT"
     //------------------------------------------//
     myGLCD.setColor(255,255,255);               // Oscillo back clear
     myGLCD.fillRect(300,50,470,314);            // Oscillo back clear
     myGLCD.setColor(0,0,0);                     // FRAME
     myGLCD.drawRect(300,95,460,305);            // FRAME
     myGLCD.setColor(255,255,255);               // FRAME
     myGLCD.fillRect(301,96,459,304);            // FRAME
     //------------------------------------------//
     int x1=305,y1=100,wd=50,xd=50;              // key pad
     for (int y=0; y<4; y++){                    // key pad
      for (int x=0; x<3; x++ ){                  // key pad
        myGLCD.setColor(255,255,0);              // FRAME
        myGLCD.drawRect(x1+x*xd,y1+y*xd,x1+x*xd+wd,y1+wd+y*xd);
        myGLCD.setColor(100,100,100);            // fill
        myGLCD.fillRect(x1+x*xd+1,y1+1+y*xd,x1+x*xd+wd-1,y1+wd-1+y*xd);
        if ( n<10 ){                             // key = 0 to 7
          myGLCD.setFont(BigFont);               // Bigfont
          myGLCD.setColor(255,255,255);          //
          myGLCD.setBackColor(100,100,100);      //
          myGLCD.print(String(n),323+x*xd,y1+18+y*xd); // key no
        }                                        //
        if ( n == 11){                           // key = ENT
          myGLCD.setFont(BigFont);               //
          myGLCD.setColor(255,255,255);          //
          myGLCD.setBackColor(100,100,100);      //
          myGLCD.print("ENT",306+x*xd,y1+18+y*xd);
        }                                        //
        n++;                                     // key no +
       }                                         //
      }                                          //
    }                                            //
    else{mode = 0;delay(50);}                    //
   }                                             //
   //--------------------------------------------//------------------------
   if ( mode == 6 ){                             // MONITOR
   int k;                                        //
   //     x1       x2       y1       y2          // MONITOR MODE AREA
   if (xt>305 & xt<355 & yt>100 & yt<150){k=320;}// 0 = 323
   if (xt>355 & xt<405 & yt>100 & yt<150){k=330;}// 1 = 333
   if (xt>405 & xt<455 & yt>100 & yt<150){k=340;}// E = 343
   mode = mode + k;                              //
  }                                              //
  // MONITOR --------------------------------------------------------------
  if ( xt>420 & xt<470 & yt>5 & yt<35){          // MONITOR MEMU AREA
   if ( mode == 0 ){                             // rx mode
     mode = 6;                                   // MODE 6
     //------------------------------------------// 420,5,470,35
     myGLCD.setColor(255,0,0);                   //
     myGLCD.fillRect(421,6,469,34);              //
     myGLCD.setFont(SmallFont);                  // Small Font
     myGLCD.setColor(255,255,255);               // "BIT"
     myGLCD.setBackColor(255,0,0);               // "BIT"
     myGLCD.print("MON",435,15);                 // "BIT"
     //------------------------------------------//
     myGLCD.setColor(0,0,0);                     // FRAME
     myGLCD.drawRect(300,95,460,155);            // FRAME
     myGLCD.setColor(255,255,255);               // Oscillo back clear
     myGLCD.fillRect(300,45,470,314);            // Oscillo back clear
     //------------------------------------------//
     myGLCD.setColor(255,255,0);                 // FRAME
     myGLCD.drawRect(305,100,355,150);           //
     myGLCD.setColor(100,100,100);               // fill
     myGLCD.fillRect(306,101,354,149);           //
     myGLCD.setFont(BigFont);                    // Bigfont
     myGLCD.setColor(255,255,255);               //
     myGLCD.setBackColor(100,100,100);           //
     myGLCD.print("0",323,118);                  // key no
     //------------------------------------------//     
     myGLCD.setColor(255,255,0);                 // FRAME
     myGLCD.drawRect(355,100,405,150);           //
     myGLCD.setColor(100,100,100);               // fill
     myGLCD.fillRect(356,101,404,149);           //
     myGLCD.setFont(BigFont);                    // Bigfont
     myGLCD.setColor(255,255,255);               //
     myGLCD.setBackColor(100,100,100);           //
     myGLCD.print("1",373,118);                  // key no
     //------------------------------------------//     
     myGLCD.setColor(255,255,0);                 // FRAME
     myGLCD.drawRect(405,100,455,150);           //
     myGLCD.setColor(100,100,100);               // fill
     myGLCD.fillRect(406,101,454,149);           //
     myGLCD.setFont(BigFont);                    // Bigfont
     myGLCD.setColor(255,255,255);               //
     myGLCD.setBackColor(100,100,100);           //
     myGLCD.print("ENT",406,118);                // key no
    }                                            //
    else{mode = 0;delay(50);}                    // mode 0
   }                                             //
  // MONITOR ------------------------------------//------------------------
  return mode;                                   //
}                                                //
//=========================================================================
int key(int mode){                               // LABEL KEY INPUT
  if ( mode == 103 ){                            // mode 3 enter action
       myGLCD.setFont(BigFont);                  //
       myGLCD.setColor(255,255,255);             //  
       myGLCD.setBackColor(100,100,100);         //  
       myGLCD.print(LBL,306,70);                 //
       myGLCD.setColor(bk,bk,bk);                //
       myGLCD.fillRect(301,6,349,34);            //
       myGLCD.setFont(SmallFont);                // Small Font
       myGLCD.setColor(0,0,0);                   //
       myGLCD.setBackColor(bk,bk,bk);            //
       myGLCD.print(LBL,315,15);                 // LABEL disp write
       mode = 0;                                 // rx mode
     }                                           //
     else{                                       //
     LBL = LBL + String(int(mode/10)-2);         // key read add
     int L = LBL.length();                       //
     if (L==0 | L==1 | L==2 | L==3){ goto p1;}   // 0,1,2,3
     if (L>3){LBL = LBL.substring(L-3,L+1);}     //
     p1:                                         //
     myGLCD.setFont(BigFont);                    //
     myGLCD.setColor(255,255,255);               //
     myGLCD.setBackColor(100,100,100);           //
     myGLCD.print(LBL,306,70);                   //
     mode = 3;                                   // key input mode
     }                                           //
   return mode;                                  //  
}                                                //
//=========================================================================
int bkey(int mode){                              // BIT KYE INPUT
  if ( mode == 234 ){                            // mode 4 enter action
       myGLCD.setFont(BigFont);                  //
       myGLCD.setColor(255,255,255);             //  
       myGLCD.setBackColor(100,100,100);         //  
       myGLCD.print(BIT,306,70);                 //
       myGLCD.setColor(bk,bk,bk);                //
       myGLCD.fillRect(361,6,409,34);            //
       myGLCD.setFont(SmallFont);                // Small Font
       myGLCD.setColor(0,0,0);                   //
       myGLCD.setBackColor(bk,bk,bk);            //
       myGLCD.print(BIT,380,15);                 // bit disp write
       mode = 0;                                 // rx mode
     }                                           //
     else{                                       //
     BIT = BIT + String(int(mode/10)-12);        // key read add
     int L = BIT.length();                       //
     if (L==0 | L==1 | L==2){ goto p1;}          // 0,1,2
     if (L>2){BIT = BIT.substring(L-2,L+1);}     //
     p1:                                         //
     myGLCD.setFont(BigFont);                    //
     myGLCD.setColor(255,255,255);               //
     myGLCD.setBackColor(100,100,100);           //
     myGLCD.print(BIT,306,70);                   //
     mode = 4;                                   // key input mode
     }                                           //
   return mode;                                  //  
}                                                //
//=========================================================================
int mkey(int mode){                              // MONITOR KYE INPUT
  if ( mode == 346 ){                            // mode 6 enter action
       myGLCD.setFont(BigFont);                  // Oscillo disp
       myGLCD.setColor(255,255,255);             //  
       myGLCD.setBackColor(100,100,100);         //  
       myGLCD.print(MON,306,70);                 // oscillo bit disp
       myGLCD.setColor(bk,bk,bk);                //
       myGLCD.fillRect(421,6,469,34);            //
       myGLCD.setFont(SmallFont);                // Small Font
       myGLCD.setColor(0,0,0);                   //
       myGLCD.setBackColor(bk,bk,bk);            //
       myGLCD.print(MON,443,15);                 // bit button disp write
       mode = 0;                                 // rx mode
     }                                           //
     else{                                       //
     MON = MON + String(int(mode/10)-32);        // key read add
     int L = MON.length();                       //
     if (L==0 | L==1){ goto p1;}                 // 0,1
     if (L>1){MON = MON.substring(L-1,L+1);}     //
     p1:                                         //
     myGLCD.setFont(BigFont);                    //
     myGLCD.setColor(255,255,255);               //
     myGLCD.setBackColor(100,100,100);           //
     myGLCD.print(MON,306,70);                   //
     mode = 6;                                   // key input mode
     }                                           //
   return mode;                                  //  
}                                                //
//=========================================================================

Written by macsbug

9月 30, 2014 @ 11:28 am

カテゴリー: Arduino

コメントを残す

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

WordPress.com ロゴ

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

Twitter 画像

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

Facebook の写真

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

Google+ フォト

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

%s と連携中

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