Browse Source

feature:1.添加新任务:L3_task_Adc_handler

pcb_v2
Zhangwen 4 months ago
parent
commit
21336bba3b
  1. 2
      source/app/app_config.c
  2. 2
      source/app/app_config.h
  3. 10
      source/app/main.c
  4. 1
      source/app/main.h
  5. 62
      source/app/task_adc.c
  6. 34
      source/app/task_adc.h

2
source/app/app_config.c

@ -18,6 +18,8 @@ void L3_param_init(void)
G.tail[0] = TAIL0; G.tail[0] = TAIL0;
G.tail[1] = TAIL1; G.tail[1] = TAIL1;
G.bat_percent = 0;
G.volume = 0x15; G.volume = 0x15;
//U8 i; //U8 i;
G.debug = 1; G.debug = 1;

2
source/app/app_config.h

@ -107,6 +107,8 @@ typedef struct global_param
U8 head[2]; U8 head[2];
U8 tail[2]; U8 tail[2];
// 电量百分比
U8 bat_percent;
// 喇叭音量 // 喇叭音量
U8 volume; U8 volume;
//调试模式 //调试模式

10
source/app/main.c

@ -58,6 +58,9 @@ void L0_TASK_init(void)
//游戏任务初始化 //游戏任务初始化
L3_task_game_init(); L3_task_game_init();
//adc任务初始化
L3_task_Adc_init();
// //游戏任务初始化 // //游戏任务初始化
// L3_task_game_init(); // L3_task_game_init();
// //寄存器监听任务初始化 // //寄存器监听任务初始化
@ -126,12 +129,19 @@ void main(void)
// L0_uart0_0d0a(); // L0_uart0_0d0a();
// L0_uart0_sendstr("oid_p"); // L0_uart0_sendstr("oid_p");
// } // }
// 系统状态任务 // 系统状态任务
L3_task_appstatus_handler(&_s_task_appstatus); L3_task_appstatus_handler(&_s_task_appstatus);
// 系统状态测试任务 // 系统状态测试任务
// L3_task_AppTest_handler(&_s_task_apptest); // L3_task_AppTest_handler(&_s_task_apptest);
// 按键状态任务 // 按键状态任务
L3_task_keystatus_handler(&_s_task_keystatus); L3_task_keystatus_handler(&_s_task_keystatus);
// adc任务
L3_task_Adc_handler(&_s_task_adc);
// OID和WIFI任务 // OID和WIFI任务
if (R.app_status != POW_OFF) if (R.app_status != POW_OFF)
{ {

1
source/app/main.h

@ -75,6 +75,7 @@
#include "../app/task_w600.h" #include "../app/task_w600.h"
#include "../app/task_SmartConfig.h" #include "../app/task_SmartConfig.h"
#include "../app/task_game.h" #include "../app/task_game.h"
#include "../app/task_adc.h"
#include "../bsp/bsp_led.h" #include "../bsp/bsp_led.h"

62
source/app/task_adc.c

@ -0,0 +1,62 @@
#include "../app/task_adc.h"
#include "../msp/msp_adc.h"
#include "../app/app_config.h"
#include "../msp/uart0.h"
S_TASK_ADC _s_task_adc;
void L3_task_Adc_init(void)
{
L1_task_init(&_s_task_adc.task);
_s_task_adc.index = 0;
_s_task_adc.SUM = 0;
L3_task_s_go(_s_task_adc,D_task_init);
}
#define D_task_ADC_READ 0x50
#define D_task_ADC_COUNT 0x51
void L3_task_Adc_handler(S_TASK_ADC *s)
{
TTSS_Task_init()
L2_task_go_Tdelay(D_task_ADC_READ,D_Tdelay_300ms);
TTSS_Task_step(D_task_ADC_READ)
s->adc_val[_s_task_adc.index] = L1_ADC_Read(12);
s->SUM += s->adc_val[_s_task_adc.index++];
if (_s_task_adc.index >= 10)
{
_s_task_adc.index = 0;
L2_task_go_Tdelay(D_task_ADC_COUNT,D_Tdelay_300ms);
}
else
{
L2_task_go_Tdelay(D_task_ADC_READ,D_Tdelay_300ms);
}
TTSS_Task_step(D_task_ADC_COUNT)
// 计算平均值
U16 Aver = s->SUM / ADC_NUM;
// 计算方差
U8 i;
FP32 Variance = 0;
for(i = 0; i < ADC_NUM; i++)
{
Variance += (s->adc_val[i] - Aver) * (s->adc_val[i] - Aver);
}
Variance /= ADC_NUM;
// // 方差合格,计算电量,放到G,不合格丢弃
// if ((U16)(Variance*10) < 2)
// {
// Vin = (Aver / 0x1000) * 3.3;
// Percent = Vin / 4.2
// }
Aver = 0;
L2_task_go_Tdelay(D_task_ADC_READ,D_Tdelay_300ms);
TTSS_Task_end();
}

34
source/app/task_adc.h

@ -0,0 +1,34 @@
////////////////////////////////////////////////////////////////////////////
///@copyright Copyright (c) 2018, 传控科技 All rights reserved.
///-------------------------------------------------------------------------
/// @file bsp_drv.h
/// @brief bsp @ driver config
///-------------------------------------------------------------------------
/// @version 1.0
/// @author CC
/// @date 20180331
/// @note cc_AS_stc02
//////////////////////////////////////////////////////////////////////////////
#ifndef _TASK_ADC_H
#define _TASK_ADC_H
#include "../ctask/task.h"
#define ADC_NUM 10
typedef struct _s_task_adc
{
TS_task task;
U16 adc_val[ADC_NUM];
U8 index;
U16 SUM;
}S_TASK_ADC;
extern S_TASK_ADC _s_task_adc;
extern void L3_task_Adc_init(void);
extern void L3_task_Adc_handler(S_TASK_ADC *s);
#endif // #ifndef
Loading…
Cancel
Save