出租车计费设计
基于51单片机出租车计费仿真设计(proteus仿真+程序+原理图+设计说明书)功能说明仿真图程序原理图设计说明书摘要
设计清单(提供资料清单所有文件)资料下载
基于51单片机出租车计费仿真设计(proteus仿真+程序+原理图+设计说明书)
仿真图proteus 7.8
程序编译器:keil 4/keil 5
编程语言:C语言
设计编号:C0050
功能说明
51单片机 + 1302时钟芯片准确计时 + LCD1602液晶显示 + 24c02芯片可以掉电存储数据 + 3v直流电机模拟发动机工作。
1、当无乘客时液晶可以显示时间(年月日时分秒),时间可以按键设置,此时电机不工作;
2、当有乘客时电机工作,可以通过按键开始计费系统工作,有清零键,收费可以修改(包括起价费、超过起价费每公里或分钟收费、白天和夜晚收费标准);
3、可以切换白天和夜晚收费标准,可以按照分钟或公里收费切换。
仿真图
![img](https://img-blog.csdnimg.cn/img_convert/96d2ba7ec149545839c79fb52d6cdf07.png) ![img](https://img-blog.csdnimg.cn/img_convert/0a2601ed623ffa2e8e76a2f1e0dcaee3.png)
程序
![img](https://img-blog.csdnimg.cn/img_convert/b3e3eabfc026d3d6278cbd89e471a87d.png)
//出租车计价器
//宏定义
#define uchar unsigned char
#define uint unsigned int
//头函数声明
#include
#include "Lcd.h"
#include "Data.h"
#include "DS1302.h"
#include "AT24C02.h"
//键盘定义
sbit K1=P3^4; //模式切换
sbit K2=P3^6; //减按键
sbit K3=P3^5; //加按键
sbit K4=P3^7; //万年历模式时:设置时间信息。计价器模式时:设置单价
//模式0时钟 1时钟调整
uchar Mode=0;
//时钟屏幕调整
uchar Wei=0;
uchar SS=0;
//价格调整
uchar JGWei=0;
//计价器参数
uint Day=0;
uint Night=0;
uint DanJia=0;
uint DJ_min=0;
uint ZJ=0;
unsigned long GL=0;
uint Time=0;
uint count=0;
uchar m=0;
//白天/晚上
uchar DN=0;
//公里/时间
uchar GT=0;
//初始化函数
void InitTimer0();
//写初值
void SETS();
//读初值
void READS();
//主函数
void main()
{
//初始化
Ds1302_Init();
Init_LCD();
initeeprom();
//SETS();
//读取初始参数
READS();
//定时器初始化
InitTimer0();
//循环
while(1)
{
//时钟模式
if(Mode==0)
{
//读时间
if(Wei==0)
{
Ds1302_Read_Time();
//显示时间
display_NYR(time_buf1,Wei,0);
}
}
else if(Mode==1)
{
if(time_buf1[4]>=23||time_buf1[4]
Wei++;
if(Wei==1)
{
SS=1;
}
//闪烁
display_NYR(time_buf1,Wei,SS);
if(Wei==7)
{
Wei=0;
//保存时间
Ds1302_Write_Time();
Init_LCD();
}
}
else if(Mode==1)
{
JGWei++;
if(JGWei==1)
{
Mode=2;
//显示计价器价格
Init_LCD_JGTZ();
display_D(Day,Night,DanJia,JGWei,DJ_min);
}
}
else if(Mode==2)
{
JGWei++;
display_D(Day,Night,DanJia,JGWei,DJ_min);
if(JGWei==5)
{
Mode=1;
JGWei=0;
//参数初始化
//保存
SETS();
//读初值
READS();
ZJ=0;
GL=0;
Time=0;
//开启定时器
TR0=1;
//显示计价器
Init_LCD_JJQ();
}
}
while(K4==0);
}
//+
if(K3==0)
{
delay(100);
//调时
if(Mode==0)
{
//年
if(Wei==1)
{
time_buf1[1]++;
if(time_buf1[1]>=100)
time_buf1[1]=0;
}
//月
else if(Wei==2)
{
time_buf1[2]++;
if(time_buf1[2]>=13)
time_buf1[2]=1;
}
//日
else if(Wei==3)
{
time_buf1[3]++;
if(time_buf1[3]>=YDay(time_buf1[1],time_buf1[2])+1)
time_buf1[3]=1;
}
//时
else if(Wei==4)
{
time_buf1[4]++;
if(time_buf1[4]>=24)
time_buf1[4]=0;
}
//分
else if(Wei==5)
{
time_buf1[5]++;
if(time_buf1[5]>=60)
time_buf1[5]=0;
}
//秒
else if(Wei==6)
{
time_buf1[6]++;
if(time_buf1[6]>=60)
time_buf1[6]=0;
}
//显示
if(Wei!=0)
display_NYR(time_buf1,Wei,SS);
}
//调价
else if(Mode==2)
{
//单价
if(JGWei==1)
{
DanJia++;
if(DanJia>999)
{
DanJia=1;
}
}
//等待时间单价
else if(JGWei==2)
{
DJ_min++;
if(DJ_min>999)
{
DJ_min=1;
}
}
//夜间
else if(JGWei==3)
{
Night++;
if(Night>999)
{
Night=1;
}
}
//白天
else if(JGWei==4)
{
Day++;
if(Day>999)
{
Day=1;
}
}
display_D(Day,Night,DanJia,JGWei,DJ_min);
}
while(K3==0);
}
//-
if(K2==0)
{
delay(100);
//调时
if(Mode==0)
{
//年
if(Wei==1)
{
time_buf1[1]--;
if(time_buf1[1]
time_buf1[3]--;
if(time_buf1[3]
time_buf1[5]--;
if(time_buf1[5]
//单价
if(JGWei==1)
{
DanJia--;
if(DanJia==0)
{
DanJia=999;
}
}
//等待时间单价
else if(JGWei==2)
{
DJ_min--;
if(DJ_min==0)
{
DJ_min=999;
}
}
//夜间
else if(JGWei==3)
{
Night--;
if(Night==0)
{
Night=999;
}
}
//白天
else if(JGWei==4)
{
Day--;
if(Day==0)
{
Day=999;
}
}
display_D(Day,Night,DanJia,JGWei,DJ_min);
}
while(K2==0);
}
//切换
if(K1==0)
{
delay(100);
//计价器模式
if(Mode==1)
{
Mode=0;
ZJ=0;
GL=0;
Time=0;
//开启定时器
TR0=0;
EX0=0;
//显示计价器
Init_LCD();
}
else if(Mode==0)
{
Mode=1;
//参数初始化
//读初值
READS();
ZJ=0;
GL=0;
Time=0;
//开启定时器
m=0;
TR0=1;
EX0=1;
//显示计价器
Init_LCD_JJQ();
}
while(K1==0);
}
}
}
//初始化函数
void InitTimer0(void)
{
TMOD = 0x01;
TH0 = 0x3C;
TL0 = 0xB0; //10ms
EA = 1;
ET0 = 1;
TR0 = 1;
IT0=1; //INT0负跳变触发
EX0=0;//开外部INTO中断
}
//定时器0中断10ms
void Timer0Interrupt(void) interrupt 1
{
TH0 = 0x3C;
TL0 = 0xB0; //赋初值
m++;
if(m>=20)
{
m=0;
if(count>=60)
{
GT=0;
GL=GL+count/10;
count=0;
}
else
{
count=0;
GT=1;
Time++; //时间++
}
}
//计算钱数
//公里数小于3
if(GL
if(Time>60)
ZJ=Day+Time/60*DJ_min;
else
ZJ=Day;
}
else
{
if(Time>60)
ZJ=Night+Time/60*DJ_min;
else
ZJ=Night;
}
}
else
{
if(DN==0)
{
if(Time>60)
ZJ=Day+(GL/10-20)/10*DanJia+Time/60*DJ_min;
else
ZJ=Day+(GL/10-20)/10*DanJia;
}
else
{
if(Time>60)
ZJ=Night+(GL/10-20)/10*DanJia+Time/60*DJ_min;
else
ZJ=Night+(GL/10-20)/10*DanJia;
}
}
}
void EXINT0() interrupt 0
{
count++;
}
//读初值
void READS()
{
uchar SH=0,SL=0;
uint temp=0;
delay(10);
SL=read_add(0x01);
delay(10);
SH=read_add(0x02);
temp=SH;
temp=temp |