エレキジャックweb mbed入門 mbed CWデコーダ課題9です。英数字に加えて、和文にスイッチで切り替えることで対応します。デコーダ基板が必要です

Dependencies:   mbed

Revision:
0:4a234ad277bf
diff -r 000000000000 -r 4a234ad277bf main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jul 16 02:33:03 2012 +0000
@@ -0,0 +1,371 @@
+// CW09
+// BT AR 
+// Wabun 
+// Switch kirikae
+
+#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 AUTO 1
+#define MANUAL 0
+#define KN 44
+#define AS 33
+#define CT 52
+#define BT 48
+#define AR 41
+#define HH 255
+#define VA 103
+#define HORE 120
+
+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");
+  }
+}
+
+void lcd_alpha(){
+  lcd.locate(7,0);
+  lcd.printf("A");
+}
+void lcd_kana(){
+  lcd.locate(7,0);
+  lcd.printf("%c",0xb6);                 
+}    
+      
+int main() {      
+  
+  int i,j,k;
+  int code[8];
+  int scount;
+  char mj[115],mjj[121],c1,c2;
+  int cw_sum,tan_sum,tanten,cpm;
+  int gengo,wabun_temp;
+  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]='+';
+  
+  for(i=0;i<121;i++){
+    mjj[i]=' ';
+  }
+  mjj[58]=0xb1;mjj[5]=0xb2;mjj[11]=0xb3;mjj[60]=0xb4;mjj[33]=0xb5;//a 
+  mjj[17]=0xb6;mjj[36]=0xb7;mjj[23]=0xb8;mjj[28]=0xb9;mjj[30]=0xba;//ka
+  mjj[52]=0xbb;mjj[42]=0xbc;mjj[54]=0xbd;mjj[45]=0xbe;mjj[22]=0xbf;//sa
+  mjj[4]=0xc0;mjj[19]=0xc1;mjj[21]=0xc2;mjj[57]=0xc3;mjj[35]=0xc4;//ta 
+  mjj[9]=0xc5;mjj[20]=0xc6;mjj[15]=0xc7;mjj[26]=0xc8;mjj[27]=0xc9;//na
+  mjj[16]=0xca;mjj[50]=0xcb;mjj[18]=0xcc;mjj[1]=0xcd;mjj[8]=0xce;//ha
+  mjj[24]=0xcf;mjj[51]=0xd0;mjj[2]=0xd1;mjj[48]=0xd2;mjj[40]=0xd3;//ma
+  mjj[13]=0xd4;mjj[56]=0xd5;mjj[6]=0xd6;//ya
+  mjj[7]=0xd7;mjj[10]=0xd8;mjj[44]=0xd9;mjj[14]=0xda;mjj[25]=0xdb;//ra 
+  mjj[12]=0xdc;mjj[49]=0xb2;mjj[37]=0xb4;mjj[29]=0xa6;mjj[41]=0xdd;//wa
+  mjj[53]=0xb0;mjj[43]=0xdf;mjj[105]=',';
+  mjj[3]=0xde;mjj[73]=0xa3; 
+  mjj[108]='(';mjj[81]=')';
+  mjj[61]='1';mjj[59]='2';mjj[55]='3';mjj[47]='4';mjj[31]='5';
+  mjj[32]='6';mjj[34]='7';mjj[38]='8';mjj[46]='9';mjj[62]='0';
+   
+  lcd.cls();
+  lcd.printf("*CW09 ");
+  
+  for(i=0;i<8;i++){
+    code[i]=0;
+  }
+
+  i=0;
+  tan_sum=0;
+  set_speed();
+  c1=' ',c2=' ';
+  
+  while( i<5 ){//initialize
+    lcd.locate(8,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;
+  k=0;
+  tan_sum=0;
+  gyou=1,retu=0;
+  gengo=OUBUN;
+  wabun_temp=OUBUN;
+  while(1){
+        set_speed();
+
+        if(GENGO_SELECT==WABUN){
+          gengo=WABUN;
+          
+        }
+        else if(GENGO_SELECT==OUBUN){
+          gengo=OUBUN;
+ 
+        }
+        
+        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(8,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(gengo==OUBUN &&  scount > tanten*2.0){
+          lcd_alpha();
+          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 if(cw_sum > 115){
+            lcd_scprintf('*');
+            cw_sum=0;
+          }
+          else { 
+            lcd_scprintf(mj[cw_sum]);
+          }
+          
+          k=0;
+          for(i=0;i<=7;i++){
+            code[i]=0;
+          }
+        }//if oubun        
+        
+        else if(gengo==WABUN && scount > tanten*2.0){
+          lcd_kana();
+          cw_sum=0;
+          for(i=0;i<=7;i++){
+              cw_sum=cw_sum+code[i]*int(pow(2.0,i));
+          }
+
+          if(cw_sum > 121){
+            cw_sum=0;
+            lcd_scprintf(' ');
+          }
+          
+          lcd_scprintf(mjj[cw_sum]);
+          
+          k=0;
+          for(i=0;i<=7;i++){
+            code[i]=0;
+          }
+        }//if wabun
+        
+        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(11,0);
+          lcd.printf("%3dc(%c)",cpm,cw_class);
+          //lcd.printf("%3dc,%3dm",cpm,tanten);
+        }
+  }//while 1
+}//main