エレキジャックweb mbed入門 mbed CWデコーダ課題8です。数字とアルファベットに加えて、BT・ARなどの通信記号に対応しました。デコーダ基板が必要です

Dependencies:   mbed

Revision:
0:e516dfe942bc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jul 16 01:08:27 2012 +0000
@@ -0,0 +1,297 @@
+// CW08
+// BT AR taiou
+#include "mbed.h"
+#include "TextLCD0420.h"
+
+#define ON 1
+#define OFF 0
+#define XON 0
+#define XOFF 1
+#define XHI 0
+#define XLOW 1
+#define HI 1
+#define LOW 0
+#define OUBUN 1
+#define WABUN 0
+#define KN 44
+#define AS 33
+#define CT 52
+#define BT 48
+#define AR 41
+#define HH 255
+#define VA 103
+
+DigitalOut mled1(LED1);
+DigitalOut mled2(LED2);
+DigitalOut mled3(LED3);
+DigitalOut mled4(LED4);
+DigitalIn CW(p5);
+DigitalIn SP_SELECT(p6);
+DigitalIn GENGO_MODE(p7);
+DigitalIn GENGO_SELECT(p8);
+
+TextLCD lcd(p24, p25, p26, p27, p28, p29, p30,20,4); // rs, rw, e, d0, d1, d2, d3
+
+int retu,gyou;
+char g2[20],g3[20];
+int init_flag=ON;
+int min_ms,max_ms;
+
+void lcd_scprintf(char pdata){
+  int i;
+  
+  if(init_flag==ON){
+    if(gyou==1){
+      lcd.locate(retu,1);
+      lcd.printf("%c",pdata);
+      retu++;
+      if(retu==20){
+        gyou=2;
+        retu=0;
+      }
+    }
+    else if(gyou==2){
+      lcd.locate(retu,2);
+      lcd.printf("%c",pdata);
+      g2[retu]=pdata;
+      retu++;
+      if(retu==20){
+        retu=0;
+        gyou=3;
+      }
+    }
+    else if(gyou==3){
+      lcd.locate(retu,3);
+      lcd.printf("%c",pdata);
+      g3[retu]=pdata;
+      retu++;
+      if(retu==20){
+        retu=0;
+        gyou=1;
+        for(i=0;i<20;i++){
+          lcd.locate(i,1);
+          lcd.printf("%c",g2[i]);
+        }
+        for(i=0;i<20;i++){
+          lcd.locate(i,2);
+          lcd.printf("%c",g3[i]);
+          g2[i]=g3[i];
+        }
+        lcd.locate(0,3);
+        lcd.printf("                    ");        
+        init_flag=OFF;
+      }
+    }
+  }
+  if(init_flag==OFF){
+      gyou=3;
+      lcd.locate(retu,3);
+      lcd.printf("%c",pdata); 
+      g3[retu]=pdata; 
+      retu++;     
+      if(retu==20){
+        for(i=0;i<20;i++){
+          lcd.locate(i,1);
+          lcd.printf("%c",g2[i]);
+          lcd.locate(i,2);
+          lcd.printf("%c",g3[i]);
+          g2[i]=g3[i];
+        }
+        lcd.locate(0,3);
+        lcd.printf("                    ");
+        retu=0;
+      }
+  }
+}
+
+void set_speed(){
+  if(SP_SELECT==HI){
+    min_ms=30;
+    max_ms=90;
+    lcd.locate(5,0);
+    lcd.printf("H");
+  }
+  else if(SP_SELECT==LOW){
+    min_ms=70;
+    max_ms=210;
+    lcd.locate(5,0);
+    lcd.printf("L");
+  }
+}  
+
+int main() {      
+  
+  int i,j,k;
+  int code[8];
+  int scount;
+  char mj[115];
+  int cw_sum,tan_sum,tanten,cpm;
+  int gengo,gengo_auto;
+  char cw_class;
+  
+  for(i=0;i<115;i++){
+    mj[i]=' ';
+  }
+  mj[5]='A';mj[16]='B';mj[20]='C';mj[8]='D';mj[1]='E';
+  mj[19]='F';mj[10]='G';mj[15]='H';mj[3]='I';mj[29]='J';
+  mj[12]='K';mj[17]='L';mj[6]='M';mj[4]='N';mj[14]='O';
+  mj[21]='P';mj[26]='Q';mj[9]='R';mj[7]='S';mj[2]='T';
+  mj[11]='U';mj[23]='V';mj[13]='W';mj[24]='X';mj[28]='Y';
+  mj[18]='Z';
+  mj[61]='1';mj[59]='2';mj[55]='3';mj[47]='4';mj[31]='5';
+  mj[32]='6';mj[34]='7';mj[38]='8';mj[46]='9';mj[62]='0';
+  mj[105]='.';mj[114]=',';mj[75]='?';mj[48]='=';mj[96]='-';
+  mj[70]=':';mj[93]='\'';mj[44]='(';mj[108]=')';mj[40]='/';
+  mj[85]='@';
+  //mj[41]='+';
+   
+  lcd.cls();
+  lcd.printf("*CW08 ");
+  
+  for(i=0;i<8;i++){
+    code[i]=0;
+  }
+
+  i=0;
+  tan_sum=0;
+  set_speed();
+  
+  while( i<5 ){
+    lcd.locate(7,0);
+    lcd.printf("%2d",5-i);
+    scount=0;
+    while(CW==XLOW){
+    }
+    mled1=ON;
+    while(CW==XHI){
+      scount++;
+      wait_ms(1);
+    }
+    mled1=OFF;
+    if(min_ms < scount && scount < max_ms){
+      tan_sum=tan_sum+scount;
+      i++;
+    }
+    
+  }//while i  
+  
+  tanten=tan_sum/5;    
+  
+  j=0;
+  tan_sum=0;
+  k=0;
+  gyou=1,retu=0;
+  while(1){
+        set_speed();
+        while(CW==XLOW){
+        }       
+        scount=0;  
+        mled1=ON;
+        while(CW==XHI){
+          wait_ms(1);
+          scount++;
+        }
+        mled1=OFF;
+        
+        if(min_ms < scount && scount < max_ms){ 
+          //lcd.printf(".");
+          code[k]=1;
+          k++;
+          tan_sum=tan_sum+scount;
+          j++;
+        }
+
+        else if ( scount > tanten*2.0){
+          //lcd.printf("_");
+          code[k]=2;
+          k++;
+          tan_sum=tan_sum+scount/3;
+          j++;
+        }
+        
+        lcd.locate(7,0);
+        lcd.printf("%2d",k);
+                 
+        scount=0;
+        while(CW==XLOW){
+          wait_ms(1);
+          scount++;
+          if(scount > tanten*10){
+            break;
+          }
+        }
+        
+        if(k>8){
+          k=0;
+          lcd_scprintf('*');
+          for(i=0;i<=7;i++){
+            code[i]=0;
+          }
+        }
+        
+        if(scount > tanten*2.0){      
+          cw_sum=0;
+          for(i=0;i<=7;i++){
+              cw_sum=cw_sum+code[i]*int(pow(2.0,i));
+          }
+          if(cw_sum==BT){
+            lcd_scprintf('[');lcd_scprintf('B');lcd_scprintf('T');lcd_scprintf(']');
+          }
+          else if(cw_sum==KN){
+            lcd_scprintf('[');lcd_scprintf('K');lcd_scprintf('N');lcd_scprintf(']');
+          }
+          else if(cw_sum==AR){
+            lcd_scprintf('[');lcd_scprintf('A');lcd_scprintf('R');lcd_scprintf(']');
+          }
+          else if(cw_sum==HH){
+            lcd_scprintf('[');lcd_scprintf('H');lcd_scprintf('H');lcd_scprintf(']');
+          }
+          else if(cw_sum==AS){
+            lcd_scprintf('[');lcd_scprintf('A');lcd_scprintf('S');lcd_scprintf(']');
+          }
+          else if(cw_sum==CT){
+            lcd_scprintf('[');lcd_scprintf('C');lcd_scprintf('T');lcd_scprintf(']');
+          }
+          else if(cw_sum==VA){
+            lcd_scprintf('[');lcd_scprintf('V');lcd_scprintf('A');lcd_scprintf(']');
+          }
+ 
+          else { 
+            lcd_scprintf(mj[cw_sum]);
+          }
+          k=0;
+          for(i=0;i<=7;i++){
+            code[i]=0;
+          }
+        }//if
+        
+        if(scount > tanten*7){
+          lcd_scprintf(' ');
+        }
+        
+        if(j==10){
+          tanten=tan_sum/10;
+          cpm=60000/(tanten*57)*5;
+          tan_sum=0;
+          j=0;
+          if(cpm > 100){
+            cw_class='P';
+          }
+          else if(cpm > 90){
+            cw_class='S';
+          }
+          else if(cpm > 65){
+            cw_class='1';
+          }
+          else if(cpm > 40){
+            cw_class='2';
+          }
+          else if(cpm > 30){
+            cw_class='3';
+          }
+          lcd.locate(10,0);
+          lcd.printf("%3dc(%c)",cpm,cw_class);
+          //lcd.printf("%3dc,%3dm",cpm,tanten);
+        }
+  }//while 1
+}//main