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

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // CW08
00002 // BT AR taiou
00003 #include "mbed.h"
00004 #include "TextLCD0420.h"
00005 
00006 #define ON 1
00007 #define OFF 0
00008 #define XON 0
00009 #define XOFF 1
00010 #define XHI 0
00011 #define XLOW 1
00012 #define HI 1
00013 #define LOW 0
00014 #define OUBUN 1
00015 #define WABUN 0
00016 #define KN 44
00017 #define AS 33
00018 #define CT 52
00019 #define BT 48
00020 #define AR 41
00021 #define HH 255
00022 #define VA 103
00023 
00024 DigitalOut mled1(LED1);
00025 DigitalOut mled2(LED2);
00026 DigitalOut mled3(LED3);
00027 DigitalOut mled4(LED4);
00028 DigitalIn CW(p5);
00029 DigitalIn SP_SELECT(p6);
00030 DigitalIn GENGO_MODE(p7);
00031 DigitalIn GENGO_SELECT(p8);
00032 
00033 TextLCD lcd(p24, p25, p26, p27, p28, p29, p30,20,4); // rs, rw, e, d0, d1, d2, d3
00034 
00035 int retu,gyou;
00036 char g2[20],g3[20];
00037 int init_flag=ON;
00038 int min_ms,max_ms;
00039 
00040 void lcd_scprintf(char pdata){
00041   int i;
00042   
00043   if(init_flag==ON){
00044     if(gyou==1){
00045       lcd.locate(retu,1);
00046       lcd.printf("%c",pdata);
00047       retu++;
00048       if(retu==20){
00049         gyou=2;
00050         retu=0;
00051       }
00052     }
00053     else if(gyou==2){
00054       lcd.locate(retu,2);
00055       lcd.printf("%c",pdata);
00056       g2[retu]=pdata;
00057       retu++;
00058       if(retu==20){
00059         retu=0;
00060         gyou=3;
00061       }
00062     }
00063     else if(gyou==3){
00064       lcd.locate(retu,3);
00065       lcd.printf("%c",pdata);
00066       g3[retu]=pdata;
00067       retu++;
00068       if(retu==20){
00069         retu=0;
00070         gyou=1;
00071         for(i=0;i<20;i++){
00072           lcd.locate(i,1);
00073           lcd.printf("%c",g2[i]);
00074         }
00075         for(i=0;i<20;i++){
00076           lcd.locate(i,2);
00077           lcd.printf("%c",g3[i]);
00078           g2[i]=g3[i];
00079         }
00080         lcd.locate(0,3);
00081         lcd.printf("                    ");        
00082         init_flag=OFF;
00083       }
00084     }
00085   }
00086   if(init_flag==OFF){
00087       gyou=3;
00088       lcd.locate(retu,3);
00089       lcd.printf("%c",pdata); 
00090       g3[retu]=pdata; 
00091       retu++;     
00092       if(retu==20){
00093         for(i=0;i<20;i++){
00094           lcd.locate(i,1);
00095           lcd.printf("%c",g2[i]);
00096           lcd.locate(i,2);
00097           lcd.printf("%c",g3[i]);
00098           g2[i]=g3[i];
00099         }
00100         lcd.locate(0,3);
00101         lcd.printf("                    ");
00102         retu=0;
00103       }
00104   }
00105 }
00106 
00107 void set_speed(){
00108   if(SP_SELECT==HI){
00109     min_ms=30;
00110     max_ms=90;
00111     lcd.locate(5,0);
00112     lcd.printf("H");
00113   }
00114   else if(SP_SELECT==LOW){
00115     min_ms=70;
00116     max_ms=210;
00117     lcd.locate(5,0);
00118     lcd.printf("L");
00119   }
00120 }  
00121 
00122 int main() {      
00123   
00124   int i,j,k;
00125   int code[8];
00126   int scount;
00127   char mj[115];
00128   int cw_sum,tan_sum,tanten,cpm;
00129   int gengo,gengo_auto;
00130   char cw_class;
00131   
00132   for(i=0;i<115;i++){
00133     mj[i]=' ';
00134   }
00135   mj[5]='A';mj[16]='B';mj[20]='C';mj[8]='D';mj[1]='E';
00136   mj[19]='F';mj[10]='G';mj[15]='H';mj[3]='I';mj[29]='J';
00137   mj[12]='K';mj[17]='L';mj[6]='M';mj[4]='N';mj[14]='O';
00138   mj[21]='P';mj[26]='Q';mj[9]='R';mj[7]='S';mj[2]='T';
00139   mj[11]='U';mj[23]='V';mj[13]='W';mj[24]='X';mj[28]='Y';
00140   mj[18]='Z';
00141   mj[61]='1';mj[59]='2';mj[55]='3';mj[47]='4';mj[31]='5';
00142   mj[32]='6';mj[34]='7';mj[38]='8';mj[46]='9';mj[62]='0';
00143   mj[105]='.';mj[114]=',';mj[75]='?';mj[48]='=';mj[96]='-';
00144   mj[70]=':';mj[93]='\'';mj[44]='(';mj[108]=')';mj[40]='/';
00145   mj[85]='@';
00146   //mj[41]='+';
00147    
00148   lcd.cls();
00149   lcd.printf("*CW08 ");
00150   
00151   for(i=0;i<8;i++){
00152     code[i]=0;
00153   }
00154 
00155   i=0;
00156   tan_sum=0;
00157   set_speed();
00158   
00159   while( i<5 ){
00160     lcd.locate(7,0);
00161     lcd.printf("%2d",5-i);
00162     scount=0;
00163     while(CW==XLOW){
00164     }
00165     mled1=ON;
00166     while(CW==XHI){
00167       scount++;
00168       wait_ms(1);
00169     }
00170     mled1=OFF;
00171     if(min_ms < scount && scount < max_ms){
00172       tan_sum=tan_sum+scount;
00173       i++;
00174     }
00175     
00176   }//while i  
00177   
00178   tanten=tan_sum/5;    
00179   
00180   j=0;
00181   tan_sum=0;
00182   k=0;
00183   gyou=1,retu=0;
00184   while(1){
00185         set_speed();
00186         while(CW==XLOW){
00187         }       
00188         scount=0;  
00189         mled1=ON;
00190         while(CW==XHI){
00191           wait_ms(1);
00192           scount++;
00193         }
00194         mled1=OFF;
00195         
00196         if(min_ms < scount && scount < max_ms){ 
00197           //lcd.printf(".");
00198           code[k]=1;
00199           k++;
00200           tan_sum=tan_sum+scount;
00201           j++;
00202         }
00203 
00204         else if ( scount > tanten*2.0){
00205           //lcd.printf("_");
00206           code[k]=2;
00207           k++;
00208           tan_sum=tan_sum+scount/3;
00209           j++;
00210         }
00211         
00212         lcd.locate(7,0);
00213         lcd.printf("%2d",k);
00214                  
00215         scount=0;
00216         while(CW==XLOW){
00217           wait_ms(1);
00218           scount++;
00219           if(scount > tanten*10){
00220             break;
00221           }
00222         }
00223         
00224         if(k>8){
00225           k=0;
00226           lcd_scprintf('*');
00227           for(i=0;i<=7;i++){
00228             code[i]=0;
00229           }
00230         }
00231         
00232         if(scount > tanten*2.0){      
00233           cw_sum=0;
00234           for(i=0;i<=7;i++){
00235               cw_sum=cw_sum+code[i]*int(pow(2.0,i));
00236           }
00237           if(cw_sum==BT){
00238             lcd_scprintf('[');lcd_scprintf('B');lcd_scprintf('T');lcd_scprintf(']');
00239           }
00240           else if(cw_sum==KN){
00241             lcd_scprintf('[');lcd_scprintf('K');lcd_scprintf('N');lcd_scprintf(']');
00242           }
00243           else if(cw_sum==AR){
00244             lcd_scprintf('[');lcd_scprintf('A');lcd_scprintf('R');lcd_scprintf(']');
00245           }
00246           else if(cw_sum==HH){
00247             lcd_scprintf('[');lcd_scprintf('H');lcd_scprintf('H');lcd_scprintf(']');
00248           }
00249           else if(cw_sum==AS){
00250             lcd_scprintf('[');lcd_scprintf('A');lcd_scprintf('S');lcd_scprintf(']');
00251           }
00252           else if(cw_sum==CT){
00253             lcd_scprintf('[');lcd_scprintf('C');lcd_scprintf('T');lcd_scprintf(']');
00254           }
00255           else if(cw_sum==VA){
00256             lcd_scprintf('[');lcd_scprintf('V');lcd_scprintf('A');lcd_scprintf(']');
00257           }
00258  
00259           else { 
00260             lcd_scprintf(mj[cw_sum]);
00261           }
00262           k=0;
00263           for(i=0;i<=7;i++){
00264             code[i]=0;
00265           }
00266         }//if
00267         
00268         if(scount > tanten*7){
00269           lcd_scprintf(' ');
00270         }
00271         
00272         if(j==10){
00273           tanten=tan_sum/10;
00274           cpm=60000/(tanten*57)*5;
00275           tan_sum=0;
00276           j=0;
00277           if(cpm > 100){
00278             cw_class='P';
00279           }
00280           else if(cpm > 90){
00281             cw_class='S';
00282           }
00283           else if(cpm > 65){
00284             cw_class='1';
00285           }
00286           else if(cpm > 40){
00287             cw_class='2';
00288           }
00289           else if(cpm > 30){
00290             cw_class='3';
00291           }
00292           lcd.locate(10,0);
00293           lcd.printf("%3dc(%c)",cpm,cw_class);
00294           //lcd.printf("%3dc,%3dm",cpm,tanten);
00295         }
00296   }//while 1
00297 }//main