#include "led.h" #include "delay.h" #include "sys.h" #include "stm32f10x.h" #include "stdio.h" #include "key.h" #include "usart.h" #include "drive_dht11.h" #include "bh1750.h" #include "ds1302.h" #include "oled.h" #include "ds18b20.h" #include "string.h" #include "adc.h" u8 humi=0;//ʪ��ֵ u8 temp=0;//�¶�ֵ u8 buffer[10]={0}; u16 GzVal=0; //ʵ�ʹ���ֵ char ShowBuf[16]={0}; char DateShowBuf[30]={0}; char SendBuff[50]={0}; short TEMP = 0; u16 cj_val=0;//���ֵ u8 openflag=0;//�ֶ�ģʽ���ذ�ť u8 mode_flag=0; #define AM_PIN PCout(13) //��Ħ�������� #define FAN_PIN PCout(14) //���ȿ������� #define ZM_PIN PCout(15) //������������ #define FM_PIN PAout(12) //�������������� #define LED_PIN PAout(11) //��ɫled���� #define SAMPLE_PERIOD 20 // ���β��� #define BUFF_SIZE 50 // ���ݻ�������С typedef enum {FALSE, TRUE} BOOL; uint16_t VitData, LastData; // ��ȡ���� AD ֵ uint16_t timeCount = 0; // �������ڼ������� uint16_t firstTimeCount = 0; // ��һ������ʱ�� uint16_t secondTimeCount = 0; // �ڶ�������ʱ�� /*adjoin_val: ��������������ʱ�䣬bmp_val: ����ֵ�� pulse_val: ����ͼ����ֵ����ʾ*/ uint16_t adjoin_val, bmp_val, pulse_val; uint16_t data[BUFF_SIZE] = {0}; // �������ݻ��� int buf_index = 0; // ���������±� uint16_t max, min, mid; // �����С���м�ֵ uint16_t filter_val; // �˲�ֵ BOOL PULSE = FALSE; // ��Ч���� BOOL PRE_PULSE = FALSE; // ��ǰ��Ч���� uint8_t pulseCount = 0; // �������� uint32_t i; void Print_Wave(void); uint16_t Get_Array_Max(uint16_t * array, uint32_t size); uint16_t Get_Array_Min(uint16_t * array, uint32_t size); u16 Get_ADC_Average_Val(void); u8 warning_cnt=0; u16 GetTimer=0;//�ɼ�ʱ������� u8 dw_val=0;//��λ//����ֵ u8 sc_val=0;//ɫ�� int cnt_s1=2,cnt_f1=0,cnt_m1=0;//ѧϰʱ�� ʱ���� u8 zm_open_flag=0; //�������ر�־λ u8 ln_open_flag=0;//�������ر�־λ u8 am_open_flag=0;//��Ħ u8 off_time_s=22,off_time_f=0;//��ʱ�ر�ʱ�� ʱ�� u8 set_s1=8,set_f1=0; //���� ʱ������ #define RT_INPUT PBin(8)//��������Ӧ #define KEY_GPIO_PROT GPIOA #define KEY1_GPIO_PIN GPIO_Pin_1 #define KEY2_GPIO_PIN GPIO_Pin_2 #define KEY3_GPIO_PIN GPIO_Pin_3 #define KEY4_GPIO_PIN GPIO_Pin_4 #define KEY5_GPIO_PIN GPIO_Pin_5 #define KEY6_GPIO_PIN GPIO_Pin_6 #define KEY7_GPIO_PIN GPIO_Pin_7 #define KEY1_IN GPIO_ReadInputDataBit(KEY_GPIO_PROT,KEY1_GPIO_PIN) #define KEY2_IN GPIO_ReadInputDataBit(KEY_GPIO_PROT,KEY2_GPIO_PIN) #define KEY3_IN GPIO_ReadInputDataBit(KEY_GPIO_PROT,KEY3_GPIO_PIN) #define KEY4_IN GPIO_ReadInputDataBit(KEY_GPIO_PROT,KEY4_GPIO_PIN) #define KEY5_IN GPIO_ReadInputDataBit(KEY_GPIO_PROT,KEY5_GPIO_PIN) #define KEY6_IN GPIO_ReadInputDataBit(KEY_GPIO_PROT,KEY6_GPIO_PIN) #define KEY7_IN GPIO_ReadInputDataBit(KEY_GPIO_PROT,KEY7_GPIO_PIN) void key_gpio_init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC, ENABLE); GPIO_InitStructure.GPIO_Pin = KEY1_GPIO_PIN|KEY2_GPIO_PIN|KEY3_GPIO_PIN|KEY4_GPIO_PIN|KEY5_GPIO_PIN|KEY6_GPIO_PIN|KEY7_GPIO_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(KEY_GPIO_PROT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); } void TIMER3_Int_Init(u16 arr,u16 psc) { TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStrue; NVIC_InitTypeDef NVIC_InitStructure; TIM_TimeBaseInitStrue.TIM_Period=arr; TIM_TimeBaseInitStrue.TIM_Prescaler=psc; TIM_TimeBaseInitStrue.TIM_CounterMode=TIM_CounterMode_Up; TIM_TimeBaseInitStrue.TIM_ClockDivision=TIM_CounterMode_Up; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStrue); TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);//ʹ��TIM3�����ж� //�ж����ȼ�NVIC���� NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3�ж� NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //��ռ���ȼ�0�� NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //�����ȼ�3�� NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ����ʹ�� NVIC_Init(&NVIC_InitStructure); //��ʼ��NVIC�Ĵ��� TIM_Cmd(TIM3, ENABLE); //ʹ��TIMx ������һ���� �ظ���һ����ˢ������ } /* 1,���������붨ʱ��ģ�飬�������������ƿ��� ��ʱ�صƣ���������ʱ�䣬����ʱ�䵽�������ε��챨����������Ҫ����ʵʱʱ��ģ�� 2,�Զ�����ͨ����ť���ƣ��������תģ���Զ����ϡ� 3,���ֲ��Ź���ͨ��������Ƶģ��ʵ�֣�ͨ���������û��ֻ����Ӳ������֡� 4,��Ħ���ܣ�ͨ���ֶ��������ƿ��أ�ͨ������ģ��ʵ�ְ�ĦЧ���� 5,�������¶�ֵ����������¶ȹ��ߣ����ַ�����������з���������ͬʱ��ɫLED������ ������ʪ�ȿ����Ƿ���Ⱥ��ŷ磬��ʵ���¶�ֵС�������¶�ֵʱ���Զ���������˿(����ͨ���̵������Ƽ��ȵ���ʵ��)�� ��ʵ���¶�ֵ��������ֵ��ʵ��ʪ��ֵ��������ʪ��ֵ����ʱ�����ŷ磬����ʹ��С����ʵ�֡� 6 �������ֵ����ʵ��ֵ��������ֵʱ����С������ֵʱ������������������ͬʱLED��˸��\ 7 Һ����ʾ */ u8 set_flag=0;//���ñ�־λ u8 set_ok_flag=1;//������ɱ�־λ u8 temp_L=30,temp_H=37;//�����¶�������ֵ u8 humi_H=0;//ʪ������ֵ u8 xl_L=0,xl_H=120;//��������ֵ int key_Task(void) { static char key_flag=0; if(KEY1_IN==0|KEY2_IN==0|KEY3_IN==0|KEY4_IN==0|KEY5_IN==0|KEY6_IN==0|KEY7_IN==0) { if(key_flag==0) { key_flag=1; if(KEY1_IN==0) { zm_open_flag^=1;//���ؿ����л� } else if(KEY2_IN==0) { ln_open_flag^=1; } else if(KEY3_IN==0) { am_open_flag^=1; } else if(KEY4_IN==0) { if(set_flag++>9) { set_flag=0; } set_ok_flag=0; } else if(KEY5_IN==0) { switch(set_flag) { case 1: if(++off_time_s>23)off_time_s=0; break; case 2: if(++off_time_f>59)off_time_f=0; break; case 3: if(++set_s1>23)set_s1=0; break; case 4: if(++set_f1>59)set_f1=0; break; case 5: if(++temp_L>99)temp_L=0; break; case 6: if(++temp_H>99)temp_H=0; break; case 7: if(++humi_H>99)humi_H=0; break; case 8: if(++xl_L>150)xl_L=0; break; case 9: if(++xl_H>150)xl_H=0; break; case 10: break; } } else if(KEY6_IN==0) { switch(set_flag) { case 1: if(--off_time_s<=0)off_time_s=23; break; case 2: if(--off_time_f<=0)off_time_f=59; break; case 3: if(--set_s1<=0)set_s1=23; break; case 4: if(--set_f1<=0)set_f1=59; break; case 5: if(--temp_L<=0)temp_L=99; break; case 6: if(--temp_H>99)temp_H=99; break; case 7: if(--humi_H<=0)humi_H=99; break; case 8: if(--xl_L<=0)xl_L=150; break; case 9: if(--xl_H<=0)xl_H=150; break; case 10: break; } } else if(KEY7_IN==0) { set_ok_flag=1; } } }else { key_flag=0; } return 20; } u16 DataUpTime=0;//ʱ����ʾ������ u8 rt_flag=0;//���������־λ u16 rt_cnt=0; u8 seccnt=0; //IN1-PA4 #define IN1_GPIO_PORT GPIOB #define IN1_GPIO_CLK RCC_APB2Periph_GPIOB #define IN1_GPIO_PIN GPIO_Pin_12 //IN2-PA5 #define IN2_GPIO_PORT GPIOB #define IN2_GPIO_CLK RCC_APB2Periph_GPIOB #define IN2_GPIO_PIN GPIO_Pin_13 //IN3-PA6 #define IN3_GPIO_PORT GPIOB #define IN3_GPIO_CLK RCC_APB2Periph_GPIOB #define IN3_GPIO_PIN GPIO_Pin_14 //IN1-PA7 #define IN4_GPIO_PORT GPIOB #define IN4_GPIO_CLK RCC_APB2Periph_GPIOB #define IN4_GPIO_PIN GPIO_Pin_15 /* ֱ�Ӳ����Ĵ����ķ�������IO */ #define digitalHi(p,i) {p->BSRR=i;} //���Ϊ�ߵ�ƽ #define digitalLo(p,i) {p->BRR=i;} //����͵�ƽ /* �������IO�ĺ� */ #define IN1_HIGH digitalHi(IN1_GPIO_PORT,IN1_GPIO_PIN) #define IN1_LOW digitalLo(IN1_GPIO_PORT,IN1_GPIO_PIN) #define IN2_HIGH digitalHi(IN2_GPIO_PORT,IN2_GPIO_PIN) #define IN2_LOW digitalLo(IN2_GPIO_PORT,IN2_GPIO_PIN) #define IN3_HIGH digitalHi(IN3_GPIO_PORT,IN3_GPIO_PIN) #define IN3_LOW digitalLo(IN3_GPIO_PORT,IN3_GPIO_PIN) #define IN4_HIGH digitalHi(IN4_GPIO_PORT,IN4_GPIO_PIN) #define IN4_LOW digitalLo(IN4_GPIO_PORT,IN4_GPIO_PIN) void GPIO_Config(void) { /*����һ��GPIO_InitTypeDef���͵Ľṹ��*/ GPIO_InitTypeDef GPIO_InitStructure; /*����������ص�GPIO����ʱ��*/ RCC_APB2PeriphClockCmd( IN1_GPIO_CLK | IN2_GPIO_CLK | IN3_GPIO_CLK | IN4_GPIO_CLK , ENABLE); /*ѡ��Ҫ���Ƶ�GPIO����*/ GPIO_InitStructure.GPIO_Pin = IN1_GPIO_PIN; /*��������ģʽΪͨ���������*/ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /*������������Ϊ50MHz */ GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /*���ÿ⺯������ʼ��GPIO*/ GPIO_Init(IN1_GPIO_PORT, &GPIO_InitStructure); /*ѡ��Ҫ���Ƶ�GPIO����*/ GPIO_InitStructure.GPIO_Pin = IN2_GPIO_PIN; /*���ÿ⺯������ʼ��GPIO*/ GPIO_Init(IN2_GPIO_PORT, &GPIO_InitStructure); /*ѡ��Ҫ���Ƶ�GPIO����*/ GPIO_InitStructure.GPIO_Pin = IN3_GPIO_PIN; /*���ÿ⺯������ʼ��GPIOF*/ GPIO_Init(IN3_GPIO_PORT, &GPIO_InitStructure); /*ѡ��Ҫ���Ƶ�GPIO����*/ GPIO_InitStructure.GPIO_Pin = IN4_GPIO_PIN; /*���ÿ⺯������ʼ��GPIOF*/ GPIO_Init(IN4_GPIO_PORT, &GPIO_InitStructure); //�������ų�ʼ��Ϊ�͵�ƽ IN1_LOW; IN2_LOW; IN3_LOW; IN4_LOW; } void stepper(uint8_t dir,int speed) { if(dir == 1) { IN1_HIGH; delay_ms(speed); IN1_LOW; IN2_HIGH; delay_ms(speed); IN2_LOW; IN3_HIGH; delay_ms(speed); IN3_LOW; IN4_HIGH; delay_ms(speed); IN4_LOW; } else if(dir==2) { IN1_HIGH; delay_ms(speed); IN1_LOW; IN4_HIGH; delay_ms(speed); IN4_LOW; IN3_HIGH; delay_ms(speed); IN3_LOW; IN2_HIGH; delay_ms(speed); IN2_LOW; } } void fanzhuan(void) { int i; for(i = 0;i < 220;i++) //�����ת stepper(2,5); } void zhengzhuan(void) { int i; for(i = 0;i < 220;i++) //�����ת stepper(1,5); } void zhendong_task(void) //��Ħ������ѯ �� - �� - �� -�� ʱ�䲻ͬģ�ⰴĦЧ�� { static uint16_t cnt_time=0;//��ʱ���� ��Ħʱ�� if(am_open_flag) { switch(cnt_time) { case 0: AM_PIN=1;//���� 2S break; case 200: AM_PIN=0;//off 1S break; case 300: AM_PIN=1;//���� break; //3S case 600: AM_PIN=0;//���� break; //1S case 700: AM_PIN=1;//���� break; //4s case 1100: AM_PIN=0;//���� break; //1s case 1200: AM_PIN=1;//���� break; case 1400: AM_PIN=0;//off break; case 1600: cnt_time=0; break; } cnt_time++; }else { cnt_time=0; AM_PIN=0;//�رհ�Ħ ���� } } #define Nx 5 u16 value_buf[Nx]; int Rx_count=0; u16 FILTER_median(char Flag) //��λֵ�˲� ��λֵƽ���˲� NΪ����������ȡ���� Flag:��λֵƽ���˲�ʹ�� ���������˲��õ� { u16 temp=0; long sum=0; int count,i,j; for(j=0;j<Nx-1;j++) //���� { for(i=0;i<Nx-j-1;i++) { if ( value_buf[i] > value_buf[i+1] ) { temp = value_buf[i]; value_buf[i] = value_buf[i+1]; value_buf[i+1] = temp; } } } if(Flag) { for(count=1;count<Nx-1;count++) //��λ��ƽ�� ��Flag��־���� sum+=value_buf[count]; return (sum/(Nx-2)); } else return value_buf[(Nx-1)/2]; //��λֵ } int iCnt =0 ;//������������ u8 CheckCnt=0;//������ char showBuff[16]={0};//Һ����ʾbuff u8 sendbuff[4]={0};//�������ݻ�����buff int val1=0;//��¼���ݱ��� int val2=0;//��¼���ݱ��� u8 Flag1=0;//��¼���ݱ��� void xl_sensor_task(void) { if(++CheckCnt>=2) { LastData = VitData; // ����ǰһ��ֵ VitData = Get_ADC_Average_Val(); // ��ȡADת��ֵ if (((VitData - LastData) < filter_val)&&VitData>1000) // �˳�ͻ�������źŸ��� data[buf_index++] = VitData; // ��仺������ if (buf_index >= BUFF_SIZE) { buf_index = 0; // ������������ͷ���� // ͨ�����������ȡ�����źŵIJ��塢����ֵ���������м�ֵ��Ϊ�ж��ο���ֵ max = Get_Array_Max(data, BUFF_SIZE); min = Get_Array_Min(data, BUFF_SIZE); mid = (max + min)/2; filter_val = (max - min) / 2; } PRE_PULSE = PULSE; // ���浱ǰ����״̬ PULSE = (VitData > mid) ? TRUE : FALSE; // ����ֵ�����м�ֵΪ��Ч���� if (PRE_PULSE == FALSE && PULSE == TRUE) // Ѱ�ҵ����ź�����������м�λ�á��������㣬��һ����Ч���� { pulseCount++; pulseCount %= 2; if(pulseCount == 1) // ���������ĵ�һ�� { firstTimeCount = timeCount; // ��¼��һ������ʱ�� } if(pulseCount == 0) // ���������ĵڶ��� { secondTimeCount = timeCount; // ��¼�ڶ�������ʱ�� timeCount = 0; if ( (secondTimeCount > firstTimeCount)) { adjoin_val = (secondTimeCount - firstTimeCount) * SAMPLE_PERIOD; // ������������������ʱ�䣬�õ� adjoin_val if(iCnt<Nx) { value_buf[iCnt++]=adjoin_val; } if(iCnt==Nx) { val2 = 60000 / FILTER_median(0); // ͨ�� adjoin_val �õ�����ֵ bmp_val if(Flag1==0)//��һ�μ��� { if(val2>20&&val2<150)bmp_val=val2; Flag1=1; }else { if(abs(val2-val1)<20)//��������ֹͻ���������ݶԱ�ǰ�����ε� { if(val2>20&&val2<150)bmp_val=val2; } } // sprintf(showBuff,"BMP:%3d/min",bmp_val);//��ӡ���ַ��� // OLED_ShowString(0,2,showBuff,16);//��ʾ��Һ�� // sendbuff[0]='&';//��ʶ�� ���͵�app������֡ͷ // sendbuff[1]=0;//û������0 // sendbuff[2]=bmp_val;//ʵ���������� // sendbuff[3]=sendbuff[0]+sendbuff[1]+sendbuff[2];//�����У�� // UART3SendBuffer(sendbuff,4);//ͨ��wifi���ڷ���ȥ iCnt=0;//���������� val1=val2;//���汾��ֵ } } } } timeCount++; // ʱ������ۼ� CheckCnt=0; } //delay_ms(20);//��ʱ20ms��ʱ�ٽ�����һ���ڲ��� ����IJ�������50*10=500HZ } void TIM3_IRQHandler(void)//�жϷ������ { if(TIM_GetITStatus(TIM3,TIM_IT_Update)==SET)//SETΪ1 { GetTimer++;//�ɼ������� TIM_ClearITPendingBit(TIM3,TIM_IT_Update); //���TIM3�ĸ����жϱ�־ key_Task();//����ɨ�� DataUpTime++; zhendong_task();//���� xl_sensor_task();//������ʹ��ܺ��� if(rt_flag) //���� ��ʼ��ʱ����ѧϰʱ�� { if(++seccnt>50) { seccnt=0; if(++cnt_m1>59) { cnt_m1=0; if(++cnt_f1>59) { cnt_f1=0; if(++cnt_s1>23) { cnt_s1=0; } } } } } } } u8 GetFlag=0; uint8_t sendBuff[16]={0}; void ShowTo(char* Pdat,char len)//�ַ����еĿո� 0 { char ixd=0; for(ixd=0;ixd<len;ixd++) { if(Pdat[ixd]==' ') { Pdat[ixd]='0'; } } } #define IO_TX_GPIO_Port PAout(7) void uartX_sendByte(uint8_t val) { int i = 0; IO_TX_GPIO_Port=0; delay_us(104); for (i = 0; i < 8; i++) { if (val & 0x01) { IO_TX_GPIO_Port=1; } else { IO_TX_GPIO_Port=0; } delay_us(104); val >>= 1; } IO_TX_GPIO_Port=1; delay_us(104); } u8 test=0; u8 ln_lock_flag=0;//��������������־ short tb_temp=0;//����¶� int main(void) { NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//�����ж����ȼ�����Ϊ��2��2λ��ռ���ȼ���2λ��Ӧ���ȼ� delay_init(); //��ʱ������ʼ�� LED_Init(); //��ʼ�������ӵ�Ӳ���ӿ� uart_init(9600); delay_ms(1000); key_gpio_init(); OLED_Init();//Һ����ʼ�� OLED_Clear();//Һ������ delay_ms(10);//�ϵ���ʱһ�� DS18B20_Init(); Ds1302_Gpio_Init(); Ds1302_Write_Time_All(1); ADC1_Init(); TIMER3_Int_Init(10000,71);//��ʱ����ʼ�� //10ms��һ���ж� while(1) { if(ln_open_flag) //�������� { if(ln_lock_flag==0) //������־ ת��һ�ξ����� { ln_lock_flag=1; zhengzhuan();//���Ƶ�� } }else //�ر����� { if(ln_lock_flag==1) { ln_lock_flag=0; fanzhuan(); } } if(GetTimer>100)//1S { GetTimer=0; if(dht11_read_data(buffer) == 0)//��ȡ��ʪ�� { humi = buffer[0] + buffer[1] / 10;//ȡʪ��ֵ temp = buffer[2] + buffer[3] / 10;//ȡ�¶�ֵ } tb_temp = DS18B20_Get_Temp(); } if(DataUpTime>40) //400msˢ��һ������ { DataUpTime=0;// Ds1302_Readtime(); sprintf((char*)DateShowBuf,"time:%2d:%2d:%2d", (int)ds1302Data.hour, (int)ds1302Data.min, (int)ds1302Data.sec); ShowTo(DateShowBuf,strlen(DateShowBuf)); OLED_ShowString(0,0,(u8*)DateShowBuf,12);//��ʾʵʱʱ�� sprintf((char*)DateShowBuf,"alarm:%2d:%2d", (int)set_s1, (int)set_f1); ShowTo(DateShowBuf,strlen(DateShowBuf)); OLED_ShowString(0,1,(u8*)DateShowBuf,12);//��ʾ����ʱ�� sprintf((char*)DateShowBuf,"off:%2d:%2d", (int)off_time_s, (int)off_time_s);//��ӡ�ַ��� ShowTo(DateShowBuf,strlen(DateShowBuf)); OLED_ShowString(0,2,(u8*)DateShowBuf,12);//��ʾ�ر�ʱ�� sprintf((char*)DateShowBuf,"bmp:%3d L:%3d H%3d", (int)bmp_val,xl_L,xl_H); OLED_ShowString(0,3,(u8*)DateShowBuf,12);//��ʾ����¶� ����ֵ if((ds1302Data.hour==set_s1)&&(ds1302Data.min==set_f1)) //��������ʱ�� { warning_cnt|=0x01;//��Ϊ1 ��Ҫ���� } else { warning_cnt&=~0x01; } if(zm_open_flag) //�ж��Ƿ��������� { ZM_PIN=1; if(ds1302Data.hour==off_time_s&&ds1302Data.min==off_time_s) //��ʱ�ص�ʱ�䵽�� { ZM_PIN=0; zm_open_flag=0;//�����־λ } }else { ZM_PIN=0; } } } } /******************** ADCͨ��2ת������ ************************/ u16 Get_ADC_Average_Val(void) { u8 i,j; u16 buff[10] = {0}; u16 temp; for(i = 0; i < 10; i ++) { /* ��ʼת�� */ buff[i] = Get_Adc(0); //��ȡת����� } /* �Ѷ�ȡֵ�����ݰ���С��������� */ for(i = 0; i < 9; i++) { for(j = 0 ; j < 9-i; j++) { if(buff[j] > buff[j+1]) { temp = buff[j]; buff[j] = buff[j+1]; buff[j+1] = temp; } } } /* ��ƽ��ֵ */ temp = 0; for(i = 1; i < 9; i++) { temp += buff[i]; } return temp/8; } uint16_t Get_Array_Max(uint16_t * array, uint32_t size)//������������������ { uint16_t max = array[0]; uint32_t i; for (i = 1; i < size; i++) { if (array[i] > max) max = data[i]; } return max; } uint16_t Get_Array_Min(uint16_t * array, uint32_t size)//����������������С�� { uint16_t min = array[0]; uint32_t i; for (i = 1; i < size; i++) { if (array[i] < min) min = data[i]; } return min; }