#include "stm32f10x.h"
#include "usart1.h"
#include "adc.h"
#include "math.h"
#include "change.h"
//#include "oled.h"
#include "bsp_led.h"
#include "bsp_key.h"
#include "lcd.h"
#include "delay.h"
extern __IO u16 BUF1[100]; //缓冲1区
extern __IO u16 BUF2[100]; //缓冲2区
/*********************************状态标志位******************************/
u8 MODE_FLAG=0;
u8 MODE_FLAG_CAL=0;
u8 MODE1_START_FLAG=0;
u8 MODE1_FINISH_FLAG=0;
u8 MODE1_CHANGE_FLAG=0;
u8 MODE1_CHANGE_STATE_FLAG=0;
/*********************************ECG数据*********************************/
int ECG_DATA[10500];
u16 ECG_NUM=0;
u16 BMP_ECG=0;
/**********************************DMA标志位******************************/
#define BUF_Entrance 5
#define BUF1_store_Finish 0
#define BUF1_filter_Finish 1
#define BUF2_store_Finish 2
#define BUF2_filter_Finish 3
extern __IO u8 Data_flag;
extern __IO u8 DMA_flag;
#define L 100
#define N 11
#define M 5
__IO u16 i=0,j;
/*********************************滤波器数组*******************************/
__IO float buf_N[N]={0}; //SG平滑滤波数组
__IO float IIR_Filter_Data[100]; //缓存数组,储存滤波之后的时域信号 float类型
__IO float SG_Filter_Data[100]; //SG平滑之后数据
__IO int Send_int_Data[100]; //转换为int类型数据
__IO char Send_char_Data[5]; //发送数组
__IO float w0[3]={0};
__IO float w1[3]={0};
__IO float x0=0,x1=0;
__IO float y0=0,y1=0;
/*******************************SG_Filter*****************************/
//N=11 D=2
const float B[N][N]={
{ 0.580420, 0.377622, 0.209790, 0.076923, -0.020979, -0.083916, -0.111888, -0.104895, -0.062937, 0.013986, 0.125874},
{ 0.377622, 0.278322, 0.193007, 0.121678, 0.064336, 0.020979, -0.008392, -0.023776, -0.025175, -0.012587, 0.013986},
{ 0.209790, 0.193007, 0.173893, 0.152448, 0.128671, 0.102564, 0.074126, 0.043357, 0.010256, -0.025175, -0.062937},
{ 0.076923, 0.121678, 0.152448, 0.169231, 0.172028, 0.160839, 0.135664, 0.096503, 0.043357, -0.023776, -0.104895},
{ -0.020979, 0.064336, 0.128671, 0.172028, 0.194406, 0.195804, 0.176224, 0.135664, 0.074126, -0.008392, -0.111888},
{ -0.083916, 0.020979, 0.102564, 0.160839, 0.195804, 0.207459, 0.195804, 0.160839, 0.102564, 0.020979, -0.083916},
{ -0.111888, -0.008392, 0.074126, 0.135664, 0.176224, 0.195804, 0.194406, 0.172028, 0.128671, 0.064336, -0.020979},
{ -0.104895, -0.023776, 0.043357, 0.096503, 0.135664, 0.160839, 0.172028, 0.169231, 0.152448, 0.121678, 0.076923},
{ -0.062937, -0.025175, 0.010256, 0.043357, 0.074126, 0.102564, 0.128671, 0.152448, 0.173893, 0.193007, 0.209790},
{ 0.013986, -0.012587, -0.025175, -0.023776, -0.008392, 0.020979, 0.064336, 0.121678, 0.193007, 0.278322, 0.377622},
{ 0.125874, 0.013986, -0.062937, -0.104895, -0.111888, -0.083916, -0.020979, 0.076923, 0.209790, 0.377622, 0.580420}
};
/******************************50hz_IIR_Fnotch_Filter**************************/
const float IIR_50Notch_B[3] = {
0.9023977442,
-0.5577124773,
0.9023977442
};
const float IIR_50Notch_A[3] = {
1,
-0.5577124773,
0.8047954884
};
/*****************************0.3Hz_IIR__High_Filter****************************/
const float Gain=0.99468273;
const float IIR_High_B[3]={
1,
-2,
1
};
const float IIR_High_A[3]={
1,
-1.9833718117,
0.9839372834
};
void IIR_Reset()
{
for(i=0;i<3;i--)
{
w0[i]=0;
w1[i]=0;
}
x0=0;
y0=0;
x1=0;
y1=0;
}
void DelayMs(unsigned int ms)
{
unsigned int i;
while(ms--)
{
for(i=0;i<7200;i++);
}
}
void First_filter_buf1(void)
{
for(i=0;i<100;i++)
{
x0=(float)BUF1[i]/4096*3.3-1.23; // 读取转换的AD值
x0=-x0; //电压数值翻转
w0[0]=IIR_50Notch_A[0]*x0-IIR_50Notch_A[1]*w0[1]-IIR_50Notch_A[2]*w0[2];
y0=IIR_50Notch_B[0]*w0[0]+IIR_50Notch_B[1]*w0[1]+IIR_50Notch_B[2]*w0[2];
w1[0]=IIR_High_A[0]*y0-IIR_High_A[1]*w1[1]-IIR_High_A[2]*w1[2];
y1=Gain*(IIR_High_B[0]*w1[0]+IIR_High_B[1]*w1[1]+IIR_High_B[2]*w1[2]);
IIR_Filter_Data[i]=y1; //缓存数组储存滤波之后的信号
w0[2]=w0[1];
w0[1]=w0[0];
w1[2]=w1[1];
w1[1]=w1[0];
}
for(i=0;i<=M;i++) //第0到M,一共M+1个点
{
for(j=0;j<N;j++)
{
SG_Filter_Data[i]=SG_Filter_Data[i]+B[j][i]*IIR_Filter_Data[j];
}
}
for(i=0;i<N;i++) //将数据放入缓存数组中
{
buf_N[0]=buf_N[1];
buf_N[1]=buf_N[2];
buf_N[2]=buf_N[3];
buf_N[3]=buf_N[4];
buf_N[4]=buf_N[5];
buf_N[5]=buf_N[6];
buf_N[6]=buf_N[7];
buf_N[7]=buf_N[8];
buf_N[8]=buf_N[9]; //数据移位
buf_N[9]=buf_N[10];
buf_N[10]=IIR_Filter_Data[i];
}
for(i=M+1;i<L-M;i++) //第M+1到L-1,一共L-M-1个点
{
for(j=0;j<N;j++)
{
SG_Filter_Data[i]=SG_Filter_Data[i]+B[j][M]*buf_N[j];
}
buf_N[0]=buf_N[1];
buf_N[1]=buf_N[2];
buf_N[2]=buf_N[3];
buf_N[3]=buf_N[4];
buf_N[4]=buf_N[5];
buf_N[5]=buf_N[6];
buf_N[6]=buf_N[7];
buf_N[7]=buf_N[8];
buf_N[8]=buf_N[9]; //数据移位
buf_N[9]=buf_N[10];
buf_N[10]=IIR_Filter_Data[i+M];
}
}
void Else_filter_buf1(void)
{
for(i=0;i<100;i++)
{
x0=(float)BUF1[i]/4096*3.3-1.23; // 读取转换的AD值
x0=-x0; //电压数值翻转
w0[0]=IIR_50Notch_A[0]*x0-IIR_50Notch_A[1]*w0[1]-IIR_50Notch_A[2]*w0[2];
y0=IIR_50Notch_B[0]*w0[0]+IIR_50Notch_B[1]*w0[1]+IIR_50Notch_B[2]*w0[2];
w1[0]=IIR_High_A[0]*y0-IIR_High_A[1]*w1[1]-IIR_High_A[2]*w1[2];
y1=Gain*(IIR_High_B[0]*w1[0]+IIR_High_B[1]*w1[1]+IIR_High_B[2]*w1[2]);
IIR_Filter_Data[i]=y1; //缓存数组储存滤波之后的信号
w0[2]=w0[1];
w0[1]=w0[0];
w1[2]=w1[1];
w1[1]=w1[0];
}
for(i=0;i<L;i++) //第0到M,一共M+1个点
{
buf_N[0]=buf_N[1];
buf_N[1]=buf_N[2];
buf_N[2]=buf_N[3];
buf_N[3]=buf_N[4];
buf_N[4]=buf_N[5];
buf_N[5]=buf_N[6];
buf_N[6]=buf_N[7];
buf_N[7]=buf_N[8];
buf_N[8]=buf_N[9]; //数据移位
buf_N[9]=buf_N[10];
buf_N[10]=IIR_Filter_Data[i];
for(j=0;j<N;j++)
{
SG_Filter_Data[i]=SG_Filter_Data[i]+B[j][M]*buf_N[j];
}
}
}
void First_filter_buf2(void)
{
for(i=0;i<100;i++)
{
x0=(float)BUF2[i]/4096*3.3-1.23; // 读取转换的AD值
x0=-x0; //电压数值翻转
w0[0]=IIR_50Notch_A[0]*x0-IIR_50Notch_A[1]*w0[1]-IIR_50Notch_A[2]*w0[2];
y0=IIR_50Notch_B[0]*w0[0]+IIR_50Notch_B[1]*w0[1]+IIR_50Notch_B[2]*w0[2];
w1[0]=IIR_High_A[0]*y0-IIR_High_A[1]*w1[1]-IIR_High_A[2]*w1[2];
y1=Gain*(IIR_High_B[0]*w1[0]+IIR_High_B[1]*w1[1]+IIR_High_B[2]*w1[2]);
IIR_Filter_Data[i]=y1; //缓存数组储存滤波之后的信号
w0[2]=w0[1];
w0[1]=w0[0];
w1[2]=w1[1];
w1[1]=w1[0];
}
for(i=0;i<=M;i++) //第0到M,一共M+1个点
{
for(j=0;j<N;j++)
{
SG_Filter_Data[i]=SG_Filter_Data[i]+B[j][i]*IIR_Filter_Data[j];
}
}
for(i=0;i<N;i++) //将数据放入缓存数组中
{
buf_N[0]=buf_N[1];
buf_N[1]=buf_N[2];
buf_N[2]=buf_N[3];
buf_N[3]=buf_N[4];
buf_N[4]=buf_N[5];
buf_N[5]=buf_N[6];
buf_N[6]=buf_N[7];
buf_N[7]=buf_N[8];
buf_N[8]=buf_N[9]; //数据移位
buf_N[9]=buf_N[10];
buf_N[10]=IIR_Filter_Data[i];
}
for(i=M+1;i<L-M;i++) //第M+1到L-1,一共L-M-1个点
{
for(j=0;j<N;j++)
{
SG_Filter_Data[i]=SG_Filter_Data[i]+B[j][M]*buf_N[j];
}
buf_N[0]=buf_N[1];
buf_N[1]=buf_N[2];
buf_N[2]=buf_N[3];
buf_N[3]=buf_N[4];
buf_N[4]=buf_N[5];
buf_N[5]=buf_N[6];
buf_N[6]=buf_N[7];
buf_N[7]=buf_N[8];
buf_N[8]=buf_N[9]; //数据移位
buf_N[9]=buf_N[10];
buf_N[10]=IIR_Filter_Data[i+M];
}
}
void Else_filter_buf2(void)
{
for(i=0;i<100;i++)
{
x0=(float)BUF2[i]/4096*3.3-1.23; // 读取转换的AD值
x0=-x0; //电压数值翻转
w0[0]=IIR_50Notch_A[0]*x0-IIR_50Notch_A[1]*w0[1]-IIR_50Notch_A[2]*w0[2];
y0=IIR_50Notch_B[0]*w0[0]+IIR_50Notch_B[1]*w0[1]+IIR_50Notch_B[2]*w0[2];
w1[0]=IIR_High_A[0]*y0-IIR_High_A[1]*w1[1]-IIR_High_A[2]*w1[2];
y1=Gain*(IIR_High_B[0]*w1[0]+IIR_High_B[1]*w1[1]+IIR_High_B[2]*w1[2]);
IIR_Filter_Data[i]=y1; //缓存数组储存滤波之后的信号
w0[2]=w0[1];
w0[1]=w0[0];
w1[2]=w1[1];
w1[1]=w1[0];
}
for(i=0;i<L;i++) //第0到M,一共M+1个点
{
buf_N[0]=buf_N[1];
buf_N[1]=buf_N[2];
buf_N[2]=buf_N[3];
buf_N[3]=buf_N[4];
buf_N[4]=buf_N[5];
buf_N[5]=buf_N[6];
buf_N[6]=buf_N[7];
buf_N[7]=buf_N[8];
buf_N[8]=buf_N[9]; //数据移位
buf_N[9]=buf_N[10];
buf_N[10]=IIR_Filter_Data[i];
for(j=0;j<N;j++)
{
SG_Filter_Data[i]=SG_Filter_Data[i]+B[j][M]*buf_N[j];
}
}
}
void send_data(unsigned char ascii_code)
{
USART_SendData(USART1,ascii_code);
while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET){}
}
void getBMP(int length)
{
float bmpnummax = 0;
float bmpnummin = 0;
float bmpavemax = 0;
float bmpavemin = 0;
float bmpfamax = 0;
float bmpfamin = 0;
float BMP=0;
for (i = 0; i < length; i++)
{
if (ECG_DATA[i] >= bmpavemax)
bmpavemax = ECG_DATA[i];
if (ECG_DATA[i] <= bmpavemin)
bmpavemin = ECG_DATA[i];
if (i == length / 5)
{
bmpnummax = bmpnummax + bmpavemax / 5;
bmpnummin = bmpnummin + bmpavemin / 5;
bmpavemax = 0;
bmpavemin = 0;
}
if (i == length / 5 * 2)
{
bmpnummax = bmpnummax + bmpavemax / 5;
bmpnummin = bmpnummin + bmpavemin / 5;
bmpavemax = 0;
bmpavemin = 0;
}
if (i == length / 5 * 3)
{
bmpnummax = bmpnummax + bmpavemax / 5;
bmpnummin = bmpnummin + bmpavemin / 5;
bmpavemax = 0;
bmpavemin = 0;
}
if (i == length / 5 * 4)
{
bmpnummax = bmpnummax + bmpavemax / 5;
bmpnummin = bmpnummin + bmpavemin / 5;
bmpavemax = 0;
bmpavemin = 0;
}
if (i == length - 1)
{
bmpnummax = bmpnummax + bmpavemax / 5;
bmpnummin = bmpnummin + bmpavemin / 5;
bmpavemax = 0;
bmpavemin = 0;
}
}
bmpfamax = bmpnummax * 3 / 5;
bmpfamin = bmpnummin * 3 / 5;
bmpnummax = 0;
bmpnummin = 0;
for (i = 0; i < length; i++)
{
if (ECG_DATA[i] >= bmpnummax)// && tipmax == true)
{
bmpnummax = ECG_DATA[i];
}
if (ECG_DATA[i] <= bmpnummin)//&& tipmin == true)
{
bmpnummin = ECG_DATA[i];
}
if (bmpnummax > bmpfamax)
{
if (ECG_DATA[i] < bmpfamin)
{
BMP++;
bmpnummax = 0;
bmpnummin = 0;
}
}
}
BMP = (60 * BMP / ((float)length * 0.004));
BMP_ECG=BMP;
// BMP = (int)(60 * (float)BMP / ((float)length * 0.004));
}
int main(void)
{
u8 ID=1;
u8 lcd_id[12];
Data_flag=0;
USART1_Config();
//OLED_Init(); //初始化OLED
LCD_Init();
ADC1_Init();
DMA_flag=BUF_Entrance; //初始化DMA缓冲区切换标识位
IIR_Reset();
POINT_COLOR=RED;
sprintf((char*)lcd_id,"LCD ID:%04X",lcddev.id);//将LCD ID打印到lcd_id数组。
//OLED_Clear();
LCD_Clear(WHITE);
/* config the led */
LED_GPIO_Config();
LED0_OFF;
LED1_OFF;
//LED3_OFF;
/*config key*/
Key_GPIO_Config();
// OLED_ShowString(24,0,ASCII16x16,"ECG SYSTEM");
// OLED_ShowString(12,3,ASCII16x16,"K1
OCAL MODE");
// OLED_ShowString(12,5,ASCII16x16,"K1:UPPER MODE");
LCD_ShowString(30,50,200,16,16,"ECG SYSTEM");
LCD_ShowString(30,70,200,16,16,"K0
OCAL MODE");
LCD_ShowString(30,90,200,16,16,"K0:UPPER MODE");
while(1)
{
// if( Key_Scan(GPIOA,GPIO_Pin_1) == KEY_ON )
// {
// LED0_TOGGLE;
// }
if( Key_Scan(GPIOE,GPIO_Pin_4) == KEY_ON )
{
MODE_FLAG=~MODE_FLAG;
MODE1_CHANGE_FLAG =0;
MODE1_FINISH_FLAG=0;
if(MODE_FLAG==0)
{
/*LED0反转*/
LED0_ON;
LED1_OFF;
//LED3_OFF;
MODE_FLAG_CAL=1;
// OLED_Clear();
// OLED_ShowString(24,0,ASCII16x16,"LOCAL MODE");
// OLED_ShowString(32,4,ASCII16x16,"K2:START");
LCD_Clear(WHITE);
LCD_ShowString(30,50,200,16,16,"LOCAL MODE");
LCD_ShowString(30,70,200,16,16,"K2:START");
MODE1_START_FLAG =0;
}
else
{
/*LED0反转*/
LED0_OFF;
LED1_ON;
//LED3_OFF;
MODE_FLAG_CAL=2;
// OLED_Clear();
// OLED_ShowString(24,0,ASCII16x16,"UPPER MODE");
// OLED_ShowString(12,4,ASCII16x16,"CONNECTING...");
LCD_Clear(WHITE);
LCD_ShowString(30,50,200,16,16,"UPPER MODE");
LCD_ShowString(30,70,200,16,16,"CONNECTING...");
MODE1_START_FLAG =0;
}
}
if(MODE_FLAG_CAL==1)
{
if( Key_Scan(GPIOC,GPIO_Pin_13) == KEY_ON )
{
MODE1_START_FLAG =1;
MODE1_FINISH_FLAG=0;
//LED3_ON;
// OLED_Clear();
// OLED_ShowString(8,2,ASCII16x16,"RECEIVING DATA");
// OLED_ShowString(24,4,ASCII16x16,"WAITING...");
LCD_Clear(WHITE);
LCD_ShowString(30,50,200,16,16,"RECEIVING DATA");
LCD_ShowString(30,70,200,16,16,"WAITING...");
}
// if(ECG_NUM >8000&&MODE1_START_FLAG ==1)
// {
// send_data('A');
// }
if(MODE1_START_FLAG ==1)
{
/****************获取标志位,1管道储存完成,处理管道1数据******************/
if(DMA_flag==BUF1_store_Finish)
{
if(ID==1)
{
First_filter_buf1(); //处理缓冲区1的数据
for(i=0;i<L-M;i++)
{
Send_int_Data[i]=(int)(SG_Filter_Data[i]*1000);
int_to_char(Send_int_Data[i],Send_char_Data);
ECG_DATA [ECG_NUM]=Send_int_Data[i];
ECG_NUM++;
if(ECG_NUM>10000)
{
MODE1_START_FLAG =0;
}
}
for(i=10;i<100;i++) //清零操作
{
IIR_Filter_Data[i]=0;
SG_Filter_Data[i]=0;
}
DMA_flag=BUF1_filter_Finish;
ID++;
}
else
{
Else_filter_buf1(); //处理缓冲区1的数据
for(i=0;i<L;i++)
{
Send_int_Data[i]=(int)(SG_Filter_Data[i]*1000);
int_to_char(Send_int_Data[i],Send_char_Data);
ECG_DATA [ECG_NUM]=Send_int_Data[i];
ECG_NUM++;
if(ECG_NUM>10000)
{
MODE1_START_FLAG =0;
}
}
for(i=0;i<L;i++) //清零操作
{
IIR_Filter_Data[i]=0;
SG_Filter_Data[i]=0;
}
DMA_flag=BUF1_filter_Finish;
ID++;
}
}
/****************获取标志位,2管道储存完成,处理管道2数据******************/
if(DMA_flag==BUF2_store_Finish) //缓冲区2存储满
{
if(ID==1)
{
First_filter_buf2(); //处理缓冲区2的数据
for(i=0;i<L;i++)
{
Send_int_Data[i]=(int)(SG_Filter_Data[i]*1000);
int_to_char(Send_int_Data[i],Send_char_Data);
ECG_DATA [ECG_NUM]=Send_int_Data[i];
ECG_NUM++;
if(ECG_NUM>10000)
{
MODE1_START_FLAG =0;
}
}
for(i=0;i<L;i++) //清零操作
{
IIR_Filter_Data[i]=0;
SG_Filter_Data[i]=0;
}
DMA_flag=BUF2_filter_Finish;
ID++;
}
else
{
Else_filter_buf2(); //处理缓冲区2的数
for(i=0;i<100;i++)
{
Send_int_Data[i]=(int)(SG_Filter_Data[i]*1000);
int_to_char(Send_int_Data[i],Send_char_Data);
ECG_DATA [ECG_NUM]=Send_int_Data[i];
ECG_NUM++;
if(ECG_NUM>10000)
{
MODE1_START_FLAG =0;
}
}
for(i=0;i<100;i++) //清零操作
{
IIR_Filter_Data[i]=0;
SG_Filter_Data[i]=0;
}
DMA_flag=BUF2_filter_Finish;
ID++;
}
}
}
/******************************显示波形************************************/
if(ECG_NUM>10000&&MODE1_START_FLAG ==0)
{
// OLED_Clear();
LCD_Clear(WHITE);
//LED3_OFF;
getBMP(10000);
for(i=0;i<10000;i++)
{
ECG_DATA [i]=-(ECG_DATA [i]/32-32);
if(ECG_DATA [i]<0)
ECG_DATA [i]=0;
else if(ECG_DATA [i]>63)
ECG_DATA [i]=63;
}
for(i=0;i<10000-512;i+=100)
{
// OLED_Clear();
LCD_Clear(WHITE);
for(j=0;j<512;j++)
{
LCD_DrawLine(j/4,ECG_DATA [j+i],(j+1)/4,ECG_DATA [j+i+1]);
}
delay_ms(50);
}
ECG_NUM=0;
MODE1_FINISH_FLAG=1;
MODE1_CHANGE_STATE_FLAG=0;
}
if( Key_Scan(GPIOA,GPIO_Pin_1) == KEY_ON&&MODE1_FINISH_FLAG ==1)
{
MODE1_CHANGE_STATE_FLAG=~MODE1_CHANGE_STATE_FLAG;
MODE1_CHANGE_FLAG =1;
}
if(MODE1_CHANGE_FLAG ==1&&MODE1_FINISH_FLAG==1)
{
MODE1_CHANGE_FLAG =0;
if(MODE1_CHANGE_STATE_FLAG==0)
{
for(i=0;i<10000-512;i+=100)
{
// OLED_Clear();
LCD_Clear(WHITE);
for(j=0;j<512;j++)
{
LCD_DrawLine(j/4,ECG_DATA [j+i],(j+1)/4,ECG_DATA [j+i+1]);
}
delay_ms(50);
}
}
else
{
// OLED_Clear();
// OLED_ShowString(32-16,0,ASCII16x16,"ECG DATA");
// OLED_ShowString(24-16,2,ASCII16x16,"NUM:");
// OLED_ShowString(24-16,4,ASCII16x16,"STATE:");
LCD_Clear(WHITE);
LCD_ShowString(30,70,200,16,16,"ECG DATA");
LCD_ShowString(30,90,200,16,16,"NUM:");
LCD_ShowString(30,110,200,16,16,"STATE:");
getBMP(10000);
//OLED_ShowNum(24+32,2,BMP_ECG,4,16);
if(BMP_ECG>400)
{
// OLED_ShowString(24+32-16,2,ASCII16x16,"ERROR");
LCD_ShowString(45,110,200,16,16,"ERROR");
}
else if(BMP_ECG<=400&&BMP_ECG>=0)
{
// OLED_ShowNum(24+32-16,2,BMP_ECG,4,16);
LCD_ShowNum(30,90,BMP_ECG,16,16);
}
if(BMP_ECG>50&&BMP_ECG<300)
{
// OLED_ShowString(24+48-16,4,ASCII16x16,"SAFE");
LCD_ShowString(30,130,200,16,16,"SAFE");
}
else if(BMP_ECG<=50&&BMP_ECG>=0)
{
// OLED_ShowString(24+48-16,4,ASCII16x16,"DANGEROUS");
LCD_ShowString(30,130,200,16,16,"DANGEROUS");
}
else if(BMP_ECG>=300&&BMP_ECG<=400)
{
// OLED_ShowString(24+48-16,4,ASCII16x16,"DANGEROUS");
LCD_ShowString(30,130,200,16,16,"DANGEROUS");
}
else if(BMP_ECG>400)
{
// OLED_ShowString(24+48-16,4,ASCII16x16,"ERROR");
LCD_ShowString(30,130,200,16,16,"DANGEROUS");
}
//OLED_ShowNum(u8 x,u8 y,u16 num,u8 len,u8 size);
}
}
}
if(MODE_FLAG_CAL==2)
{
/****************获取标志位,1管道储存完成,处理管道1数据******************/
if(DMA_flag==BUF1_store_Finish)
{
if(ID==1)
{
First_filter_buf1(); //处理缓冲区1的数据
for(i=0;i<L-M;i++)
{
Send_int_Data[i]=(int)(SG_Filter_Data[i]*1000);
int_to_char(Send_int_Data[i],Send_char_Data);
for(j=0;j<7;j++)
{
send_data(Send_char_Data[j]);
}
}
for(i=10;i<100;i++) //清零操作
{
IIR_Filter_Data[i]=0;
SG_Filter_Data[i]=0;
}
DMA_flag=BUF1_filter_Finish;
ID++;
}
else
{
Else_filter_buf1(); //处理缓冲区1的数据
for(i=0;i<L;i++)
{
Send_int_Data[i]=(int)(SG_Filter_Data[i]*1000);
int_to_char(Send_int_Data[i],Send_char_Data);
for(j=0;j<7;j++)
{
send_data(Send_char_Data[j]);
}
}
for(i=0;i<L;i++) //清零操作
{
IIR_Filter_Data[i]=0;
SG_Filter_Data[i]=0;
}
DMA_flag=BUF1_filter_Finish;
ID++;
}
}
/****************获取标志位,2管道储存完成,处理管道2数据******************/
if(DMA_flag==BUF2_store_Finish) //缓冲区2存储满
{
if(ID==1)
{
First_filter_buf2(); //处理缓冲区2的数据
for(i=0;i<L;i++)
{
Send_int_Data[i]=(int)(SG_Filter_Data[i]*1000);
int_to_char(Send_int_Data[i],Send_char_Data);
for(j=0;j<7;j++)
{
send_data(Send_char_Data[j]);
}
}
for(i=0;i<L;i++) //清零操作
{
IIR_Filter_Data[i]=0;
SG_Filter_Data[i]=0;
}
DMA_flag=BUF2_filter_Finish;
ID++;
}
else
{
Else_filter_buf2(); //处理缓冲区2的数
for(i=0;i<100;i++)
{
Send_int_Data[i]=(int)(SG_Filter_Data[i]*1000);
int_to_char(Send_int_Data[i],Send_char_Data);
for(j=0;j<7;j++)
{
send_data(Send_char_Data[j]);
}
}
for(i=0;i<100;i++) //清零操作
{
IIR_Filter_Data[i]=0;
SG_Filter_Data[i]=0;
}
DMA_flag=BUF2_filter_Finish;
ID++;
}
}
}
}
}
我把AD往右移了两位 电压方面我看有人用STM32VET6做这个也没有用分压电路或者别的电路,我这个STM32ZET6应该也是可以的吧? 感觉是程序的问题
一周热门 更多>