Browse Source

采集到三个数值没有做逻辑

master
Yuenold 4 years ago
parent
commit
8bab75a1c5
  1. 31
      APP/adc.c
  2. 5
      APP/adc.h
  3. 913
      project_ozone/Listings/project_o.map
  4. 141
      project_ozone/project_o.uvgui.admin

31
APP/adc.c

@ -1,5 +1,9 @@
#include "adc.h" #include "adc.h"
static adc_t s_adc[] = {0};
static adc_t s_adc[] = {
{.port = "A", .pin = 2},
{.port = "B", .pin = 8},
{.port = "B", .pin = 9},
};
/*********************************************************************************************************************** /***********************************************************************************************************************
* =====================================================adc====================================================== * =====================================================adc======================================================
** **
@ -14,15 +18,18 @@ void ADCInit(uint8_t *port, uint8_t pin) {
y.Dir = GPIO_Direction_Input; // y.Dir = GPIO_Direction_Input; //
y.Func = GPIO_Reuse_Func0; y.Func = GPIO_Reuse_Func0;
// GPIO_Init(GPIO_Pin_B9, &y); // GPIO_Init(GPIO_Pin_B9, &y);
if (pin == 4) {
GPIO_Init(GPIO_Pin_A4, &y);
if (pin == 2) {
GPIO_Init(GPIO_Pin_A2, &y);
x.CHS = ADC_CHS_AIN8; x.CHS = ADC_CHS_AIN8;
printf("A4\r\n");
} else if (pin == 8) { } else if (pin == 8) {
GPIO_Init(GPIO_Pin_B8, &y); GPIO_Init(GPIO_Pin_B8, &y);
x.CHS = ADC_CHS_AIN3; x.CHS = ADC_CHS_AIN3;
printf("B8\r\n");
} else if (pin == 9) { } else if (pin == 9) {
GPIO_Init(GPIO_Pin_B9, &y); GPIO_Init(GPIO_Pin_B9, &y);
x.CHS = ADC_CHS_AIN4; x.CHS = ADC_CHS_AIN4;
printf("B9\r\n");
} }
//Tadclk=1/(PCLK/4)0.083us //Tadclk=1/(PCLK/4)0.083us
@ -43,24 +50,26 @@ void ADCInit(uint8_t *port, uint8_t pin) {
ADC_Init(&x); ADC_Init(&x);
} }
uint16_t get_adc_value(void) {
uint16_t adc_value;
void get_adc_value(void) {
uint16_t adc_value = 0;
for (int i = 0; i < 3; i++) {
ADCInit(s_adc[i].port, s_adc[i].pin);
ADC_SoftStart(); ADC_SoftStart();
while (ADC_GetConvStatus() == SET) while (ADC_GetConvStatus() == SET)
; // ; //
adc_value = ADC_GetConvValue();
s_adc[i].adc_just_now_gather_val = ADC_GetConvValue();
ADC_SoftStop(); ADC_SoftStop();
return adc_value;
record_adc_gather_value(s_adc[i].adc_just_now_gather_val);
//printf("%d\r\n",s_adc[i].adc_just_now_gather_val);
}
} }
void adc_loop_gather(void) { void adc_loop_gather(void) {
static uint32_t adc_ticket = 0; static uint32_t adc_ticket = 0;
uint16_t adc_value = 0;
if (port_haspassedms(adc_ticket) > 500) { if (port_haspassedms(adc_ticket) > 500) {
adc_ticket = get_sys_ticket(); adc_ticket = get_sys_ticket();
adc_value = get_adc_value();
record_adc_gather_value(adc_value);
get_adc_value();
} }
} }

5
APP/adc.h

@ -5,7 +5,7 @@
#include "systick.h" #include "systick.h"
#include "ozone_work.h" #include "ozone_work.h"
void ADCInit(uint8_t *port,uint8_t pin); void ADCInit(uint8_t *port,uint8_t pin);
uint16_t get_adc_value(void);
void get_adc_value(void);
void adc_loop_gather(void); void adc_loop_gather(void);
void beg_average_value(uint16_t *adc_buff); void beg_average_value(uint16_t *adc_buff);
@ -16,6 +16,9 @@ typedef struct {
bool first_detection_abnormal; bool first_detection_abnormal;
uint16_t adc_value_buff[5]; uint16_t adc_value_buff[5];
uint8_t adc_value_count; uint8_t adc_value_count;
uint16_t adc_just_now_gather_val;
uint8_t *port;
uint8_t pin;
}adc_t; }adc_t;
void record_adc_gather_value(uint16_t adc_value); void record_adc_gather_value(uint16_t adc_value);
// typedef struct { // typedef struct {

913
project_ozone/Listings/project_o.map
File diff suppressed because it is too large
View File

141
project_ozone/project_o.uvgui.admin
File diff suppressed because it is too large
View File

Loading…
Cancel
Save