Commit 2484ba45 authored by 崔立宝's avatar 崔立宝

变更前文件

parent 8bc61ac0
This diff is collapsed.
This diff is collapsed.
#define GLOBALS_API_ATD
#include "../App_Headers/includes.h"
/*-------------------------------------------------------------------------
* Function Name : ATD_INIT
* Description : AD转化初始化
* Input :
* Output : None
* Return : None
* onther :
--------------------------------------------------------------------------*/
void Api_ATD_Init(void)
{
ATDCTL0 = Disable;
ATDCTL1_ETRIGSEL = Disable;
ATDCTL1_SRES = True; //10位精度
ATDCTL1_SMP_DIS = Disable; //
ATDCTL1_ETRIGCH = 0; //转化通道初始化
ATDCTL2_AFFC = Disable; //分别清除每一个 CCFX标志位用写1的方式
ATDCTL2_ICLKSTP = Enable; //使能停止模式
ATDCTL2_ETRIGE = Disable; //外部触发禁止
ATDCTL2_ASCIE = Disable; //禁止转化中断
ATDCTL2_ACMPIE = Disable; //禁止比较中断
ATDCTL3_DJM = Enable; //右对齐
ATDCTL3_S1C = 1; //转化长度3
ATDCTL3_S2C = 0;
ATDCTL3_S4C = 0;
ATDCTL3_S8C = 0;
ATDCTL3_FIFO = Disable; //不是FIFO模式 并且各自的结果放在各自的寄存器 ATDDRx
ATDCTL3_FRZ = Disable; //冻结模式继续运行
ATDCTL4_SMP = SMP_TIME; //采样时间 4 CYCLE
ATDCTL4_PRS = SMP_PRE; //
ATDCTL5_SC = Disable; //
ATDCTL5_Cx = CHNAL7;
ATDDIEN = 0x0C; //控制个别AD管脚作为通用管脚输入
ATDCTL5_SCAN = Enable; //
ATDCTL5_MULT = 0; //
}
/*-------------------------------------------------------------------------
* Function Name : Api_ADDelay
* Description :
* Input :
* Output : None
* Return : None
* onther : Delay1ms
--------------------------------------------------------------------------*/
INT8U Api_ADDelay(INT16U time)
{
INT16U i,b;
b = time;
for(i = 0;i<= b;i++)
{
asm(NOP;);
_FEED_COP();
}
return True;
}
/*-------------------------------------------------------------------------
* Function Name : Api_GetSensorAD glz--20170519
* Description : 提取AD值 24v
* Input :
* Output : None
* Return : None
* onther :
--------------------------------------------------------------------------*/
void Api_GetSensorAD(void)
{
INT8U AD_STATUS;
AD_STATUS = ATDSTAT0;
if((AD_STATUS & 0x80) == 0x80)
{
ATDSTAT0_SCF = ClearFlag;
switch(ATDCTL5_Cx)
{
case CHNAL7:
if(ADEveArry.pKey > ADEveLen -1)
{
ADEveArry.pKey = null;
}
w = ATDDR0;
wVcc= ATDDR0;
ADEveArry.KeyEven[ADEveArry.pKey] = (INT16U)w;
ADEveArry.pKey ++;
App_SortNByte((INT16U *)ADEveArry.KeyEven,ADEveLen);
if(w > 420) //16.6v
{
ATDCTL5_Cx = CHNAL4;
ADEveArry.KeyOffCn = null;
if(ADEveArry.KeyOnCn < 20)
{
if(Api_ADDelay(Delay1ms))
{
ADEveArry.KeyOnCn ++;
}
}
if(ADEveArry.KeyOnCn >= 0)
{
Curkeyinput = KeyON;
}
}
else
{
ADEveArry.KeyOnCn = null;
if(ADEveArry.KeyOffCn < 100)
{
if(Api_ADDelay(Delay1ms))
{
ADEveArry.KeyOffCn ++;
}
}
if(ADEveArry.KeyOffCn >= 30)
{
Curkeyinput = KeyOFF;
}
ATDCTL5_Cx = CHNAL7;
}
break;
case CHNAL4:
if(Curkeyinput == KeyON)
{
if(ADEveArry.pFuel > ADEveLen-1)
{
ADEveArry.pFuel = null;
}
ADEveArry.FuelEven[ADEveArry.pFuel] = ATDDR0;
ADEveArry.pFuel ++;
if(ADEveArry.pFuel % 2 == null)
{
ATDCTL5_Cx = CHNAL5;
}
else
{
ATDCTL5_Cx = CHNAL4;
}
App_SortNByte((INT16U *)ADEveArry.FuelEven,ADEveLen);
}
else
{
w = ATDDR0;
ATDCTL5_Cx = CHNAL7;
}
break;
case CHNAL5:
if(Curkeyinput == KeyON)
{
if(ADEveArry.pQY2 > ADEveLen-1)
{
ADEveArry.pQY2 = null;
}
ADEveArry.QY2Even[ADEveArry.pQY2] = ATDDR0;
ADEveArry.pQY2 ++;
if(ADEveArry.pQY2 % 2 == null)
{
ATDCTL5_Cx = CHNAL6;
}
else
{
ATDCTL5_Cx = CHNAL5;
}
App_SortNByte((INT16U *)ADEveArry.QY1Even,ADEveLen);
}
else
{
w = ATDDR0;
ATDCTL5_Cx = CHNAL7;
}
break;
case CHNAL6:
if(Curkeyinput == KeyON)
{
if(ADEveArry.pQY1 > ADEveLen-1)
{
ADEveArry.pQY1 = null;
}
ADEveArry.QY1Even[ADEveArry.pQY1] = ATDDR0;
ADEveArry.pQY1 ++;
if(ADEveArry.pQY1 % 2 == null)
{
ATDCTL5_Cx = CHNAL0;
}
else
{
ATDCTL5_Cx = CHNAL6;
}
App_SortNByte((INT16U *)ADEveArry.QY1Even,ADEveLen);
}
else
{
w = ATDDR0;
ATDCTL5_Cx = CHNAL7;
}
break;
//离合踏板1
case CHNAL0:
if(Curkeyinput == KeyON)
{
if(ADEveArry.pClutch1 > ADEveLen-1)
{
ADEveArry.pClutch1 = null;
}
ADEveArry.ClutchEven1[ADEveArry.pClutch1] = ATDDR0;
ADEveArry.pClutch1 ++;
if(ADEveArry.pClutch1 % 2 == null)
{
ATDCTL5_Cx = CHNAL1;
}
else
{
ATDCTL5_Cx = CHNAL0;
}
App_SortNByte((INT16U *)ADEveArry.ClutchEven1,ADEveLen);
}
else
{
w = ATDDR0;
ATDCTL5_Cx = CHNAL7;
}
break;
//离合踏板2
case CHNAL1:
if(Curkeyinput == KeyON)
{
if(ADEveArry.pClutch2 > ADEveLen-1)
{
ADEveArry.pClutch2 = null;
}
ADEveArry.ClutchEven2[ADEveArry.pClutch2] = ATDDR0;
ADEveArry.pClutch2 ++;
if(ADEveArry.pClutch2 % 2 == null)
{
ATDCTL5_Cx = CHNAL7;
}
else
{
ATDCTL5_Cx = CHNAL1;
}
App_SortNByte((INT16U *)ADEveArry.ClutchEven2,ADEveLen);
}
else
{
w = ATDDR0;
ATDCTL5_Cx = CHNAL7;
}
break;
default:
ATDCTL5_Cx = CHNAL7;
}
}
}
\ No newline at end of file
This diff is collapsed.
#define GLOBALS_API_DFLASH
#include "../App_Headers/includes.h"
/*-------------------------------------------------------------------------
* Function Name : Api_Flash_Init
* Description : FLASH初始化
* Input : None
* Output : None
* Return : None
* onther :
--------------------------------------------------------------------------*/
void Api_Flash_Init(void)
{
FCNFG = Disable; //禁止完成中断
FERCNFG = Disable; //禁止错误中断
if(false != FERSTAT)
{
FERSTAT = 0x03;
}
if(false == FCLKDIV_FDIVLD)
{
if(True == FCLKDIV_FDIVLCK)
{
FCLKDIV_FDIVLCK = Disable; //开启改写时钟Flash时钟分频
}
FCLKDIV_FDIV = 32; //10
FCLKDIV_FDIVLCK = Enable; //禁止改写时钟Flash时钟分频
}
}
/*-------------------------------------------------------------------------
* Function Name : Api_Flash_byte_read
* Description : 读取字节
* Input : None
* Output : None
* Return : None
* onther :
--------------------------------------------------------------------------*/
INT8U Api_Flash_byte_read(INT16U _addr)
{
return *(INT8U *)_addr;
}
/*-------------------------------------------------------------------------
* Function Name : Api_DFlashCommSequence
* Description : DFlash命令序列
* Input : bCommandCounter
* Output : None
* Return : None
* onther :
--------------------------------------------------------------------------*/
INT8U Api_DFlashCommSequence(INT8U bCommandCounter)
{
INT8U bCounter;
INT32U dwDelay;
if(MaxDFlashCommandCounter <= bCommandCounter)
{
return RunParameterErr;
}
//检测命令完成
dwDelay = null;
while(!FSTAT_CCIF)
{
dwDelay++;
if(dwDelay > MaxDelayTime)
{
bReturn = RunOverTimeErr;
break;
}
}
//命令正常完成
if(dwDelay < MaxDelayTime)
{
//清零ACCERR和FPVIOL标志
if((True == FSTAT_FPVIOL) ||
(True == FSTAT_ACCERR))
{
FSTAT = (FSTAT_FPVIOL_MASK | FSTAT_ACCERR_MASK);
}
//装载命令
for(bCounter = 0; bCounter <= bCommandCounter; bCounter++)
{
FCCOBIX = bCounter;
FCCOB = FlashCommandArray[bCounter];
}
FSTAT_CCIF = True; //启动命令
//检测命令完成
dwDelay = 0;
while(!FSTAT_CCIF)
{
dwDelay++;
if(dwDelay > MaxDelayTime)
{
bReturn = RunOverTimeErr;
break;
}
}
if(dwDelay < MaxDelayTime)
{
if(false != FSTAT_ACCERR)
{
bReturn = RunErrACCERR;
}
else
{
if(false != FSTAT_FPVIOL)
{
bReturn = RunErrFPVIOL;
}
else
{
if(false != FSTAT_MGSTAT1)
{
bReturn = RunErrMGSTAT1;
}
else
{
if(false != FSTAT_MGSTAT0)
{
bReturn = RunErrMGSTAT0;
}
}
}
}
}
}
return(bReturn);
}
/*-------------------------------------------------------------------------
函数名称:Api_DFlashEraseSector
功 能:DFlash扇区擦除
参 数:wDestination
返回数值:
使用说明:
--------------------------------------------------------------------------*/
INT8U Api_DFlashEraseSector(INT16U wDestination)
{
INT16U wCommand;
if((wDestination & (INT16U)(DFLASH_SECTOR_SIZE -1)) != 0)
{
bReturn = RunParameterErr;
}
else
{
bReturn = RunComplete;
if((wDestination < DFLASH_BLOCK_START_ADDR) || \
(wDestination >= DFLASH_BLOCK_END_ADDR) || \
((wDestination + DFLASH_SECTOR_SIZE) > DFLASH_BLOCK_END_ADDR))
{
bReturn = RunParameterErr;
}
else
{
wDestination = wDestination & (INT16U)~(DFLASH_SECTOR_SIZE -1);
//命令准备
wCommand = ((INT16U)(DFLASH_ERASE_SECTOR) << 8);
FlashCommandArray[0] = (wCommand|GLOBAL_ADDRESS_DFLASH);
FlashCommandArray[1] = wDestination;
bReturn = Api_DFlashCommSequence(DFLASH_ERASE_COM_LENGTH);
}
}
return(bReturn);
}
/*-------------------------------------------------------------------------
* Function Name : Api_DFlashEraseVerify
* Description : DFlash扇区擦除
* Input : wDestination
* Output : None
* Return : None
* onther :
--------------------------------------------------------------------------*/
INT8U Api_DFalshProgram(INT16U wDest,INT16U wByteNub,INT16U *wSource)
{
INT8U bLoopIndex;
INT8U bCounter;
INT8U bIndex;
INT16U wEndAdd;
INT16U wCommand;
//else
{
bReturn = RunComplete;
wEndAdd = wDest + wByteNub;
//检测参数正确性
if((0 != (wByteNub % WordSize)) ||
(DFLASH_BLOCK_END_ADDR < wEndAdd))
{
bReturn = RunParameterErr;
}
else
{
wCommand = (((INT16U)(DFLASH_PROGRAM)) << 8);
while(wDest < wEndAdd)
{
FlashCommandArray[0] = (wCommand | GLOBAL_ADDRESS_DFLASH);
FlashCommandArray[1] = wDest;
if(MaxProgramByteNumber < wByteNub)
{
bLoopIndex = DFLASH_PROGRAM_COM_LENGTH;
}
else
{
bLoopIndex = (INT8U)(wByteNub / WordSize);
}
for(bCounter = 0;bCounter < bLoopIndex;bCounter++)
{
FlashCommandArray[bCounter + 2] = *wSource;
wDest += WordSize;
wSource++;
wByteNub -= WordSize;
}
bIndex = bLoopIndex + 1;
if(RunComplete != Api_DFlashCommSequence(bIndex))
{
break;
}
}
}
}
return(bReturn);
}
\ No newline at end of file
This diff is collapsed.
#define GLOBALS_API_HT1621
#include "../App_Headers/includes.h"
/*-------------------------------------------------------------------------
* Function Name : Api_HT1621_SendBit
* Description :
* Input :
* Output : None
* Return : None
* onther :
--------------------------------------------------------------------------*/
void Api_HT1621_SendBit(INT8U data,INT8U len)
{
INT8U i = null;
INT8U w;
w = data;
for(i = 0;i<len;i++)
{
HT1621_WR = 0;
asm(NOP;);
asm(NOP;);
asm(NOP;);
asm(NOP;);
if(w & 0x80)
{
HT1621_DATA = 1;
}
else
{
HT1621_DATA = 0;
}
asm(NOP;);
asm(NOP;);
asm(NOP;);
asm(NOP;);
asm(NOP;);
HT1621_WR = 1;
asm(NOP;);
asm(NOP;);
w = w <<1;
}
}
/*-------------------------------------------------------------------------
* Function Name : Api_HT1621_Write
* Description :
* Input : None
* Output : None
* Return : None
* onther :
--------------------------------------------------------------------------*/
void Api_HT1621_Write(INT8U addr,INT8U sdata)
{
addr<<=2;
HT1621_CS = 0;
Api_HT1621_SendBit(0xa0,3); //写入标志码“101”
Api_HT1621_SendBit(addr,6); //写入addr 的高6位
Api_HT1621_SendBit(sdata,4); //写入data 的8位
HT1621_CS = 1;
}
/*-------------------------------------------------------------------------
* Function Name : Api_HT1621_CMD
* Description :
* Input : None
* Output : None
* Return : None
* onther :
--------------------------------------------------------------------------*/
void Api_HT1621_CMD(INT8U CmdType,INT8U cmd)
{
HT1621_CS =0;
Api_HT1621_SendBit(CmdType,4); //写入标志码“100”和9 位command 命令,由于
Api_HT1621_SendBit(cmd,8); //没有使有到更改时钟输出等命令,为了编程方便
HT1621_CS =1; //直接将command 的最高位写“0”
}
/*-------------------------------------------------------------------------
* Function Name : Api_HT1621_Init
* Description :
* Input : None
* Output : None
* Return : None
* onther :
--------------------------------------------------------------------------*/
void Api_HT1621_Init(void)
{
Api_HT1621_CMD(0x80,0x02); //打开系统晶振 SYS EN
Api_HT1621_CMD(0x80,0x30); //RC 256K
Api_HT1621_CMD(0x80,0x52); //偏压 1/3 BIAS 1/3
Api_HT1621_CMD(0x80,0x06); //开屏 打开LCD 偏压发生器 LCD ON
}
#define GLOBALS_API_LCD
#include "../App_Headers/includes.h"
/*-------------------------------------------------------------------------
* Function Name : Api_LCD_Init
* Description :
* Input :
* Output : None
* Return : None
* onther :
--------------------------------------------------------------------------*/
void Api_LCD_Init(void)
{
/* INT8U b;
INT8U *bp;
LCDCR1_LCDSWAI = Disable; //在停止模式下运行
LCDCR0_DUTY = Duty4; // 1/4 Duty
LCDCR0_LCLK = IRCCLK_1M; // IRCCLK 1M
bp = &LCDRAM0;
for(b = 0; b < 20;b++)
{
*bp = 0; //清零LCDRAM
}
FPENR0 = clear; //0-7 //初始化各段
FPENR1 = clear; //8-15 //初始化各段
FPENR2 = clear; //16-23 //初始化各段
FPENR3 = clear; //24-31 //初始化各段
FPENR4 = clear; //32-39 //初始化各段
LCDCR0_LCDEN = Disable; //使能LCD */
}
This diff is collapsed.
#define GLOBALS_API_PWM
#include "../App_Headers/includes.h"
/*--------------------------------------------------------------------------
* Function Name : Api_PWM_Init
* Description :
* Input : None
* Output : None
* Return : None
* onther : qitiancun
--------------------------------------------------------------------------*/
void Api_PWM_Init(void)
{
PWME = Channel_1 ;
PWMCLK = Channel_1 ; //通道 1 2 时钟选择
PWMPOL = ~(Channel_1 );
PWMPRCLK = PWM_CLK_128DIV; //时钟 = busclk / 32
PWMCAE = ~(Channel_1 ); //通道 1 0 左对称
PWMCTL = PWM_CTL;
//PWMDTY0 = null;
PWMDTY1 = null;
//PWMDTY2 = null;
PWMSCLA = 2; //255
PWMSCLB = 2; //255
//PWMPER0 = PWM0_CYCLE; //PWM1 周期
PWMPER1 = PWM1_CYCLE; //PWM1 周期
//PWMPER2 = PWM2_CYCLE; //PWM2 周期
}
/*-------------------------------------------------------------------------
* Function Name : Api_BeepCtl
* Description : 报警控制
* Input :
* Output : None
* Return : None
* onther :
Clock SA = Clock A / (2 * PWMSCLA)
Clock A = Bus/div1
--------------------------------------------------------------------------*/
void Api_BeepCtl(INT8U duty1,INT8U duty2,INT8U Cycle)
{
PWME_PWME1 = Enable;
//PWME_PWME2 = Enable;
PWMPER1 = Cycle; //PWM1 周期
// PWMPER2 = Cycle; //PWM2 周期
PWMDTY1 = duty1;
// PWMDTY2 = duty2;
}
/*-------------------------------------------------------------------------
* Function Name : Api_LightCtl
* Description :
* Input :
* Output : None
* Return : None
* onther :
Clock SA = Clock A / (2 * PWMSCLA)
Clock A = Bus/div1
--------------------------------------------------------------------------*/
void Api_LightCtl(INT8U duty,INT8U Cycle)
{
// PWMPER0 = Cycle; //PWM1 周期
// PWMDTY0 = duty;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#ifdef GLOBALS_BSP_IIC
#define EXTERN_BSP_IIC
#else
#define EXTERN_BSP_IIC extern
#endif
#ifndef BSP_IIC_H_
#define BSP_IIC_H_
#define IIC_WaitOverTime 10000
#define ACK 0
#define NACK 1
#define SCL PTS_PTS4
#define SDA PTS_PTS7
#define SDADIR DDRS_DDRS7
EXTERN_BSP_IIC void bsp_IIC_delay(void);
EXTERN_BSP_IIC void bsp_IIC_Start(void);
EXTERN_BSP_IIC void bsp_IIC_Stop(void);
EXTERN_BSP_IIC void bsp_IIC_ACK(void);
EXTERN_BSP_IIC void bsp_IIC_NACK(void);
EXTERN_BSP_IIC INT8U bsp_IIC_WaitAck(void);
EXTERN_BSP_IIC INT8U bsp_IIC_SendByte(INT8U Data);
EXTERN_BSP_IIC INT8U bsp_IIC_WritePage(INT8U PhyAdd,INT8U MemAdd, INT8U *Data,INT8U len);
EXTERN_BSP_IIC INT8U bsp_IIC_ReadByte(void);
EXTERN_BSP_IIC INT8U bsp_IIC_ReadPage(INT8U PhyAdd,INT8U MemAdd, INT8U *Data,INT8U len);
#endif /* BSP_IIC_H_ */
\ No newline at end of file
#ifdef GLOBALS_API_ATD
#define EXTERN_API_ATD
#else
#define EXTERN_API_ATD extern
#endif
#ifndef API_ATD_H_
#define API_ATD_H_
EXTERN_API_ATD void Api_ATD_Init(void);
EXTERN_API_ATD void Api_GetSensorAD(void);
EXTERN_API_ATD INT8U Api_ADDelay(INT16U time);
EXTERN_API_ATD void Api_SetAdTimer(INT16U Second,ClockType *T);
EXTERN_API_ATD INT8U Api_AdTimerOver(ClockType *T);
#endif /* API_ATD_H_ */
#ifdef GLOBALS_API_CAN
#define EXTERN_API_CAN
#else
#define EXTERN_API_CAN extern
#endif
#ifndef API_CAN_H_
#define API_CAN_H_
EXTERN_API_CAN void Api_CAN_Init(void);
EXTERN_API_CAN INT32U Api_EXT_ID_TO_PGN(INT8U *IDR0_Add);
EXTERN_API_CAN INT32U bsp_GET_EXTEND_ID(INT8U *IDR0_Add);
EXTERN_API_CAN INT16U Api_GET_STAND_ID(INT8U *IDR0_Add);
EXTERN_API_CAN INT8U Api_GET_EXTID_SA(INT8U *IDR3_Add);
EXTERN_API_CAN interrupt void Api_CAN_Rev_isr(void);
EXTERN_API_CAN interrupt void Api_CAN_Wakep_isr(void);
EXTERN_API_CAN INT8U Api_CANSendFrame (INT32U id,INT8U priority,INT8U length,INT8U *txdata);
#endif /* API_CAN_H_ */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
File added
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
File added
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
// After load the commands written below will be executed
// Before load the commands written below will be executed
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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