Commit e339f97b authored by hu's avatar hu

调整4051驱动方式,弃用联合体用法

parent b743c980
No preview for this file type
This diff is collapsed.
project .intvect 1536
project .text 299052
project .text 298988
project .rodata 412383
project .secinfo 120
project .syscall 6
......
......@@ -248,6 +248,7 @@ void Power_IG_ON_Init(void)
/*5s不按按键计时清零*/
//LongTimeNoKey_Operation_TimeRest();
CD4051B_KL15Init();
Fuel_Consump_K15_Init();
......
/******************************************************************************
文件名:CD4051B.C
功能:实现4051通道切换
编写时间:2021/3/25
******************************************************************************/
#include "CD4051.h"
#include "GPIO.h"
volatile u_CD4051_Input CD4051_Input[ID_MAX];
unsigned char pChannel = 0;
#include "dr7f701441.dvf.h"
void CD4051_Pin_Init(void)
{
CD4051_Input[ID_COM1].Byte = 0x00;
CD4051_Input[ID_COM2].Byte = 0x00;
CD4051_Input[ID_COM3].Byte = 0x00;
CD4051_Input[ID_COM4].Byte = 0x00;
CD4051_Input[ID_COM5].Byte = 0x00;
CD4051_Input[ID_COM6].Byte = 0x00;
CD4051_Input[ID_COM7].Byte = 0x00;
pChannel = 0;
CD4051BChannel CD4051B_CurrentChannel;
CD4051A_A_MCU_OUT = 0;
CD4051A_B_MCU_OUT = 0;
CD4051A_C_MCU_OUT = 0;
}
CD4051CtrStruct CD4051CtrStr[COMTotal][MaxChannel];
uint16_t CD4051B_GeneralCOM_Cache[COMTotal][MaxChannel];
uint16_t CD4051B_GeneralCOM_Value[COMTotal][MaxChannel];
void CD4051_GetInputStatus(unsigned char Channel)
void CD4051B_KL15Init(void)
{
}
uint8_t i, j;
i = 0u;
j = 0u;
// VCCA_EN = 1u;
for (i = 0u; i < COMTotal; i++)
{
for (j = 0u; j < MaxChannel; j++)
{
CD4051CtrStr[i][j].time = 0u;
CD4051CtrStr[i][j].Last = 0u;
CD4051B_GeneralCOM_Cache[i][j] = 0u;
CD4051B_GeneralCOM_Value[i][j] = 0u;
}
}
CD4051B_C_MCU = 0u;
CD4051B_B_MCU = 0u;
CD4051B_A_MCU = 0u;
void CD4051_Choose_Channel(unsigned char Channel)
{
CD4051A_A_MCU_OUT = Channel & 0x01;
CD4051A_B_MCU_OUT = (Channel >> 1) & 0x01;
CD4051A_C_MCU_OUT = (Channel >> 2) & 0x01;
CD4051B_CurrentChannel = 0u;
}
void CD4051_IOStatus(unsigned char Channel)
/****************************************************************************
CD4051B_ChannelSet
CD4051B_C_MCU CD4051B_B_MCU CD4051B_A_MCU Channel ON
0 0 0 0
0 0 1 1
0 1 0 2
0 1 1 3
1 0 0 4
1 0 1 5
1 1 0 6
1 1 1 7
******************************************************************************/
void CD4051B_ChannelSet(CD4051BChannel Ch)
{
if (CD4051A_COM1_MCU_IN)
{
CD4051_Input[ID_COM1].Byte |= (1 << Channel);
}
else
{
CD4051_Input[ID_COM1].Byte &= ~(1 << Channel);
}
if (CD4051A_COM2_MCU_IN)
{
CD4051_Input[ID_COM2].Byte |= (1 << Channel);
}
else
{
CD4051_Input[ID_COM2].Byte &= ~(1 << Channel);
}
if (CD4051A_COM3_MCU_IN)
if (Ch < MaxChannel)
{
CD4051_Input[ID_COM3].Byte |= (1 << Channel);
CD4051B_CurrentChannel = Ch;
CD4051B_C_MCU = (Ch & 0x04u) >> 2u;
CD4051B_B_MCU = (Ch & 0x02u) >> 1u;
CD4051B_A_MCU = Ch & 0x01u;
}
else
{
CD4051_Input[ID_COM3].Byte &= ~(1 << Channel);
;
}
if (CD4051A_COM4_MCU_IN)
{
CD4051_Input[ID_COM4].Byte |= (1 << Channel);
}
else
{
CD4051_Input[ID_COM4].Byte &= ~(1 << Channel);
}
if (CD4051A_COM5_MCU_IN)
{
CD4051_Input[ID_COM5].Byte |= (1 << Channel);
}
else
{
CD4051_Input[ID_COM5].Byte &= ~(1 << Channel);
}
if (CD4051A_COM6_MCU_IN)
{
CD4051_Input[ID_COM6].Byte |= (1 << Channel);
}
else
{
CD4051_Input[ID_COM6].Byte &= ~(1 << Channel);
}
if (CD4051A_COM7_MCU_IN)
}
/****************************************************************************
函数名:CD4051B_ChannelGet
形参:无
返回值:CD4051BChannel 当前通道数
功能:获取当前通道数
******************************************************************************/
CD4051BChannel CD4051B_ChannelGet(void)
{
return CD4051B_CurrentChannel;
}
/****************************************************************************
CD4051B_ReadSignal_Serviece
******************************************************************************/
void CD4051B_ReadSignal_Serviece(void)
{
uint8_t channel = 0u;
channel = CD4051B_ChannelGet();
CD4051B_GeneralCOM_Cache[COM1][channel] = CD4051B_InputGOIO_Com1;
CD4051B_GeneralCOM_Cache[COM2][channel] = CD4051B_InputGOIO_Com2;
CD4051B_GeneralCOM_Cache[COM3][channel] = CD4051B_InputGOIO_Com3;
CD4051B_GeneralCOM_Cache[COM4][channel] = CD4051B_InputGOIO_Com4;
CD4051B_GeneralCOM_Cache[COM5][channel] = CD4051B_InputGOIO_Com5;
CD4051B_GeneralCOM_Cache[COM6][channel] = CD4051B_InputGOIO_Com6;
CD4051B_GeneralCOM_Cache[COM7][channel] = CD4051B_InputGOIO_Com7;
if (channel < (MaxChannel - 1u))
{
CD4051_Input[ID_COM7].Byte |= (1 << Channel);
channel++;
}
else
{
CD4051_Input[ID_COM7].Byte &= ~(1 << Channel);
channel = Channel0;
}
CD4051B_ChannelSet(channel);
}
/****************************************************************************
CD4051B_Debounce_Service
void CD4051_GetInputStatusProc(void)
******************************************************************************/
void CD4051B_Debounce_Service(void)
{
CD4051_IOStatus(pChannel);
pChannel++;
CD4051_Choose_Channel(pChannel);
if (pChannel > 7)
uint8_t comcnt;
uint8_t chcnt;
comcnt = 0u;
chcnt = 0u;
for (comcnt = 0u; comcnt < COMTotal; comcnt++)
{
pChannel = 0;
for (chcnt = 0u; chcnt < MaxChannel; chcnt++)
{
if (CD4051B_GeneralCOM_Cache[comcnt][chcnt] == CD4051CtrStr[comcnt][chcnt].Last)
{
CD4051CtrStr[comcnt][chcnt].time++;
if (CD4051B_GeneralCOM_Cache[comcnt][chcnt] == 1u)
{
if (CD4051CtrStr[comcnt][chcnt].time >= CD4051B_DEBOUNCE_High_CNT)
{
CD4051CtrStr[comcnt][chcnt].time = 0u;
CD4051B_GeneralCOM_Value[comcnt][chcnt] = 1u;
}
else
{
;
}
}
else
{
if (CD4051CtrStr[comcnt][chcnt].time >= CD4051B_DEBOUNCE_Low_CNT)
{
CD4051CtrStr[comcnt][chcnt].time = 0u;
CD4051B_GeneralCOM_Value[comcnt][chcnt] = 0u;
}
else
{
;
}
}
}
else
{
CD4051CtrStr[comcnt][chcnt].time = 0u;
CD4051CtrStr[comcnt][chcnt].Last = CD4051B_GeneralCOM_Cache[comcnt][chcnt];
}
}
}
}
/****************************************************************************
CD4051B_GetComValue
******************************************************************************/
uint16_t CD4051B_GetComValue(uint8_t num, uint8_t ch)
{
return CD4051B_GeneralCOM_Value[num][ch];
}
\ No newline at end of file
This diff is collapsed.
......@@ -127,8 +127,6 @@ void Sys_Run_Mode_2ms_Tasks(void)
Common_Input_Para();
Gauges_Time_Xms_Count(2);
UDS_10ms_Service();
CD4051_GetInputStatusProc();
}
/*============================================================================*/
/*==============================================================================
......@@ -156,6 +154,7 @@ void Sys_Run_Mode_10ms_Tasks(void)
/*表头调度函数 added by yutian*/
UserGaugeSchedule();/*在主循环中调用*/
/*end*/
CD4051B_ReadSignal_Serviece();
Sound_Play_Service();
Can_BusOff_Fun();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment