在线时间16 小时
UID352142
ST金币0
蝴蝶豆0
注册时间2012-4-9
中级会员
- 最后登录
- 2019-11-19
|
a0a.1 0b0c
由于最近比较忙,所以在收到板子一个多月后才来评测,在此向与非网说声抱歉!
这个项目是本人在大学里的一个课程设计,采用了STM32F0 Discovery探索板作为控制核心,实现了通用电动车在行驶过程中的速度检测、行驶里程的计算以及电动车电瓶的剩余电量值,并根据剩余电量值预报电动车的剩余行驶里程,然后通过人机交互界面进行参数的实时显示。在设计工程中主要完成了电源电路设计,微处理器基本工作电路设计,以光电门为传感器的行驶速度和行驶里程检测电路设计,基于A/D转换的电瓶电量检测电路,实时时钟电路设计,按键及TFT LCD液晶显示电路设计。最后,在硬件系统上通过软件编程实现了部分设计的验证。
废话不多说,直接上代码:
系统时钟初始化函数SystemInit();自带的系统初始化函数
void SystemInit (void)
{
RCC->CR |= (uint32_t)0x00000001;
RCC->CFGR &= (uint32_t)0xF8FFB80C;
RCC->CR &= (uint32_t)0xFEF6FFFF;
RCC->CR &= (uint32_t)0xFFFBFFFF;
RCC->CFGR &= (uint32_t)0xFFC0FFFF;
RCC->CFGR2 &= (uint32_t)0xFFFFFFF0;
RCC->CFGR3 &= (uint32_t)0xFFFFFEAC;
RCC->CR2 &= (uint32_t)0xFFFFFFFE;
RCC->CIR = 0x00000000;
SetSysClock();
}
系统延时初始化函数delay_init()(注,移植于正点原子的开发板例程)
void delay_init()
{
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
fac_us=SystemCoreClock/8000000;
fac_ms=(int16_t)fac_us*1000;
}
LED灯初始化函数LED_Init()
void LED_Init()
{
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStructure);
led_off(LED3|LED4);
}
按键初始化函数KEY_Init(void)
void KEY_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;
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_0|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4);
}
外部中断初始化函数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);
}
}
/*****************************END OF FILE*****************************/
作品实物图
电路原理图和源代码附件
智能仪器课程设计.zip
(4.55 MB, 下载次数: 2310)
|
-
-
|