|
(1)能显示里程,单位为公里,最后一位为小数位。 (2)能显示金额数,单位为元,最后一位为小数位。 (3)可设定单程价格和往返价格,单程价格为2元/公里,往返价格为1.5元/公里。 (4)车速<5公里/小时的时间累积为总等待时间,每5分钟等待时间相当于里程数增加1公里。 (5)起步公里数为3公里,价格为5元,若实际距离大于3公里,按规则3计算价格。 (6 )按暂停键,计价器可暂停计价,按查询键,可显示总等待时间。
1 液晶尺寸是3.2寸,控制器是 ILI9341
2 SD卡4位模式DMA ,支持长文件名及中文文件名
制作出来的stm32出租车计价器实物图如下:
stm32单片机出租车计价器源程序如下:
- /******************** CHD1807 Team **************************
- * 文件名 :main.c
- * 描述 :LCD显示实验,可中英混合显示,可显示BMP格式的图片,可截图,
- * 截图保存在MicroSD卡中,文件名存为myScreen.bmp,
- * 需显示的BMP图片和字库存放在MicroSD卡中。
- * 实验平台:CHD1807-STM32开发板
- * 库版本 :ST3.5.0
- **********************************************************************************/
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f10x.h"
- #include "SysTick.h"
- #include "usart1.h"
- #include "lcd.h"
- //#include "sd_fs_app.h"
- //#include "Sd_bmp.h"
- #include "adc.h"
- #include "exti.h"
- #include "led.h"
- #include "pwm_output.h"
- #include "SPI_NRF.h"
- #include "Time_test.h"
- //#include"ds18b20.h"
- int num=0,i=0,j=0,k=0,h,time=0,q=4,flag=0;
- u8 status; //用于判断接收/发送状态
- u8 rxbuf[4]={0,0,0,0}; //接收缓冲
- float distance=0,all_distance=0,danjia=0,all_money=0;
- float speed=10;
- int all_distance_a[2]={0,0};
- int all_money_a[2]={0,0};
- int danjia_a[2]={0,0};
- int s_a=0,t_a=0;;
- float R=6.5;
- int d1=0,d2=0,d3=0,d4=0;
- int m1=0,m2=0,m3=0,m4=0;
- u8 ReadValue;
- //////////////////////////////////////////////////////////////////////////////////////////////////////////
- void delay1()
- {int j,h;
- for(j=0;j<1000;j++)
- for(h=0;h<1000;h++);
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- void NRF_control(void)
- {
- /*等待接收数据*/
-
- status = NRF_Rx_Dat(rxbuf); /*判断接收状态*/
- i=rxbuf[1];
- if(i==1) { LED_B14(ON); LED_B15(OFF); LED_D12(OFF); LED_A8(OFF); LED_C6(OFF); LED_C7(OFF);
- TIM_SetCompare3(TIM3,550); TIM_SetCompare4(TIM3,450);
- TIM_SetCompare3(TIM4,1000); TIM_SetCompare4(TIM4,1000); }
- if(i==2) { LED_B14(OFF); LED_B15(ON); LED_D12(OFF); LED_A8(OFF); LED_C6(OFF); LED_C7(OFF);
- TIM_SetCompare3(TIM3,1000); TIM_SetCompare4(TIM3,1000);
- TIM_SetCompare3(TIM4,550); TIM_SetCompare4(TIM4,500); }
- if(i==3) { LED_B14(OFF); LED_B15(OFF); LED_D12(ON); LED_A8(OFF); LED_C6(OFF); LED_C7(OFF);
- TIM_SetCompare3(TIM3,1000); TIM_SetCompare4(TIM3,1000);
- TIM_SetCompare3(TIM4,1000); TIM_SetCompare4(TIM4,1000); }
- if(i==4) { LED_B14(OFF); LED_B15(OFF); LED_D12(OFF); LED_A8(ON); LED_C6(OFF); LED_C7(OFF);
- TIM_SetCompare3(TIM3,600); TIM_SetCompare4(TIM3,350);
- TIM_SetCompare3(TIM4,1000); TIM_SetCompare4(TIM4,1000); }
- if(i==5) { LED_B14(OFF); LED_B15(OFF); LED_D12(OFF); LED_A8(OFF); LED_C6(ON); LED_C7(OFF);
- TIM_SetCompare3(TIM3,350); TIM_SetCompare4(TIM3,600);
- TIM_SetCompare3(TIM4,1000); TIM_SetCompare4(TIM4,1000); }
-
-
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////
- void calculate(void)
- {
- // temperature=(int)DS18B20_Get_Temp();
-
-
- distance = k*2*3.14*R/1000;
- speed = distance*100*10;
-
- all_distance = all_distance+distance;
-
- if(all_distance<30) all_money=50;
- else all_money = (all_distance-30)*danjia + 50;
- all_distance_a[0]=(int)all_distance%10; all_distance_a[1]=(int)all_distance/10;
- all_money_a[0]=(int)all_money%10; all_money_a[1]=(int)all_money/10;
- danjia_a[1]=danjia*10;
- danjia_a[0]=(int)danjia_a[1]%10; danjia_a[1]=(int)danjia_a[1]/10;
- if((all_distance/100)>=1) d1=1;
- if((all_distance/1000)>=1) d2=1;
- if((all_distance/10000)>=1) d3=1;
- if((all_money/100)>=1) m1=1;
- if((all_money/1000)>=1) m2=1;
- if((all_money/10000)>=1) m3=1;
-
- if(speed<2) s_a++;
- else s_a=s_a;
- if(s_a>200)
- {
- s_a=0;
- t_a++;
- all_distance = all_distance+10;
- }
-
-
- k=0;
- distance=0;
-
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- int main(void)
- {
- /* USART1 config */
- USART1_Config();
- SysTick_Init();
- LCD_Init(); //液晶屏初始化
-
- Adc_Init();
- // sd_fs_init();
- EXTI_PC2_Config(); //外部中断测速初始化
- LED_GPIO_Config(); //行驶指示灯初始化
- TIM3_PWM_Init(); //pwm初始化
- SPI_NRF_Init(); //无线通信初始化
- NRF_RX_Mode(); //接收模式
- // temperature = DS18B20_Init();
- TIM2_NVIC_Configuration(); //定时器初始化
- TIM2_Configuration();
- START_TIME; //TIM2 开始计时
-
-
- // LCD_Num_6x12_O(100, 200, 520, 8000); //在指定坐标处悬浮显示6*12大小的数字
- // LCD_Str_CH(100,20,"出租车计价器",0x0333,GRED);
- // LCD_Str_CH(60,60,"单价",0x0333,0x0ff);
- /// LCD_Str_CH(60,100,"行驶距离",0x0333,0x00ff);
- // LCD_Str_CH(60,140,"总金额",0x0333,0x00ff);
- // LCD_Str_CH(60,180,"车内温度",0x0333,0x00ff);
- LCD_Str_O(140, 20, "Taxi meter", GRED);
- LCD_Str_O(60, 60, "price", GBLUE); LCD_Str_O(220, 60, "yuan/mi", GBLUE);
- LCD_Str_O(60, 100, "distance", GBLUE); LCD_Str_O(220, 100, "mi", GBLUE);
- LCD_Str_O(60, 140, "money", GBLUE); LCD_Str_O(220, 140, "yuan", GBLUE);
- LCD_Str_O(60, 180, "WaitTime",GBLUE); LCD_Str_O(220, 180, "miao", GBLUE);
-
-
- acc_z();
- LCD_Line(20,50, 300, 50); //----------
- LCD_Line(20,90, 300, 90);
- LCD_Line(20,130, 300, 130);
- LCD_Line(20,170, 300, 170);
- LCD_Line(20,210, 300, 210); //----------
- LCD_Line(20,50, 20, 210);
- LCD_Line(300,50, 300, 210);
- LCD_Num_6x12_O(180, 65, danjia_a[1], BLACK); LCD_Point(187,74); LCD_Num_6x12_O(189, 65, danjia_a[0], BLACK);
-
- LCD_Num_6x12_O(180, 105, all_distance_a[1], BLACK); LCD_Point(187+(d1+d2+d3)*6,114); LCD_Num_6x12_O(189+(d1+d2+d3)*6, 105, all_distance_a[0], BLACK);
- LCD_Num_6x12_O(180, 145, all_money_a[1], BLACK); LCD_Point(187+(m1+m2+m3)*6,154); LCD_Num_6x12_O(189+(m1+m2+m3)*6, 145, all_money_a[0], BLACK);
- LCD_Num_6x12_O(180, 185, t_a*2, BLACK);
-
-
-
-
- while (1)
- {
-
- t:if(flag==0) goto t;
- if(q>3)
- { q=0;
- LCD_Rectangle(180,50,40,150,0x00ff);
- }
- // calculate();
- // q++;
- // NRF_control();
- q++;
- acc_z();
- LCD_Line(20,50, 300, 50); //----------
- LCD_Line(20,90, 300, 90);
- LCD_Line(20,130, 300, 130);
- LCD_Line(20,170, 300, 170);
- LCD_Line(20,210, 300, 210); //----------
- LCD_Line(20,50, 20, 210);
- LCD_Line(300,50, 300, 210);
-
-
- LCD_Num_6x12_O(180, 65, danjia_a[1], BLACK); LCD_Point(187,74); LCD_Num_6x12_O(189, 65, danjia_a[0], BLACK);
- LCD_Num_6x12_O(180, 105, all_distance_a[1], BLACK); LCD_Point(187+(d1+d2+d3)*6,114); LCD_Num_6x12_O(189+(d1+d2+d3)*6, 105, all_distance_a[0], BLACK);
- LCD_Num_6x12_O(180, 145, all_money_a[1], BLACK); LCD_Point(187+(m1+m2+m3)*6,154); LCD_Num_6x12_O(189+(m1+m2+m3)*6, 145, all_money_a[0], BLACK);
- LCD_Num_6x12_O(180, 185, t_a*2, BLACK);
-
- NRF_control();
-
-
-
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- void TIM2_IRQHandler(void)
- {
- if ( TIM_GetITStatus(TIM2 , TIM_IT_Update) != RESET )
- {
- TIM_ClearITPendingBit(TIM2 , TIM_FLAG_Update);
- ReadValue = GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_10);
- if(ReadValue==1) GPIO_SetBits(GPIOB, GPIO_Pin_11);
- else GPIO_ResetBits(GPIOB, GPIO_Pin_11);
- time++;
- num++;
- if(time>10)
- { time=0;
-
- calculate();
- }
- if(num>0&&num<500) GPIO_SetBits(GPIOC,GPIO_Pin_7);
- if(num>500&&num<1000) GPIO_ResetBits(GPIOC,GPIO_Pin_7);
-
- if(num>1000) num=0;
-
-
-
- /* acc_z();
- LCD_Line(20,50, 300, 50); //----------
- LCD_Line(20,90, 300, 90);
- LCD_Line(20,130, 300, 130);
- LCD_Line(20,170, 300, 170);
- LCD_Line(20,210, 300, 210); //----------
- LCD_Line(20,50, 20, 210);
- LCD_Line(300,50, 300, 210);
-
-
- LCD_Num_6x12_O(180, 65, danjia, BLACK);
- LCD_Num_6x12_O(180, 105,all_distance, BLACK);
- LCD_Num_6x12_O(180, 145,all_money, BLACK);
- LCD_Num_6x12_O(180, 185, 24, BLACK);
- if(q>10)
- { q=0;
- LCD_Rectangle(180,50,50,150,0x00ff);
- }
-
- */
-
- }
-
-
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- void EXTI2_IRQHandler(void)
- {
-
- if(EXTI_GetITStatus(EXTI_Line2) != RESET) //确保是否产生了EXTI Line中断
- {
-
- k++;
-
- EXTI_ClearITPendingBit(EXTI_Line2); //清除中断标志位
- }
-
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- void EXTI3_IRQHandler(void)
- {
- if(EXTI_GetITStatus(EXTI_Line3) != RESET) //确保是否产生了EXTI Line中断
- {
- flag=1;
- danjia=2;
-
-
- EXTI_ClearITPendingBit(EXTI_Line3); //清除中断标志位
- }
- }
-
- void EXTI4_IRQHandler(void)
- {
-
- if(EXTI_GetITStatus(EXTI_Line4) != RESET) //确保是否产生了EXTI Line中断
- {
- flag=1;
- danjia=1.5;
-
- EXTI_ClearITPendingBit(EXTI_Line4); //清除中断标志位
- }
-
- }
-
-
-
-
- /******************* CHD1807 Team *****END OF FILE************/
复制代码
所有资料51hei提供下载:
|
-
-
程序.7z
663.47 KB, 下载次数: 84, 下载积分: 黑币 -5
-
-
出租车计价器设计.doc
6.15 MB, 下载次数: 87, 下载积分: 黑币 -5
-
-
ILI9341_DS_V1[1].09_20110315.pdf
3.41 MB, 下载次数: 23, 下载积分: 黑币 -5
-
-
Outline- BL32007V2.pdf
214.24 KB, 下载次数: 16, 下载积分: 黑币 -5
-
-
触摸控制器tsc2046.pdf
790.92 KB, 下载次数: 16, 下载积分: 黑币 -5
评分
-
查看全部评分
|