📄 main.c.bak
字号:
TAD[7]=TAD[6];
TAD[6]=TAD[5];
TAD[5]=TAD[4];
TAD[4]=TAD[3];
TAD[3]=TAD[2];
TAD[2]=TAD[1];
TAD[1]=TAD[0];
TAD[0]=a;
if(++ADC_COUNT>=5)
{
ADC_COUNT=0;
b=0;
for(a=0;a<8;a++)
b+=TAD[a];
b=b/8;
b>>=4;
c=TEMP_TAB[0];
for(a=0;a<130&&(c>b);)
c=TEMP_TAB[++a];
*p=a;
if(b>=0xfa)*p=0xff;
}
}
/*************************************************************************
* Function Name: Dly100us
* Parameters: Int32U Dly
*
* Return: none
*
* Description: Delay Dly * 100us
*
*************************************************************************/
void delay(Int16U Dly)
{
Int16U i=0;
for(;i<Dly;i++);
}
void delay_nop(Int16U Dly)
{
Int16U i;
while(Dly--)
{
for(i=LOOP_DLY_100US; i; i--)WWDG_ClearFlag();
}
}
/*************************************************************************
* Function Name: InitADC1
* Parameters: none
* Return: none
*
* Description: ADC Init subroutine
*
*************************************************************************/
void InitGPIO(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOD|
RCC_APB2Periph_GPIOA,ENABLE);
GPIO_DeInit(GPIOA);
GPIO_DeInit(GPIOB);
GPIO_DeInit(GPIOC);
GPIO_DeInit(GPIOD);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_3|
GPIO_Pin_4|
GPIO_Pin_8|GPIO_Pin_11|GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init (GPIOA, &GPIO_InitStructure); //setion output
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|
GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init (GPIOA, &GPIO_InitStructure); //setion pull-up input
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_5|GPIO_Pin_11|GPIO_Pin_2|GPIO_Pin_9| GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init (GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_1|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_8|
GPIO_Pin_7|GPIO_Pin_10|
GPIO_Pin_12|GPIO_Pin_13|
GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init (GPIOB, &GPIO_InitStructure);
GPIO_Write(GPIOB,0xFE00);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0|GPIO_Pin_3|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7|
GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|
GPIO_Pin_12|GPIO_Pin_11 ;
GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init (GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_4;
GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init (GPIOC, &GPIO_InitStructure);
}
void InitTemperature()
{
TemRHA.IOD=GPIOC;
TemRHA.IO_D=12;
TemRHA.IOC=GPIOD;
TemRHA.IO_C=2;
//TemRHB->IOD=GPIOB,TemRHA->IOD=GPIO_Pin_2,TemRHA->IOC=GPIOB,TemRHA->IOC=GPIO_Pin_2;
}
void InitI2CFALSE()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = (GPIOSpeed_TypeDef)3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init (GPIOB, &GPIO_InitStructure);
}
/*************************************************************************
*************************************************************************/
void TimInit(void)
{
TIM1_TimeBaseInitTypeDef TIM1_TimeBaseInitStruct;
TIM_TimeBaseInitTypeDef TIM2_TimeBaseInitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
//RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1,DISABLE);
// Set timer period 0.2 sec
TIM1_TimeBaseInitStruct.TIM1_Prescaler = 720; // 10us resolution
TIM1_TimeBaseInitStruct.TIM1_CounterMode = TIM1_CounterMode_Up;
TIM1_TimeBaseInitStruct.TIM1_Period = 250; // 200 ms
TIM1_TimeBaseInitStruct.TIM1_ClockDivision = TIM1_CKD_DIV1;
TIM1_TimeBaseInitStruct.TIM1_RepetitionCounter = 0;
TIM1_TimeBaseInit(&TIM1_TimeBaseInitStruct);
// Clear update interrupt bit
TIM1_ClearITPendingBit(TIM1_FLAG_Update);//
// Enable update interrupt
TIM1_ITConfig(TIM1_FLAG_Update,ENABLE);
TIM1_Cmd(ENABLE);
TIM_DeInit(TIM2);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
TIM2_TimeBaseInitStruct.TIM_Prescaler = 17; // 10us resolution
TIM2_TimeBaseInitStruct.TIM_CounterMode=TIM_CounterMode_Up;
TIM2_TimeBaseInitStruct.TIM_Period = 250; // 200 ms
TIM2_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM2,&TIM2_TimeBaseInitStruct);
TIM_ClearITPendingBit(TIM2,TIM_IT_CC2);
TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
TIM_Cmd(TIM2,ENABLE);
}
/*************************************************************************/
void NVICInit(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 9;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*************************************************************************
*
*
*************************************************************************/
void I2CInit()
{
I2C_InitTypeDef I2C_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
/* Configure I2C1 pins: SCL and SDA */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
I2C_DeInit(I2C1);
I2C_InitStructure.I2C_Mode=I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle=I2C_DutyCycle_16_9;
I2C_InitStructure.I2C_OwnAddress1=0xa0;
I2C_InitStructure.I2C_Ack=I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress=I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed=80000;
I2C_Init(I2C1,&I2C_InitStructure);
I2C_Cmd(I2C1,ENABLE);
}
/*************************************************************************
* Function Name: main
* Parameters: none
*
* Return: none
*
* Description: main
*
************************************************************************/
void main(void)
{
volatile Int16U gSampleFlag=FALSE;
#ifdef DEBUG
debug();
#endif
ENTR_CRT_SECTION();
// Init clock system
Clk_Init();
#ifndef EMB_FLASH
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
InitGPIO();
TimInit();
Uart1Init();
//I2CInit();
InitI2CFALSE();
InitTemperature();
NVICInit();
initLCDM();
delay_nop(5000);
InitADC1() ;
InitYear(Year);
ReadFM24C04(&_YT);
Init2515(_YT._Rate&3);
delay_nop(5000);
EXT_CRT_SECTION();
LCD.Mode=C_LCM_Mode0,ALAMCREG_History.Unit=5;;
while(1)
{
if(B_unit)
{
B_unit=FALSE;
if(B_CANMode==0)B_CANMode=ReadCAN(&CANR,B_CANMode,_YT._Address);
if(B_CANMode!=0)B_CANMode=RTS(&CANR,&CANT,&ELE[0]);
if(B_Txd!=0)B_Txd=UsartTXD(pUart1TxFifo,pUart1RxFifo,_YT._ELE);
else
B_Txd=UsartRXD(pUart1RxFifo,pUart1TxFifo);
scankey(&key);
keyserver(&key,&LCD,&_YT);
}
if(B_Disp)
{
B_Disp=FALSE;
CHK_RF(&RF,&_YT.Sensor[0]);
display(&LCD,&_YT,&History[0]);
CHK_BELL(&_YT._AlamcFaultTem,_YT._Channal&0x80);
ADC_TEMP(&_YT._A_Tembuf);
}
if(B_TimerOneSec)
{
B_TimerOneSec=FALSE, GPIOA->ODR^=0X4;
NOTS_Store(&History[0],0,&_YT.Sensor[0]);
Fast_TEM_NOTS(_YT._TemFast,_YT._TemTime,&_YT._AlamcFastTem,&_YT.Sensor[0]);
AlamcFault(&_YT.Sensor[0],&_YT,&Year[1]);
ALAMCREGISTER(&Year[1],&_YT.Sensor[0].ATem,&_YT.ALAMCREG,&_YT._AlamcFaultTem);
ReadYear(Year);
}
}
}
#ifdef DEBUG
/*******************************************************************************
* Function Name : assert_failed
* Description : Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* Input : - file: pointer to the source file name
* - line: assert_param error line source number
* Output : None
* Return : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -