⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wind_routines.c

📁 lpc2138读写SD卡的fat文件系统
💻 C
字号:
/******************************************************************************/
/*  This file is part of the kp development                                   */
/*  Copyright kp                                                              */
/******************************************************************************/
/*                                                                            */
/*  wind routines                                       */
/*                                                                            */
/******************************************************************************/

#include <LPC213x.H>                     // LPC21xx definitions
#include <bsp.h>                           // include board support package
#include <math.h>

float wind_dir_ave;

// read wind direction bits
int read_wind_dir_bits() {
  int x;
    x = IOPIN0;
    x = x >> 20;
    x = x & 0x00000007;
  return(x); 
}

// Read wind direction
float wind_dir (void) {
  float azmith[8] = {225.0,270.0,315.0,0.0,45.0,90.0,135.0,180.0};
  float tmp;
  tmp = azmith[read_wind_dir_bits()];
// calculate wind direction in degrees 0-> North, 90-> E, etc.
// read io_address and strip out the three bits.
// Average reading and calulate angle
// wind_dir_ave = ((wind_dir_ave*4) + tmp)/5;
   wind_dir_ave = tmp;
  return(wind_dir_ave);
}

double wind_speed (unsigned int filterred_data) {
  double speed, x, X;
  // Get period from interrupt routine and calculate speed.
  // Interrupt routine averages the data.
  // Calculate wind_speed in MPH
  // Anomometer calibration equation is
  // f(X) = function of freqency	// curve fit equation
  // (24.342758-0.008535973*X+7.410868e-7*X^2), Where X=x^0.5
  double const A = 24.342758;
  double const B = 0.008535973;
  double const C = 7.410868e-7;
  x=(double)filterred_data; // need to capture current value
  							// before interrupt routine modifies
  X=pow(x,0.5);
  speed=(A-B*X+C*X*X);
  if (speed < 0.0) speed = 0.0;
  if (filterred_data > 40000000) speed = 0.0;
  return(speed);
}

float air_temp (void) {
// This routine will read the A/D for temperature.
// The readings are avaeraged.
// The retuned value if in degrees F 
  return (0.0);
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -