doppler shift / Mbed 2 deprecated 7021ver2

Dependencies:   mbed

main.cpp

Committer:
KINU
Date:
2021-01-04
Revision:
5:3849b0d9fcf8
Parent:
4:9fefb9f18f08

File content as of revision 5:3849b0d9fcf8:

#include "mbed.h"

Serial pc(SERIAL_TX, SERIAL_RX);
Serial device(PA_9,PA_10);
 
 
 #include <stdio.h>
  int Integer_N = 0; 
  int Fractional_N = 0;
  int intbin[7]={0};
  int decbin[14]={0};
  
void binary(int a){ //小数部分
 if(a == Fractional_N){
   for(int i=0;Fractional_N>0;i++){
     decbin[i] = Fractional_N % 2;
     Fractional_N = Fractional_N / 2;
    }
   printf(" 小数部の2進数 = ");
   int l = 15;
   while( l>0 ){
    printf("%d", decbin[--l]);/* 2進数の出力 */
   }
  }else{
   for(int i=0;Integer_N >0;i++){
     intbin[i] = Integer_N % 2;
     Integer_N = Integer_N / 2;
   }
   printf(" 整数部の2進数 = ");
   
   int k = 8;
   while( k>0 ){
   printf("%d", intbin[--k]);
  }
 }
 }
int main(void){
  /* 変数の宣言 */
  float num = 435797271; //calsatから受け取った10進数のデータ
  double n = num * 2 / 19.68; //変換式
  Integer_N = (int)n; //
  Fractional_N = (n - Integer_N)*32768;
 
  binary(Fractional_N);
  binary(Integer_N);
 
  
  printf("\n");
 
  return 0;
}