Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
caa45040
Date:
Wed May 12 22:14:44 2021 +0000
Commit message:
stm32l010 soft serial rx 1

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r b98487737435 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed May 12 22:14:44 2021 +0000
@@ -0,0 +1,223 @@
+#include "mbed.h"
+
+//10の割り算 0から1028までは、正しい。主に0から999
+#define DVI10(n) ((n*205)>>11)
+
+//Serial pc(USBTX, USBRX); // tx, rx
+//Serial pc(SERIAL_TX, SERIAL_RX); //767
+//Serial pc(PA_2, PA_3); //010
+//Serial pc(PA_9, PA_10); //010
+
+#define UART_DELAY 96 //  1/9600
+
+DigitalOut TX(PA_2);
+DigitalIn  RX(PA_3);
+//DigitalOut TX(PA_9);
+//DigitalIn  RX(PA_10);
+
+char ch_hex_a_b[5];
+char *ch_hex_a(int l_num)
+{
+    int a,b,c;
+
+    int q=0;
+if(l_num  < 0) { l_num = 0 - l_num; q = 1;} 
+
+    b=DVI10(l_num);
+    c=l_num-(b*10);
+    l_num=b;
+    a=DVI10(l_num);
+    b=l_num-(a*10);
+
+    ch_hex_a_b[0] = '0' + a;
+    ch_hex_a_b[1] = '0' + b;
+    ch_hex_a_b[2] = '0' + c;
+    ch_hex_a_b[3] = 0;
+
+if( q == 1 ) {ch_hex_a_b[0]='-';}
+
+    return(ch_hex_a_b);
+} //ch_hex_a
+
+
+//仮想シリアルへの一文字出力 9600bps
+int pc_putc(char ch) {
+        
+    TX=1;
+    TX=0;//START
+    wait_us(UART_DELAY);
+
+    for(int ii=0;ii<8;ii++){
+        TX=(ch>>ii)&1;
+        wait_us(UART_DELAY);
+    }; //for
+
+    TX=1;//Stop
+    wait_us(UART_DELAY);
+             
+    return(0);
+    
+} //pc_putc
+
+//文字列の表示
+int pc_printf(char *str1) {
+
+    int ii = 0; //ループカウンター
+    while(str1[ii]!=0){
+            
+        //一文字出力
+        pc_putc(str1[ii]);ii++;
+                        
+    } //while
+
+    //戻り値
+    return(0);
+}
+
+//タイマーの定義
+Timer t;
+
+int a,b,c,d,e,f,g,h;
+int bs;
+int zt,at,bt,ct,dt,et,ft,gt,ht,it;
+char *ret1="\r\n";
+
+
+int pc_getc()
+{
+
+    //待ちループ
+    while( RX == 1 ) {} 
+
+//llllllllllllllllllllllllllllllllllllllll
+
+    zt = t.read_us();
+
+    wait_us(156-7-12);
+
+    a=RX;
+    at = t.read_us();
+
+    wait_us(104-7-11);
+
+    b=RX;
+    bt = t.read_us();
+
+    wait_us(104-7-11);
+
+    c=RX;
+    ct = t.read_us();
+
+    wait_us(104-7-11);
+
+    d=RX;
+    dt = t.read_us();
+    
+    wait_us(104-7-10);
+    
+//hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh   
+    
+    e=RX;
+    et = t.read_us();
+
+    wait_us(104-7-11);
+
+    f=RX;
+    ft = t.read_us();
+
+    wait_us(104-7-12);
+
+    g=RX;
+    gt = t.read_us();
+
+    wait_us(104-7-11);
+
+    h=RX;
+    ht = t.read_us();
+
+    wait_us(156-7-11);
+
+    it = t.read_us();
+    
+//pc_printf(ret1);
+//pc_printf("0    zt=");
+//pc_printf(  ch_hex_a(zt)  );
+//pc_printf(ret1);
+
+//pc_printf("156  at=");
+//pc_printf(  ch_hex_a( 156  - (at-zt) )  );
+//pc_printf(ret1);
+
+//pc_printf("260  bt=");
+//pc_printf(  ch_hex_a( 260  - (bt-zt) )  );
+//pc_printf(ret1);
+
+//pc_printf("364  ct=");
+//pc_printf(  ch_hex_a( 364  - (ct-zt) )  );
+//pc_printf(ret1);
+
+//pc_printf("468  dt=");
+//pc_printf(  ch_hex_a( 468  - (dt-zt) )  );
+//pc_printf(ret1);
+
+//pc_printf("572  et=");
+//pc_printf(  ch_hex_a( 572  - (et-zt) )  );
+//pc_printf(ret1);
+
+//pc_printf("677  ft=");
+//pc_printf(  ch_hex_a( 677  - (ft-zt) )  );
+//pc_printf(ret1);
+
+//pc_printf("781  gt=");
+//pc_printf(  ch_hex_a( 781  - (gt-zt) )  );
+//pc_printf(ret1);
+
+//pc_printf("885  ht=");
+//pc_printf(  ch_hex_a( 885  - (ht-zt) )  );
+//pc_printf(ret1);
+
+//pc_printf("1041 it=");
+//pc_printf(  ch_hex_a( 1041 - (it-zt) )  );
+//pc_printf(ret1);
+
+    //h=0; g=1; f=0; e=0; d=0; c=0; b=0; a=1;
+
+    bs=h*128+g*64+f*32+e*16+d*8+c*4+b*2+a;
+
+    //char str2[2]={ bs ,0};
+    //pc_printf("     ch=[");
+    //pc_printf(  str2  );
+    //pc_printf(ret1);
+
+    return(bs);
+}//pc_getc
+
+int main()
+{
+    RX.mode( PullUp );   //  内蔵プルアップを使う
+    
+    //タイマーの開始
+    t.start();
+    //pc.printf("Hello World!\r\n");
+    //t.stop();
+
+    char ch;
+    
+    while(1) {
+
+        t.reset();
+
+        ch = pc_getc();
+        
+        char str2[2]={ ch ,0};
+        pc_printf("-----ch=[");
+        pc_printf(  str2  );
+        pc_printf(ret1);
+
+
+        wait(1.0);
+    }//while
+}//main
+
+//容量削減
+void error(const char* format, ...){}
diff -r 000000000000 -r b98487737435 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed May 12 22:14:44 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/2e9cc70d1897
\ No newline at end of file