2、将显示UI模块化,单独成文件displayui.c和display_ui.h; 3、将部分功能模块的状态位、标志位变量和配置参数置于congfig.h; 4、将工程程序中的TP3315字符更改SY8835。
208 lines
5.2 KiB
C
208 lines
5.2 KiB
C
/*
|
||
******************************************************************************
|
||
*
|
||
* @file adc.c
|
||
* @brief adc module
|
||
* @ic sy8835
|
||
*
|
||
* @version 1.0
|
||
* @date 2024/11/01 15:00:40
|
||
* @author Alex Xu
|
||
*
|
||
* Copyright (c) 2013-2099,Tkplusemi Technology Co.,Ltd.
|
||
* All Rights Reserved
|
||
*
|
||
* History:
|
||
* Revision Date Author Desc
|
||
* 1.0.0 2024/11/01 Alex build this file
|
||
******************************************************************************/
|
||
/*_____ I N C L U D E S ____________________________________________________*/
|
||
|
||
#include "adc.h"
|
||
#include "system.h"
|
||
#include "sys_tim.h"
|
||
|
||
#if ADC_ENABLE
|
||
|
||
/******************************************************************************\
|
||
Macro definitions
|
||
\******************************************************************************/
|
||
|
||
/******************************************************************************\
|
||
Variables definitions
|
||
\******************************************************************************/
|
||
int8_t ADC_Offset_Error; //ADC Offset Error 校准值寄存器
|
||
|
||
uint8_t ADC_Chn_Num;
|
||
|
||
idata uint16_t Vbat_Adc;
|
||
|
||
idata int16 g_Vpmu_Adc;
|
||
|
||
idata int16 g_Vntc_Adc;
|
||
|
||
uint8_t g_PMU_ADC_Chn;
|
||
|
||
idata uint16_t g_pmu_Adc_Ivol;
|
||
|
||
idata uint16_t g_pmu_Adc_Vin;
|
||
|
||
idata uint16_t g_pmu_Adc_Vpmid;
|
||
|
||
idata uint16_t g_pmu_Adc_Vor;
|
||
|
||
idata uint16_t g_pmu_Adc_Vol;
|
||
|
||
idata uint16_t g_pmu_Adc_Vdd;
|
||
|
||
idata uint16_t g_pmu_Adc_Ivor;
|
||
|
||
/******************************************************************************\
|
||
Functions definitions
|
||
\******************************************************************************/
|
||
/*
|
||
*******************************************************************************
|
||
* void Adc_Init(void)
|
||
*
|
||
* Description : ADC Initialization. --- 系统初始化调用。
|
||
*
|
||
* Arguments : NONE
|
||
|
||
* Returns : NONE
|
||
|
||
* Notes : NONE
|
||
*
|
||
*******************************************************************************
|
||
*/
|
||
void Adc_Init(void)
|
||
{
|
||
SFRADDR = ADC_CTL2; //ADC 2.5V Enable b[7];ADC1 Pullup 100K Enable b[0].
|
||
SFRDATA = 0x81;
|
||
|
||
SFRADDR = MFP_CTL0; //Set P14 As ADC1 For NTC
|
||
SFRDATA |= 0x10;
|
||
|
||
// ExtSfr_Write(ADC_CTL0,0xAB); //0B10101001,0xA9--ADC EN;Average time:16; Single mode; ADC CLK divided by 24=460k
|
||
|
||
ExtSfr_Write(ADC_CTL0, ( ADC_EN | ADC_AVG_NUM_16 | ADC_SINGLE_EN | ADC_CLK_DIV_48 ) ); //0B10101001,0xA9--ADC EN;Average time:16; Single mode; ADC CLK divided by 24=460k
|
||
|
||
SFRADDR = ADC_OFFSET;
|
||
ADC_Offset_Error = SFRDATA;
|
||
}
|
||
|
||
/*
|
||
*******************************************************************************
|
||
* void PMU_ADC_Chn_Data(PMU_ADC_CHANNELS_E pmu_Adc_Chn)
|
||
*
|
||
* Description : 设置相应通道的使能。在主循环中按通道设置各个通道的使能,在中断中获取对应的ADC值,减少主函数的阻塞。
|
||
*
|
||
* Arguments : NONE
|
||
|
||
* Returns : NONE
|
||
|
||
* Notes : NONE
|
||
*
|
||
*******************************************************************************
|
||
*/
|
||
void PMU_ADC_Chn_Data(PMU_ADC_CHANNELS_E pmu_Adc_Chn)
|
||
{
|
||
if( ADC_IntFlag & ADC_PMU_CH0 )
|
||
{
|
||
ADC_IntFlag = ADC_PMU_CH0;
|
||
|
||
g_Vpmu_Adc = ExtSfr_Read(ADC_CH0_L);
|
||
|
||
g_Vpmu_Adc |= (uint16_t)( ( ExtSfr_Read(ADC_CH0_H) & 0x03 ) << 8 );
|
||
|
||
I2cSfr_Write( XSEN_CTRL , ( 0x08 | pmu_Adc_Chn ) ); //Xsen切换通道后需要等待至少100us后ADC再进行采样。
|
||
|
||
g_Vpmu_Adc = ( (int32)( (int16)( g_Vpmu_Adc - ADC_Offset_Error ) ) * 2500 ) >> 10 ; //ADC的LSB = 2500mV / 1024 = 2.44mV
|
||
|
||
if( g_Vpmu_Adc < 0 )
|
||
{
|
||
g_Vpmu_Adc = 0;
|
||
}
|
||
|
||
/*获取xSen对应的ADC值*/
|
||
switch (g_PMU_ADC_Chn)
|
||
{
|
||
case pmu_ADC_IVOL:
|
||
g_pmu_Adc_Ivol = g_Vpmu_Adc >> 2; //采样比例4mV/mA
|
||
break;
|
||
|
||
case pmu_ADC_VBAT:
|
||
Vbat_Adc = g_Vpmu_Adc << 1; //vbat的2分压
|
||
break;
|
||
|
||
case pmu_ADC_VIN:
|
||
g_pmu_Adc_Vin = g_Vpmu_Adc << 3; //vin的8分压
|
||
break;
|
||
|
||
case pmu_ADC_VPMID:
|
||
g_pmu_Adc_Vpmid = g_Vpmu_Adc << 2; //PMID的4分压
|
||
break;
|
||
|
||
case pmu_ADC_VOR:
|
||
g_pmu_Adc_Vor = g_Vpmu_Adc << 2; //vor的4分压
|
||
break;
|
||
|
||
case pmu_ADC_VOL:
|
||
g_pmu_Adc_Vol = g_Vpmu_Adc << 2; //vol的4分压
|
||
break;
|
||
|
||
case pmu_ADC_VDD:
|
||
g_pmu_Adc_Vdd = g_Vpmu_Adc << 1; //vdd的2分压
|
||
break;
|
||
|
||
case pmu_ADC_IVOR:
|
||
g_pmu_Adc_Ivor = g_Vpmu_Adc >> 2; //采样比例4mV/mA
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
g_PMU_ADC_Chn = pmu_Adc_Chn;
|
||
|
||
ADC_CTL1 = ADC_START | ( ADC_CHN_0 ); //ADC Start Enable,Set Channel N Enabel.
|
||
|
||
}
|
||
/*
|
||
*******************************************************************************
|
||
* void ADC_NTC_Data(void)
|
||
*
|
||
* Description : 获取NTC ADC值,ADC1
|
||
*
|
||
* Arguments : NONE
|
||
|
||
* Returns : NONE
|
||
|
||
* Notes : NONE
|
||
*
|
||
*******************************************************************************
|
||
*/
|
||
void ADC_NTC_Data(void)
|
||
{
|
||
if( ADC_IntFlag & ADC_NTC_CH1 ) //获取NTC ADC 码值
|
||
{
|
||
ADC_IntFlag = ADC_NTC_CH1;
|
||
|
||
g_Vntc_Adc = ExtSfr_Read(ADC_CH1_L);
|
||
|
||
g_Vntc_Adc |= (uint16_t)( ( ExtSfr_Read(ADC_CH1_H) & 0x03 ) << 8 );
|
||
|
||
g_Vntc_Adc = g_Vntc_Adc - ADC_Offset_Error ;
|
||
|
||
if( g_Vntc_Adc < 0 )
|
||
{
|
||
g_Vntc_Adc = 0;
|
||
}
|
||
}
|
||
|
||
ADC_CTL1 = ADC_START | ( ADC_CHN_1 ); //ADC Start Enable,Set Channel N Enabel.
|
||
}
|
||
|
||
#endif
|
||
|