//出租车计价器
//宏定义
#define uchar unsigned char
#define uint unsigned int
//头函数声明
#include <reg52.h>
#include <stdlib.h>
#include "Lcd.h"
#include "Data.h"
#include "DS1302.h"
#include "AT24C02.h"
//键盘定义
sbit K1=P3^1;
sbit K2=P3^3;
sbit K3=P3^7;
sbit K4=P3^0;
sbit K5=P3^2;
sbit K6=P3^4;
sbit K7=P3^6;
sbit K8=P3^5;
//模式0时钟 1时钟调整
uchar Mode=0;
//时钟屏幕调整
uchar Wei=0;
uchar SS=0;
//价格调整
uchar JGWei=0;
//计价器参数
uint Day=0;
uint Night=0;
uint DanJia=0;
uint ZJ=0;
uint GL=0;
uint Time=0;
//白天/晚上
uchar DN=0;
//公里/时间
uchar GT=0;
uchar DS=0;
//时间记录
uchar TG=0;
uchar TT=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)
{
//显示计价器信息
display_S(Day,Night,DanJia,ZJ,GL,Time,GT,DN);
}
//时间调整
if(K7==0)
{
delay(10);
//调时
if(Mode==0)
{
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)
{
if(DN==0)
{
DN=1;
}
else
{
DN=0;
}
}
while(K7==0);
}
//价格调整
if(K6==0)
{
delay(10);
if(Mode==1)
{
JGWei++;
if(JGWei==1)
{
Mode=2;
//显示计价器价格
Init_LCD_JGTZ();
display_D(Day,Night,DanJia,JGWei);
}
}
else if(Mode==2)
{
JGWei++;
display_D(Day,Night,DanJia,JGWei);
if(JGWei==4)
{
Mode=1;
JGWei=0;
//参数初始化
//保存
SETS();
//读初值
READS();
TG=0;
TT=0;
ZJ=0;
GL=0;
Time=0;
//白天/晚上
DN=0;
//公里/时间
GT=0;
//开启定时器
TR0=1;
//显示计价器
Init_LCD_JJQ();
}
}
while(K6==0);
}
//+
if(K5==0)
{
delay(10);
//调时
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]==59)
time_buf1[5]=0;
}
//秒
else if(Wei==6)
{
time_buf1[6]++;
if(time_buf1[6]==59)
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)
{
Night++;
if(Night>999)
{
Night=1;
}
}
//白天
else if(JGWei==3)
{
Day++;
if(Day>999)
{
Day=1;
}
}
display_D(Day,Night,DanJia,JGWei);
}
while(K5==0);
}
//-
if(K4==0)
{
delay(10);
//调时
if(Mode==0)
{
//年
if(Wei==1)
{
time_buf1[1]--;
if(time_buf1[1]==0xff)
time_buf1[1]=99;
}
//月
else if(Wei==2)
{
time_buf1[2]--;
if(time_buf1[2]==0)
time_buf1[2]=12;
}
//日
else if(Wei==3)
{
time_buf1[3]--;
if(time_buf1[3]==0)
time_buf1[3]=YDay(time_buf1[1],time_buf1[2]);
}
//时
else if(Wei==4)
{
time_buf1[4]--;
if(time_buf1[4]==0xff)
time_buf1[4]=23;
}
//分
else if(Wei==5)
{
time_buf1[5]--;
if(time_buf1[5]==0xff)
time_buf1[5]=59;
}
//秒
else if(Wei==6)
{
time_buf1[6]--;
if(time_buf1[6]==0xff)
time_buf1[6]=59;
}
//显示
if(Wei!=0)
display_NYR(time_buf1,Wei,SS);
}
//调价
else if(Mode==2)
{
//单价
if(JGWei==1)
{
DanJia--;
if(DanJia==0)
{
DanJia=999;
}
}
//夜间
else if(JGWei==2)
{
Night--;
if(Night==0)
{
Night=999;
}
}
//白天
else if(JGWei==3)
{
Day--;
if(Day==0)
{
Day=999;
}
}
display_D(Day,Night,DanJia,JGWei);
}
while(K4==0);
}
//退出
if(K3==0)
{
delay(10);
//计价器模式
if(Mode==1)
{
Mode=0;
TG=0;
TT=0;
ZJ=0;
GL=0;
Time=0;
//白天/晚上
DN=0;
//公里/时间
GT=0;
//开启定时器
TR0=0;
//显示计价器
Init_LCD();
}
while(K3==0);
}
if(K8==0)
{
delay(10);
if(Mode==1)
{
if(GL<=50)
{
if(DN==0)
{
if(Time>20)
ZJ=Day+(Time-10)/10*DanJia;
else
ZJ=Day;
}
else
{
if(Time>20)
ZJ=Night+(Time-10)/10*DanJia;
else
ZJ=Night;
}
}
else
{
if(DN==0)
{
if(Time>20)
ZJ=Day+(GL-40)/10*DanJia+(Time-10)/10*DanJia;
else
ZJ=Day+(GL-40)/10*DanJia;
}
else
{
if(Time>20)
ZJ=Night+(GL-40)/10*DanJia+(Time-10)/10*DanJia;
else
ZJ=Night+(GL-40)/10*DanJia;
}
}
}
while(K8=0);
}
//暂停
if(K2==0)
{
delay(10);
//计价器模式
if(Mode==1)
{
//公里模式
if(GT==0)
{
GT=1;
}
else
{
GT=0;
}
}
while(K2==0);
}
//开启计价器模式
if(K1==0)
{
delay(10);
//为时钟模式
if(Mode==0)
{
Mode=1;
//参数初始化
//读初值
READS();
TG=0;
TT=0;
ZJ=0;
GL=0;
Time=0;
//白天/晚上
DN=0;
//公里/时间
GT=0;
//开启定时器
TR0=1;
//显示计价器
Init_LCD_JJQ();
}
//清零
if(Mode==1)
{
TG=0;
TT=0;
ZJ=0;
GL=0;
Time=0;
}
while(K1==0);
}
}
}
//初始化函数
void InitTimer0(void)
{
TMOD = 0x01;
TH0 = 0x0D8;
TL0 = 0x0F0;
EA = 1;
ET0 = 1;
TR0 = 0;//暂时不开定时器
}
//定时器0中断10ms
void Timer0Interrupt(void) interrupt 1
{
TH0 = 0x0D8;
TL0 = 0x0F0;
//公里模式
if(GT==0)
{
TG++;
if(TG>100)
//if(TG>10)
{
TG=0;
{
int a;
int i;
for(i=0;i<10;i++)
{
a=rand()%10;
}
GL+=a;
}
}
}
//时间模式
else
{
TT++;
if(TT>100)
//if(TT>10)
{
TT=0;
Time++;
}
}
//计算钱数
//公里数小于5
if(GL<=50)
{
if(DN==0)
{
if(Time>20)
ZJ=Day+(Time-10)/10*DanJia;
else
ZJ=Day;
}
else
{
if(Time>20)
ZJ=Night+(Time-