外部中断初始化函数EXTI_KEY_Init(void)void EXTI_KEY_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_ResetBits(GPIOA,GPIO_Pin_1);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource1);
EXTI_InitStructure.EXTI_Line = EXTI_Line1;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
}
定时器初始化函数TIM3_Init(void)void TIM3_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 , ENABLE);
TIM3->SC=47999;
TIM3->ARR=99;
TIM3->DIER|=1=0XFFFFFFF0)
FLASH_Write(FLASH_KM_TEST_ADDR,0);
else
FLASH_Write(FLASH_KM_TEST_ADDR,x);
LCD_Init();
Self_Test();
GUI_Init();
BACK_COLOR=GRAYBLUE;
km_test=FLASH_Read(FLASH_KM_TEST_ADDR);
while (1)
{
LCD_Show2Num(108, 92,(uint16_t)speed,3,16,0);
LCD_Show2Num(140, 92,(speed-(uint16_t)speed)*100,2,16,0);
km= ((float)(km_test/8)*2*pi*0.28/1000)/100;
LCD_Show2Num(108,132,(uint16_t)km,4,16,0);
LCD_Show2Num(148,132,(km-(uint16_t)km)*10,1,16,0);
while((DMA_GetFlagStatus(DMA1_FLAG_TC1)) == RESET );
DMA_ClearFlag(DMA1_FLAG_TC1);
temp = (float)RegularConvData_Tab[0]*(3.3/4096)*5.12;
battery = temp*6000/12;
LCD_Show2Num(108, 172,(uint16_t)battery,6,16,0);
remain_km=battery*0.05;
LCD_Show2Num(108, 212,(uint16_t)remain_km,6,16,0);
temp = (float)RegularConvData_Tab[1]*(3.3/4096);
temperate=(1.43-temp)/0.043+25;
BACK_COLOR=LBBLUE;
LCD_Show2Num(132, 280,(uint8_t)temperate,2,16,0);
LCD_Show2Num(156, 280,(temperate-(uint8_t)temperate)*100,2,16,0);
BACK_COLOR=GRAYBLUE;
i++;
if(i>100)
{
i=0;F_LED4;
FLASH_Write(FLASH_KM_TEST_ADDR,km_test); //
}
delay_ms(10);
}
}
|