353 基于单片机出租车计价器系统设计【毕设课设】

利用51单片机,设计实现市面上的出租车计价器的基本功能,能区分白天和黑夜,自动调整价格;在液晶上显示界面和计价信息等;价格存储在外部EEPROM中,防止修改;其软件系统的主要模块包含里程计量、费用计算、时间判断、等待费用等

完整版 电路图和程序代码 下载地址

https://pan.baidu.com/s/1JwJ16my5UKwmGahB7IbPfg?pwd=8888

部分代码展示

#include <reg51.h>
#include "LCD1602.h"
#include "da1302.h"
//#include "at24c02.h"
#define uchar unsigned char
#define uint unsigned int

uchar time[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};  //1302的时间预设值
uchar Price,kilometre,Unit_price; //总价,里程,单价
uchar lch,biao,k;
int Hall_counter;
sbit Day_night=P2^5;
sbit stop=P2^6;
sbit begin=P2^7;
sbit led1=P0^0;	 //计价开始指示灯
sbit led2=P0^1;	 //夜晚计价指示灯
unsigned char PriceBuffer[10],kilometreBuffer[10],Unit_priceBuffer[10],CurrentTime_TimeStringBuffer[10];

SYSTEMTIME CurrentTime ;

/******************************************/ 
/*              延时子程序                */ 
/******************************************/ 
void Delay1ms(unsigned int count)
{
	unsigned int i,j;
	for(i=0;i<count;i++)
	for(j=0;j<120;j++);
}

void scan(void)		 //扫描键盘
{
   if(begin==0)
	{
	   biao=1;
	   EA=1;		 //开启中断计数
	   Initial_DS1302();
	   set_time(time);	 //设置1302的初始值为0,开始计时
	   Price=0;
  	   kilometre=0;
	   Unit_price=0;
	}
   if(biao==1)
	{
	   //TR1=1;
	   //TR0=1;
	   EX0=1;
	   led1=0; //开始计价指示灯亮
	  /*****************开始计时并时钟显示*********************************/
	   DS1302_GetTime(&CurrentTime);	 //获取时间
       Delay1ms(1);
       TimeToStr(&CurrentTime);	//时间转换成字符串格式
	   GotoXY(8,1);
 	   Print(&CurrentTime.TimeString);	//显示时间
       Delay1ms(10);		   
	}
   if(stop==0)
	{
	   biao=2;
	   if(biao==2)
		{		   
		   EA=0;	//停止中断计数
		   led1=1;  //开始计价指示灯灭
		   stop_1302();//时钟停止,计时停止
	    }
	}
	if(Day_night==0)
	led2=0;
	else led2=1;
}

/******************************************/ 
/*              LCD 显示转换字符程序              */ 
/******************************************/ 
void IntToStr(unsigned int t, unsigned char *str, unsigned char n) 	//将整型数据转换成字符指针,在液晶上显示
{
	unsigned char a[3]; char i, j;                                 	                                    	
	a[0]=(t/100)%10;                                      	
	a[1]=(t/10)%10;                                       	
	a[2]=(t/1)%10;                                        	
                                                      
	for(i=0; i<3; i++)         //转成ASCII码              	
		a[i]=a[i]+'0';                                    	
	for(i=0; a[i]=='0' && i<=3; i++);                     	
	for(j=3-n; j<i; j++)       //填充空格                 	
		{ *str=' ';  str++; }                             	
	for(; i<3; i++)                                       	
		{ *str=a[i]; str++; }  //加入有效的数字           	
	*str='\0'; 
} 


/******************************************/ 
/*              主程序                    */ 
/******************************************/ 

void main(void)
{
	Price,kilometre,Unit_price=0;
	TMOD=0x01;
	TH0=(65536-50000)/256;
	TL0=(65536-50000)%256;	
	//ET0=1;
	EA=1;	
	IT0=1;	 
	LCD_Initial();		   //液晶屏初始化
	Initial_DS1302();
//	Initial_com();		//24C02初始化

	GotoXY(0,0);		   //定位液晶显示位置第一行第一列
	Print("The 1602 COUNTER");  //系统开机显示logo
	GotoXY(0,1);
	Print(" BY BF-SHNU  ");
	Delay1ms(1000);
	GotoXY(0,0);
	Print("                 ");	  //清空液晶屏
	GotoXY(0,1);
	Print("                 ");
	while(1)
	{	
      scan();		 //扫描键盘
      IntToStr(kilometre,&kilometreBuffer[0],2);  //将公里数转换为液晶显示字符	
	  IntToStr(Price,&PriceBuffer[0],3);		  //将总价数转换为液晶显示字符
	  IntToStr(Unit_price,&Unit_priceBuffer[0],1);//将单价数转换为液晶显示字符
	  GotoXY(0,0);
	  Print("ZJ:");		 //总价:
      Print(&PriceBuffer[0]);	 //显示总价值
	  Print("$");
	  GotoXY(8,0);
	  Print("LC:");		//路程:
	  Print(&kilometreBuffer[0]);  //显示公里值
	  Print("Km");
	  GotoXY(0,1);
	  Print("DJ:");	    //单价:
	  Print(&Unit_priceBuffer[0]); //显示单价值
	  Print("$");
	  Delay1ms(7);	 
  

  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值